querying

package
v0.0.0-...-b9360c4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxTime = time.Unix(1<<63-62135596801, 999999999)
	MinTime = time.Time{}
)
View Source
var (
	Window24h        = &TimeScaleDBWindow{Specifier: "24h", Interval: time.Hour * 24}
	Window6h         = &TimeScaleDBWindow{Specifier: "6h", Interval: time.Hour * 6}
	Window1h         = &TimeScaleDBWindow{Specifier: "1h", Interval: time.Hour * 1}
	Window10m        = &TimeScaleDBWindow{Specifier: "10m", Interval: time.Minute * 10}
	Window1m         = &TimeScaleDBWindow{Specifier: "1m", Interval: time.Minute * 1}
	TimeScaleWindows = []*TimeScaleDBWindow{
		Window24h,
		Window6h,
		Window1h,
		Window10m,
		Window1m,
	}
)
View Source
var (
	Windows = []*InfluxDBWindow{
		&InfluxDBWindow{Specifier: "24h", Interval: time.Hour * 24},
		&InfluxDBWindow{Specifier: "12h", Interval: time.Hour * 12},
		&InfluxDBWindow{Specifier: "6h", Interval: time.Hour * 6},
		&InfluxDBWindow{Specifier: "1h", Interval: time.Hour * 1},
		&InfluxDBWindow{Specifier: "30m", Interval: time.Minute * 30},
		&InfluxDBWindow{Specifier: "10m", Interval: time.Minute * 10},
		&InfluxDBWindow{Specifier: "1m", Interval: time.Minute * 1},
	}
)

Functions

func Logger

func Logger(ctx context.Context) *zap.Logger

Types

type AggregateInfo

type AggregateInfo struct {
	Name     string    `json:"name"`
	Interval int32     `json:"interval"`
	Complete bool      `json:"complete"`
	Start    time.Time `json:"start"`
	End      time.Time `json:"end"`
}

type DataBackend

type DataBackend interface {
	QueryData(ctx context.Context, qp *backend.QueryParams) (*QueriedData, error)
	QueryTail(ctx context.Context, stationIDs []int32) (*SensorTailData, error)
	QueryRecentlyAggregated(ctx context.Context, stationIDs []int32, windows []time.Duration) (*RecentlyAggregated, error)
}

type DataRange

type DataRange struct {
	Start *time.Time
	End   *time.Time
}

type DataRow

type DataRow struct {
	Time          time.Time `json:"time"`
	StationID     int32     `json:"station_id"`
	ModuleID      int64     `json:"module_id"`
	SensorID      int64     `json:"sensor_id"`
	DataStart     time.Time `json:"start"`
	DataEnd       time.Time `json:"end"`
	BucketSamples int       `json:"bucket_samples"`
	AverageValue  float64   `json:"average"`
	MinimumValue  float64   `json:"minimum"`
	MaximumValue  float64   `json:"maximum"`
	LastValue     float64   `json:"last"`
}

type InfluxDBBackend

type InfluxDBBackend struct {
	// contains filtered or unexported fields
}

func NewInfluxDBBackend

func NewInfluxDBBackend(config *InfluxDBConfig) (*InfluxDBBackend, error)

func (*InfluxDBBackend) QueryData

func (idb *InfluxDBBackend) QueryData(ctx context.Context, qp *backend.QueryParams) (*QueriedData, error)

func (*InfluxDBBackend) QueryRanges

func (idb *InfluxDBBackend) QueryRanges(ctx context.Context, qp *backend.QueryParams) (*DataRange, error)

func (*InfluxDBBackend) QueryRecentlyAggregated

func (idb *InfluxDBBackend) QueryRecentlyAggregated(ctx context.Context, stationIDs []int32, windows []time.Duration) (map[time.Duration][]*backend.DataRow, error)

func (*InfluxDBBackend) QueryTail

func (idb *InfluxDBBackend) QueryTail(ctx context.Context, stationIDs []int32) (*SensorTailData, error)

