ch

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ch is used to interact with ClickHouse servers.

Index

Constants

View Source
const (
	// IntervalGroup is the column alias for the interval group.
	IntervalGroup  = "group_timestamp"
	AggNumberCol   = "agg_number"
	AggStringCol   = "agg_string"
	AggLocationCol = "agg_location"
)
View Source
const (

	// TimeoutErrCode is the error code returned by ClickHouse when a query is interrupted due to exceeding the max_execution_time.
	TimeoutErrCode = int32(159)
)

Variables

View Source
var SourceTranslations = map[string][]string{
	"macaron":  {"dimo/integration/2ULfuC8U9dOqRshZBAi0lMM1Rrx", "0x4c674ddE8189aEF6e3b58F5a36d7438b2b1f6Bc2"},
	"tesla":    {"dimo/integration/26A5Dk3vvvQutjSyF0Jka2DP5lg", "0xc4035Fecb1cc906130423EF05f9C20977F643722"},
	"autopi":   {"dimo/integration/27qftVRWQYpVDcO5DltO5Ojbjxk", "0x5e31bBc786D7bEd95216383787deA1ab0f1c1897"},
	"smartcar": {"dimo/integration/22N2xaPOq2WW2gAHBHd0Ikn4Zob", "0xcd445F4c6bDAD32b68a2939b912150Fe3C88803E"},
	"ruptela":  {"0xF26421509Efe92861a587482100c6d728aBf1CD0"},
	"compass":  {"0x55BF1c27d468314Ea119CF74979E2b59F962295c"},
	"motorq":   {"0x5879B43D88Fa93CE8072d6612cBc8dE93E98CE5d"},
}

Functions

This section is empty.

Types

type ActiveWindow added in v0.1.28

type ActiveWindow struct {
	WindowStart         time.Time
	WindowEnd           time.Time
	SignalCount         uint64
	DistinctSignalCount uint64
}

ActiveWindow represents a time window with sufficient signal activity

type AggSignal added in v0.1.19

type AggSignal struct {
	// SignalType describes the type of values in the aggregation:
	// float, string, or approximate location.
	SignalType FieldType
	// SignalIndex is an identifier for the aggregation within its
	// SignalType.
	//
	// For float and string aggregations this is simply an index
	// into the corresponding argument array.
	//
	// For approximate location (SignalType = AppLocType = 3), we
	// imagine expanding each element of the slice
	// model.AllFloatAggregation into two: first the latitude and then
	// the longitude. So, for example, SignalType = 3 and
	// SignalIndex = 4 means we want approximate latitude (4 % 2 = 0)
	// for the index 2 (4 / 2 = 2) float aggregation.
	//
	// We could get away with a single number, since we know how many
	// arguments of each type there are, but it appears to us that this
	// would make adding new types riskier.
	SignalIndex uint16
	// Timestamp is the timestamp for the bucket, the leftmost point.
	Timestamp time.Time
	// ValueNumber is the value for this row if it is of float or
	// approximate location type.
	ValueNumber float64
	// ValueNumber is the value for this row if it is of float or
	// approximate location type.
	ValueString   string
	ValueLocation vss.Location
}

type AliasHandleMapper added in v0.1.19

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

func NewAliasHandleMapper added in v0.1.19

func NewAliasHandleMapper() *AliasHandleMapper

func (*AliasHandleMapper) Add added in v0.1.19

func (m *AliasHandleMapper) Add(alias, handle string)

func (*AliasHandleMapper) Alias added in v0.1.19

func (m *AliasHandleMapper) Alias(handle string) string

func (*AliasHandleMapper) Handle added in v0.1.19

func (m *AliasHandleMapper) Handle(alias string) string

type CUSUMWindow added in v0.1.28

type CUSUMWindow struct {
	WindowStart         time.Time
	WindowEnd           time.Time
	SignalCount         uint64
	DistinctSignalCount uint64
	CUSUMStat           float64 // Cumulative sum statistic
	IsActive            bool    // Whether CUSUM exceeded threshold
}

CUSUMWindow represents a time window with CUSUM statistic

type ChangePointDetector added in v0.1.28

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

ChangePointDetector detects segments using CUSUM (Cumulative Sum) change point detection CUSUM monitors cumulative deviation from expected baseline to detect regime changes When vehicle becomes active, signal frequency increases significantly

func NewChangePointDetector added in v0.1.28

func NewChangePointDetector(conn clickhouse.Conn) *ChangePointDetector

NewChangePointDetector creates a new ChangePointDetector with the given connection

func (*ChangePointDetector) DetectSegments added in v0.1.28

func (d *ChangePointDetector) DetectSegments(
	ctx context.Context,
	tokenID uint32,
	from, to time.Time,
	config *model.SegmentConfig,
) ([]*Segment, error)

DetectSegments implements CUSUM-based change point detection

func (*ChangePointDetector) GetMechanismName added in v0.1.28

func (d *ChangePointDetector) GetMechanismName() string

GetMechanismName returns the name of this detection mechanism

type FieldType added in v0.1.19

type FieldType uint8

