-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTradeAggregateConfiguration.cs
More file actions
27 lines (26 loc) · 1.43 KB
/
TradeAggregateConfiguration.cs
File metadata and controls
27 lines (26 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using CmdScale.EntityFrameworkCore.TimescaleDB.Abstractions;
using CmdScale.EntityFrameworkCore.TimescaleDB.Configuration.ContinuousAggregate;
using CmdScale.EntityFrameworkCore.TimescaleDB.Configuration.ContinuousAggregatePolicy;
using CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess.Configurations
{
public class TradeAggregateConfiguration : IEntityTypeConfiguration<TradeAggregate>
{
public void Configure(EntityTypeBuilder<TradeAggregate> builder)
{
builder.HasNoKey();
builder.IsContinuousAggregate<TradeAggregate, Trade>("trade_aggregate_view", "1 hour", x => x.Timestamp, true, "7 days")
.AddAggregateFunction(x => x.AveragePrice, x => x.Price, EAggregateFunction.Avg)
.AddAggregateFunction(x => x.MinPrice, x => x.Price, EAggregateFunction.Max)
.AddAggregateFunction(x => x.MaxPrice, x => x.Price, EAggregateFunction.Min)
.AddGroupByColumn(x => x.Exchange)
.AddGroupByColumn("1, 2")
.Where("\"ticker\" = 'MCRS'")
.MaterializedOnly()
.WithRefreshPolicy(startOffset: "7 days", endOffset: "1 hour", scheduleInterval: "1 hour")
.WithRefreshNewestFirst(true);
}
}
}