type InfluxDBConfig

type InfluxDBConfig struct {
	Url      string
	Token    string
	Username string
	Password string
	Org      string
	Bucket   string
}

type InfluxDBWindow

type InfluxDBWindow struct {
	Specifier string
	Interval  time.Duration
}

func (*InfluxDBWindow) CalculateMaximumRows

func (w *InfluxDBWindow) CalculateMaximumRows(start, end time.Time) int64

type LastTimeRow

type LastTimeRow struct {
	StationID int32     `json:"station_id"`
	LastTime  time.Time `json:"last_time"`
}

type PostgresBackend

type PostgresBackend struct {
	// contains filtered or unexported fields
}

func NewPostgresBackend

func NewPostgresBackend(db *sqlxcache.DB) *PostgresBackend

func (*PostgresBackend) QueryData

func (pgb *PostgresBackend) QueryData(ctx context.Context, qp *backend.QueryParams) (*QueriedData, error)

func (*PostgresBackend) QueryRecentlyAggregated

func (pgb *PostgresBackend) QueryRecentlyAggregated(ctx context.Context, stationIDs []int32, windows []time.Duration) (*RecentlyAggregated, error)

func (*PostgresBackend) QueryTail

func (pgb *PostgresBackend) QueryTail(ctx context.Context, stationIDs []int32) (*SensorTailData, error)

type QueriedData

type QueriedData struct {
	Data          []*backend.DataRow    `json:"data"`
	BucketSize    int                   `json:"bucketSize"`
	BucketSamples int                   `json:"bucketSamples"`
	DataEnd       *data.NumericWireTime `json:"dataEnd"`
}

type RecentlyAggregated

type RecentlyAggregated struct {
	Windows  map[time.Duration][]*backend.DataRow `json:"windows"`
	Stations map[int32]*StationLastTime           `json:"stations"`
}

type SelectedAggregate

type SelectedAggregate struct {
	Specifier  string
	BucketSize int
	DataEnd    *time.Time
}

type SensorTailData

type SensorTailData struct {
	Data     []*backend.DataRow         `json:"data"`
	Stations map[int32]*StationTailInfo `json:"stations"`
}

type StationLastTime

type StationLastTime struct {
	Last *data.NumericWireTime `json:"last"`
}

type StationTailInfo

type StationTailInfo struct {
	BucketSize    int `json:"bucketSize"`
	BucketSamples int `json:"bucketSamples"`
}

type TailedStation

type TailedStation struct {
	StationID  int32
	Rows       []*backend.DataRow
	BucketSize int
}

type TimeScaleDBBackend

type TimeScaleDBBackend struct {
	// contains filtered or unexported fields
}

func NewTimeScaleDBBackend

func NewTimeScaleDBBackend(config *storage.TimeScaleDBConfig, db *sqlxcache.DB, metrics *logging.Metrics, querySpec *data.QueryingSpec) (*TimeScaleDBBackend, error)

func (*TimeScaleDBBackend) QueryData

func (tsdb *TimeScaleDBBackend) QueryData(ctx context.Context, qp *backend.QueryParams) (*QueriedData, error)

func (*TimeScaleDBBackend) QueryRecentlyAggregated

func (tsdb *TimeScaleDBBackend) QueryRecentlyAggregated(ctx context.Context, stationIDs []int32, windows []time.Duration) (*RecentlyAggregated, error)

func (*TimeScaleDBBackend) QueryTail

func (tsdb *TimeScaleDBBackend) QueryTail(ctx context.Context, stationIDs []int32) (*SensorTailData, error)

type TimeScaleDBWindow

type TimeScaleDBWindow struct {
	Specifier string
	Interval  time.Duration
}

func (*TimeScaleDBWindow) BucketSize

func (w *TimeScaleDBWindow) BucketSize() int

func (*TimeScaleDBWindow) CalculateMaximumRows

func (w *TimeScaleDBWindow) CalculateMaximumRows(start, end time.Time) int

Jump to

Keyboard shortcuts

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