tbin

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const TD_1_day int64 = 24 * TD_1_hr
View Source
const TD_1_hr int64 = 60 * TD_1_min
View Source
const TD_1_min int64 = 60 * TD_1_sec
View Source
const TD_1_ms int64 = 1
View Source
const TD_1_sec int64 = 1000 * TD_1_ms
View Source
const TD_1_week int64 = 7 * TD_1_day

Variables

View Source
var ABBREV_LARGE_TO_SMALL []string = []string{"Y", "W", "D", "h", "m", "s", "ms"}
View Source
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

View Source
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,
}
View Source
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

func BinTimestamp(ts int64, spec string) (int64, error)

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 BinTimestamps

func BinTimestamps(tss []int64, spec string) (map[int64]int64, error)

func EstimateBinSize

func EstimateBinSize(tss []int64) (string, string)

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

func GenRandomTimestamps(count int, seed int64, start_ts int64, stop_ts int64, dist string) ([]int64, error)

func ParseSpec

func ParseSpec(unit string) (mult int64, delt int64, err error)

func SimpleRandomTimestamps

func SimpleRandomTimestamps(count int, hours_duration int) ([]int64, error)

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL