Documentation ¶
Index ¶
- Constants
- Variables
- func BinTimestamp(ts int64, spec string) (int64, error)
- func BinTimestamps(tss []int64, spec string) (map[int64]int64, error)
- func EstimateBinSize(tss []int64) (string, string)
- func GenRandomTimestamps(count int, seed int64, start_ts int64, stop_ts int64, dist string) ([]int64, error)
- func ParseSpec(unit string) (mult int64, delt int64, err error)
- func SimpleRandomTimestamps(count int, hours_duration int) ([]int64, error)
- type ChartJSCtx
- type ChartJSDatapoint
Constants ¶
const TD_1_day int64 = 24 * TD_1_hr
const TD_1_hr int64 = 60 * TD_1_min
const TD_1_min int64 = 60 * TD_1_sec
const TD_1_ms int64 = 1
const TD_1_sec int64 = 1000 * TD_1_ms
const TD_1_week int64 = 7 * TD_1_day
Variables ¶
var ABBREV_LARGE_TO_SMALL []string = []string{"Y", "W", "D", "h", "m", "s", "ms"}
var ABBREV_TO_CHARTJS_UNIT map[string]string = map[string]string{
"Y": "year",
"W": "week",
"D": "day",
"h": "hour",
"m": "minute",
"s": "second",
"ms": "millisecond",
}
Maps the time abbreviations originally taken from Pandas onto the time abbreviations needed by ChartJS: https://www.chartjs.org/docs/3.0.2/axes/cartesian/time.html#time-units
var ABBREV_TO_DELT map[string]int64 = map[string]int64{ "Y": 365 * TD_1_day, "W": TD_1_week, "D": TD_1_day, "h": TD_1_hr, "m": TD_1_min, "s": TD_1_sec, "ms": TD_1_ms, }
var TIMEDELTA_ABBREVS map[string]string = map[string]string{
"Y": "Y",
"y": "Y",
"W": "W",
"w": "W",
"D": "D",
"d": "D",
"days": "D",
"day": "D",
"hours": "h",
"hour": "h",
"hr": "h",
"h": "h",
"m": "m",
"minute": "m",
"min": "m",
"minutes": "m",
"t": "m",
"s": "s",
"seconds": "s",
"sec": "s",
"second": "s",
"ms": "ms",
"milliseconds": "ms",
"millisecond": "ms",
"milli": "ms",
"millis": "ms",
"l": "ms",
}
Functions ¶
func BinTimestamp ¶
BinTimestamp takes a timestamp in epoch_ms format and returns that same timestamp floor-ed down to the nearest 'frequency' you provided, effectively giving you the "bin" where this timestamp belongs in a histogram with bins of size 'frequency'. If 'frequency' does not stand for a known bin-size, then an error is returned.
func EstimateBinSize ¶
EstimateBinSize returns two abbreviations for duration. The first is an abbreviation appropriate to get a timedelta duration from ABBREV_TO_DELT, while the second is a ChartJS compatible abbreviation
func GenRandomTimestamps ¶
Types ¶
type ChartJSCtx ¶
type ChartJSCtx struct { Unit string `json:"unit"` Data []ChartJSDatapoint `json:"data"` }
func FormatBinDataForChartJS ¶
func FormatBinDataForChartJS(bins map[int64]int64) (ChartJSCtx, error)
type ChartJSDatapoint ¶
type ChartJSDatapoint struct { X interface{} `json:"x"` Y interface{} `json:"y"` }