-
Notifications
You must be signed in to change notification settings - Fork 0
/
statsTimeSeries.ts
48 lines (41 loc) · 1.11 KB
/
statsTimeSeries.ts
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
import { EntityStorage } from '@aleph-indexer/core'
import { TimeFrame } from '../../time.js'
export type StatsTimeSeries<T> = {
account: string
type: string
timeFrame: TimeFrame
startDate: number
endDate: number
data: T
}
/**
* Stats Time Series Entity Storage.
*/
export type StatsTimeSeriesStorage = EntityStorage<StatsTimeSeries<any>>
const accountKey = {
get: (e: StatsTimeSeries<unknown>) => e.account,
length: EntityStorage.AddressLength,
}
const typeKey = {
get: (e: StatsTimeSeries<unknown>) => e.type,
length: EntityStorage.VariableLength,
}
const timeFrameKey = {
get: (e: StatsTimeSeries<unknown>) => e.timeFrame,
length: 3,
}
// @note: start date in millis of the interval
const startDateKey = {
get: (e: StatsTimeSeries<unknown>) => e.startDate,
length: EntityStorage.TimestampLength,
}
/**
* Creates a stats time series Entity Storage.
*/
export function createStatsTimeSeriesDAL(path: string): StatsTimeSeriesStorage {
return new EntityStorage<StatsTimeSeries<any>>({
name: 'stats_time_series',
path,
key: [accountKey, typeKey, timeFrameKey, startDateKey],
})
}