-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathWeatherAggregate.cs
More file actions
57 lines (50 loc) · 2.38 KB
/
WeatherAggregate.cs
File metadata and controls
57 lines (50 loc) · 2.38 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using CmdScale.EntityFrameworkCore.TimescaleDB.Abstractions;
using CmdScale.EntityFrameworkCore.TimescaleDB.Configuration.ContinuousAggregate;
using CmdScale.EntityFrameworkCore.TimescaleDB.Configuration.ContinuousAggregatePolicy;
using Microsoft.EntityFrameworkCore;
namespace CmdScale.EntityFrameworkCore.TimescaleDB.Example.DataAccess.Models
{
/// <summary>
/// Example continuous aggregate showcasing all possible configuration properties and aggregate functions.
/// This aggregates weather data into daily buckets with various statistical measures.
/// </summary>
[Keyless]
[ContinuousAggregate(
MaterializedViewName = "weather_aggregates",
ParentName = nameof(WeatherData),
ChunkInterval = "1 month",
WithNoData = true,
CreateGroupIndexes = true,
MaterializedOnly = false,
Where = "\"temperature\" > -50 AND \"humidity\" >= 0")]
[TimeBucket("1 day", nameof(WeatherData.Time), GroupBy = true)]
[ContinuousAggregatePolicy(
StartOffset = "30 days",
EndOffset = "1 day",
ScheduleInterval = "1 hour",
RefreshNewestFirst = true)]
public class WeatherAggregate
{
// Avg aggregate function
[Aggregate(EAggregateFunction.Avg, nameof(WeatherData.Temperature))]
public double AverageTemperature { get; set; }
// Max aggregate function
[Aggregate(EAggregateFunction.Max, nameof(WeatherData.Humidity))]
public double MaxHumidity { get; set; }
// Min aggregate function
[Aggregate(EAggregateFunction.Min, nameof(WeatherData.Humidity))]
public double MinHumidity { get; set; }
// Sum aggregate function
[Aggregate(EAggregateFunction.Sum, nameof(WeatherData.Temperature))]
public double TotalTemperature { get; set; }
// Count aggregate function (using "*" for count all records)
[Aggregate(EAggregateFunction.Count, "*")]
public int RecordCount { get; set; }
// First aggregate function (gets first temperature value in time bucket)
[Aggregate(EAggregateFunction.First, nameof(WeatherData.Temperature))]
public double FirstTemperature { get; set; }
// Last aggregate function (gets last temperature value in time bucket)
[Aggregate(EAggregateFunction.Last, nameof(WeatherData.Temperature))]
public double LastTemperature { get; set; }
}
}