FieldType indicates the type of values in the aggregation. Currently there are three types: normal float values, string values, and "approximate location" values that are computed from the precise location values, in Go.

const (
	// FloatType is the type for rows with numeric values that are in
	// the VSS spec.
	FloatType FieldType = 1
	// StringType is the type for rows with string values.
	StringType FieldType = 2
	// AppLocType is the type for rows needed to compute approximate
	// locations.
	AppLocType FieldType = 3
	LocType    FieldType = 4
)

func (*FieldType) Scan added in v0.1.19

func (t *FieldType) Scan(value any) error

type FrequencyDetector added in v0.1.28

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

FrequencyDetector detects segments using frequency analysis of signal updates Analyzes signal update patterns to identify vehicle activity periods

func NewFrequencyDetector added in v0.1.28

func NewFrequencyDetector(conn clickhouse.Conn) *FrequencyDetector

NewFrequencyDetector creates a new FrequencyDetector with the given connection

func (*FrequencyDetector) DetectSegments added in v0.1.28

func (d *FrequencyDetector) DetectSegments(
	ctx context.Context,
	tokenID uint32,
	from, to time.Time,
	config *model.SegmentConfig,
) ([]*Segment, error)

DetectSegments implements frequency-based segment detection

func (*FrequencyDetector) GetMechanismName added in v0.1.28

func (d *FrequencyDetector) GetMechanismName() string

GetMechanismName returns the name of this detection mechanism

type IgnitionDetector added in v0.1.28

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

IgnitionDetector detects segments using ignition state transitions

func NewIgnitionDetector added in v0.1.28

func NewIgnitionDetector(conn clickhouse.Conn) *IgnitionDetector

NewIgnitionDetector creates a new IgnitionDetector with the given connection

func (*IgnitionDetector) DetectSegments added in v0.1.28

func (d *IgnitionDetector) DetectSegments(
	ctx context.Context,
	tokenID uint32,
	from, to time.Time,
	config *model.SegmentConfig,
) ([]*Segment, error)

DetectSegments implements ignition-based segment detection

func (*IgnitionDetector) GetMechanismName added in v0.1.28

func (d *IgnitionDetector) GetMechanismName() string

GetMechanismName returns the name of this detection mechanism

type Segment added in v0.1.28

type Segment struct {
	TokenID            uint32
	StartTime          time.Time
	EndTime            *time.Time
	DurationSeconds    int32
	IsOngoing          bool
	StartedBeforeRange bool
}

Segment represents a detected vehicle usage segment

type SegmentDetector added in v0.1.28

type SegmentDetector interface {
	// DetectSegments identifies vehicle usage segments using mechanism-specific logic
	DetectSegments(
		ctx context.Context,
		tokenID uint32,
		from, to time.Time,
		config *model.SegmentConfig,
	) ([]*Segment, error)

	// GetMechanismName returns the name of this detection mechanism
	GetMechanismName() string
}

SegmentDetector defines the interface for different segment detection mechanisms

type Service

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

Service is a ClickHouse service that interacts with the ClickHouse database.

func NewService

func NewService(settings config.Settings) (*Service, error)

NewService creates a new ClickHouse service.

func (*Service) GetAggregatedSignals

func (s *Service) GetAggregatedSignals(ctx context.Context, aggArgs *model.AggregatedSignalArgs) ([]*AggSignal, error)

GetAggregatedSignals returns a slice of aggregated signals based on the provided arguments from the ClickHouse database. The signals are sorted by timestamp in ascending order. The timestamp on each signal is for the start of the interval.

func (*Service) GetAvailableSignals added in v0.0.21

func (s *Service) GetAvailableSignals(ctx context.Context, tokenId uint32, filter *model.SignalFilter) ([]string, error)

GetAvailableSignals returns a slice of available signals from the ClickHouse database. if no signals are available, a nil slice is returned.

func (*Service) GetEvents added in v0.1.19

func (s *Service) GetEvents(ctx context.Context, subject string, from, to time.Time, filter *model.EventFilter) ([]*vss.Event, error)

func (*Service) GetLatestSignals

func (s *Service) GetLatestSignals(ctx context.Context, latestArgs *model.LatestSignalsArgs) ([]*vss.Signal, error)

GetLatestSignals returns the latest signals based on the provided arguments from the ClickHouse database.

func (*Service) GetSegments added in v0.1.28

func (s *Service) GetSegments(
	ctx context.Context,
	tokenID uint32,
	from, to time.Time,
	mechanism model.DetectionMechanism,
	config *model.SegmentConfig,
) ([]*Segment, error)

GetSegments returns segments detected using the specified mechanism

func (*Service) GetSignalSummaries added in v0.1.22

func (s *Service) GetSignalSummaries(ctx context.Context, tokenId uint32, filter *model.SignalFilter) ([]*model.SignalDataSummary, error)

type StateChange added in v0.1.28

type StateChange struct {
	Timestamp time.Time
	State     float64
	PrevState float64
}

StateChange represents a single state change from the signal_state_changes table

Jump to

Keyboard shortcuts

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