Documentation
¶
Index ¶
- Constants
- Variables
- func H3IndexFromLatLon(lat, lon float64, rs RegionSize) h3.H3Index
- func NewMemoryState() *memoryState
- func Walk(v Visitor, node Expr)
- func WalkFunc(node Expr, fn func(Expr))
- type AfterDetectFunc
- type BaseLit
- type BeforeDetectFunc
- type BinaryExpr
- type BooleanLit
- type Decl
- type Detector
- type Device
- type DeviceID
- type DeviceIterFunc
- type DeviceLit
- type Devices
- type DevicesLit
- type DistanceLit
- type DistanceUnit
- type DurationLit
- type Engine
- func (e *Engine) AddRule(ctx context.Context, spec string) (*Rule, error)
- func (e *Engine) AssignCoordsFromSpec(ctx context.Context, rule *Rule) (err error)
- func (e *Engine) Detect(ctx context.Context, device *Device) (events []Event, ok bool, err error)
- func (e *Engine) Devices() Devices
- func (e *Engine) Objects() Objects
- func (e *Engine) Rules() Rules
- func (e *Engine) States() States
- type Event
- type Expr
- type FloatLit
- type GeoObject
- func (o *GeoObject) Boundary() geometry.Rect
- func (o *GeoObject) Center() geometry.Point
- func (o *GeoObject) Contains(other *GeoObject) bool
- func (o *GeoObject) Data() geojson.Object
- func (o *GeoObject) ID() ObjectID
- func (o *GeoObject) Intersects(other *GeoObject) bool
- func (o *GeoObject) Layer() LayerID
- func (o *GeoObject) RegionID() []RegionID
- func (o *GeoObject) RegionSize() RegionSize
- func (o *GeoObject) Within(other *GeoObject) bool
- type IDLit
- type IdentLit
- type IntLit
- type InvalidExprError
- type LayerID
- type ListLit
- type Match
- type Object
- type ObjectID
- type ObjectIterFunc
- type ObjectLit
- type Objects
- type Option
- type ParenExpr
- type Parser
- type ParserError
- type PointLit
- type Pos
- type PropExpr
- type Region
- type RegionID
- type RegionSize
- type RepeatMode
- type ResetLit
- type Rule
- func (r *Rule) Bounding() geometry.Rect
- func (r *Rule) Center() geometry.Point
- func (r *Rule) ID() RuleID
- func (r *Rule) MarshalJSON() ([]byte, error)
- func (r *Rule) RefIDs() (refs map[xid.ID]Token)
- func (r *Rule) RegionIDs() (ids []RegionID)
- func (r *Rule) RegionSize() RegionSize
- func (r *Rule) Regions() []Region
- func (r *Rule) Snapshot() RuleSnapshot
- func (r *Rule) Specification() string
- func (r *Rule) UnmarshalJSON(data []byte) (err error)
- type RuleID
- type RuleIterFunc
- type RuleSnapshot
- type Rules
- type Scanner
- type State
- func (s *State) DeviceID() DeviceID
- func (s *State) FromSnapshot(snap StateSnapshot)
- func (s *State) HitIncr()
- func (s *State) Hits() int
- func (s *State) ID() StateID
- func (s *State) LastResetTime() int64
- func (s *State) LastSeenTime() int64
- func (s *State) LastVisit(objectID string) int64
- func (s *State) NeedReset(interval time.Duration) bool
- func (s *State) Reset()
- func (s *State) RuleID() RuleID
- func (s *State) SetLastVisit(objectID string, visit int64)
- func (s *State) SetTime(now int64)
- func (s *State) Snapshot() StateSnapshot
- func (s *State) UpdateLastResetTime()
- func (s *State) UpdateLastSeenTime()
- type StateID
- type StateSnapshot
- type States
- type StringLit
- type TimeLit
- type Token
- type TriggerLit
- type VarLit
- type Visitor
Constants ¶
View Source
const ( TinyRegionSize RegionSize = 3 SmallRegionSize RegionSize = 2 LargeRegionSize RegionSize = 1 TinyRegionThreshold = 50000 // meters SmallRegionThreshold = 100000 // meters LargeRegionThreshold = 300000 // meters )
Variables ¶
View Source
var DefaultLayer = xid.NilID()
View Source
var ErrDeviceNotFound = errors.New("spinix/devices: not found")
View Source
var ErrObjectNotFound = errors.New("spinix/objects: not found")
View Source
var ErrRuleNotFound = errors.New("spinix/rule: rule not found")
View Source
var ErrStateNotFound = errors.New("spinix/states: not found")
Functions ¶
func H3IndexFromLatLon ¶
func H3IndexFromLatLon(lat, lon float64, rs RegionSize) h3.H3Index
func NewMemoryState ¶
func NewMemoryState() *memoryState
Types ¶
type AfterDetectFunc ¶
type BeforeDetectFunc ¶
type BinaryExpr ¶
A BinaryExpr nodes represents a binary expression.
func (*BinaryExpr) String ¶
func (e *BinaryExpr) String() string
type BooleanLit ¶
A BooleanLit represents a boolean literal.
func (*BooleanLit) String ¶
func (e *BooleanLit) String() string
type Device ¶
type Device struct {
ID DeviceID `json:"id"`
Layer LayerID `json:"layerId"`
IMEI string `json:"imei"`
Owner string `json:"owner"`
Brand string `json:"brand"`
Model string `json:"model"`
Latitude float64 `json:"lat"`
Longitude float64 `json:"lon"`
Altitude float64 `json:"alt"`
Speed float64 `json:"speed"`
DateTime int64 `json:"dateTime"`
Status int `json:"status"`
BatteryCharge float64 `json:"batteryCharge"`
Temperature float64 `json:"temperature"`
Humidity float64 `json:"humidity"`
Luminosity float64 `json:"luminosity"`
Pressure float64 `json:"pressure"`
FuelLevel float64 `json:"fuelLevel"`
// contains filtered or unexported fields
}
func (*Device) DetectRegion ¶
func (d *Device) DetectRegion()
func (*Device) RegionSize ¶
func (d *Device) RegionSize() RegionSize
func (*Device) ResetRegion ¶
func (d *Device) ResetRegion()
type Devices ¶
type Devices interface {
Lookup(ctx context.Context, id DeviceID) (*Device, error)
InsertOrReplace(ctx context.Context, device *Device) (bool, error)
Delete(ctx context.Context, id DeviceID) error
Each(ctx context.Context, rid RegionID, size RegionSize, fn DeviceIterFunc) error
Near(ctx context.Context, lat, lon, meters float64, fn DeviceIterFunc) error
}
func NewMemoryDevices ¶
func NewMemoryDevices() Devices
type DevicesLit ¶
func (*DevicesLit) String ¶
func (e *DevicesLit) String() string
type DistanceLit ¶
type DistanceLit struct {
Unit DistanceUnit
Value float64
Pos Pos
}
func (*DistanceLit) String ¶
func (e *DistanceLit) String() string
type DistanceUnit ¶
type DistanceUnit int
const ( DistanceUndefined DistanceUnit = 0 DistanceMeters DistanceUnit = 1 DistanceKilometers DistanceUnit = 2 )
func (DistanceUnit) String ¶
func (u DistanceUnit) String() string
type DurationLit ¶
func (*DurationLit) String ¶
func (e *DurationLit) String() string
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) AssignCoordsFromSpec ¶
type Event ¶
type Event struct {
ID string `json:"ID"`
Device Device `json:"device"`
DateTime int64 `json:"dateTime"`
Rule RuleSnapshot `json:"rule"`
Match []Match `json:"match"`
}
type GeoObject ¶
type GeoObject struct {
// contains filtered or unexported fields
}
func (*GeoObject) Intersects ¶
func (*GeoObject) RegionSize ¶
func (o *GeoObject) RegionSize() RegionSize
type InvalidExprError ¶
func (*InvalidExprError) Error ¶
func (e *InvalidExprError) Error() string
type ObjectLit ¶
type Objects ¶
type Objects interface {
Lookup(ctx context.Context, oid ObjectID) (*GeoObject, error)
Add(ctx context.Context, o *GeoObject) error
Delete(ctx context.Context, oid ObjectID) error
Each(ctx context.Context, lid LayerID, rid RegionID, fn ObjectIterFunc) error
Near(ctx context.Context, lid LayerID, lat, lon, meters float64, fn ObjectIterFunc) error
}
func NewMemoryObjects ¶
func NewMemoryObjects() Objects
type Option ¶
type Option func(*Engine)
func WithDetectAfter ¶
func WithDetectAfter(fn ...AfterDetectFunc) Option
func WithDetectBefore ¶
func WithDetectBefore(fn ...BeforeDetectFunc) Option
func WithDevicesStorage ¶
func WithObjectsStorage ¶
func WithRulesStorage ¶
func WithStatesStorage ¶
type ParenExpr ¶
type ParenExpr struct {
Expr Expr // parenthesized expression
}
A ParenExpr nodes represents a parenthesized expression.
type ParserError ¶
func (*ParserError) Error ¶
func (e *ParserError) Error() string
type Region ¶
type Region struct {
// contains filtered or unexported fields
}
func MakeRegion ¶
func MakeRegion(id RegionID, size RegionSize) Region
func (Region) Size ¶
func (r Region) Size() RegionSize
type RegionID ¶
type RegionID uint64
func RegionFromLatLon ¶
func RegionFromLatLon(lat, lon float64, rs RegionSize) RegionID
func RegionIDFromString ¶
func (RegionID) Size ¶
func (rid RegionID) Size() RegionSize
type RegionSize ¶
type RegionSize int
func RegionSizeFromMeters ¶
func RegionSizeFromMeters(value float64) RegionSize
func (RegionSize) IsLarge ¶
func (rs RegionSize) IsLarge() bool
func (RegionSize) IsSmall ¶
func (rs RegionSize) IsSmall() bool
func (RegionSize) IsTiny ¶
func (rs RegionSize) IsTiny() bool
func (RegionSize) String ¶
func (rs RegionSize) String() string
func (RegionSize) Threshold ¶
func (rs RegionSize) Threshold() float64
func (RegionSize) Validate ¶
func (rs RegionSize) Validate() (err error)
func (RegionSize) Value ¶
func (rs RegionSize) Value() int
type RepeatMode ¶
type RepeatMode int
const ( RepeatOnce RepeatMode = 1 RepeatEvery RepeatMode = 2 RepeatTimes RepeatMode = 3 )
func (RepeatMode) String ¶
func (rm RepeatMode) String() string
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
func RuleFromSpec ¶
func (*Rule) MarshalJSON ¶
func (*Rule) RegionSize ¶
func (r *Rule) RegionSize() RegionSize
func (*Rule) Snapshot ¶
func (r *Rule) Snapshot() RuleSnapshot
func (*Rule) Specification ¶
func (*Rule) UnmarshalJSON ¶
type RuleSnapshot ¶
type Rules ¶
type Rules interface {
Walk(ctx context.Context, lat float64, lon float64, fn RuleIterFunc) error
Insert(ctx context.Context, r *Rule) error
Delete(ctx context.Context, id RuleID) error
Lookup(ctx context.Context, id RuleID) (*Rule, error)
}
func NewMemoryRules ¶
func NewMemoryRules() Rules
type State ¶
type State struct {
// contains filtered or unexported fields
}
func (*State) FromSnapshot ¶
func (s *State) FromSnapshot(snap StateSnapshot)
func (*State) LastResetTime ¶
func (*State) LastSeenTime ¶
func (*State) SetLastVisit ¶
func (*State) Snapshot ¶
func (s *State) Snapshot() StateSnapshot
func (*State) UpdateLastResetTime ¶
func (s *State) UpdateLastResetTime()
func (*State) UpdateLastSeenTime ¶
func (s *State) UpdateLastSeenTime()
type StateSnapshot ¶
type StateSnapshot struct {
ID StateID `json:"ID"`
Now int64 `json:"now"`
LastSeenTime int64 `json:"lastSeenTime"`
LastResetTime int64 `json:"lastResetTime"`
Hits int `json:"hits"`
ObjectsVisits map[string]int64 `json:"objectsVisits"`
}
func (StateSnapshot) MarshalJSON ¶
func (s StateSnapshot) MarshalJSON() ([]byte, error)
func (*StateSnapshot) UnmarshalJSON ¶
func (s *StateSnapshot) UnmarshalJSON(data []byte) error
type States ¶
type States interface {
Lookup(ctx context.Context, id StateID) (*State, error)
Update(ctx context.Context, s *State) error
Make(ctx context.Context, id StateID) (*State, error)
Remove(ctx context.Context, id StateID) error
RemoveByRule(ctx context.Context, rid RuleID) error
RemoveByDevice(ctx context.Context, did DeviceID) error
}
type Token ¶
type Token int
const ( ILLEGAL Token = iota EOF IDENT // operation INT // 12345 FLOAT // 123.45 STRING // "abc" DEVICE // device RADIUS // radius BBOX // bbox TIME // time DURATION // duration AFTER // after FUELLEVEL // fuellevel PRESSURE // pressure LUMINOSITY // luminosity HUMIDITY // humidity TEMPERATURE // temperature BATTERY_CHARGE // batteryCharge STATUS // status SPEED // speed MODEL // model BRAND // brand OWNER // owner LAYER // layer IMEI // imei VAR_IDENT // @ YEAR // year MONTH // month WEEK // week DAY // day HOUR // hour DATE // date DATETIME // dateTime TRIGGER // trigger CENTER // center EXPIRE // expire RESET // reset AND // AND OR // OR IN // IN NIN // NOT IN RANGE // RANGE NRANGE // NOT RANGE NEAR // NEAR NNEAR // NOT NEAR INTERSECTS // INTERSECTS NINTERSECTS // NOT INTERSECTS SUB // - EQ // eq i.e. == LT // lt i.e. < GT // gt i.e. > NE // ne i.e. != LTE // lte i.e. <= GTE // gte i.e. >= LBRACK // [ LBRACE // { COMMA // , PERIOD // . RBRACK // ] RBRACE // } COLON // : DEVICES // devices(@ID) OBJECTS // object(@ID, @id1) POLY // polygon(@id1, @id2, @id3), poly(@ID) MULTI_POLY // multiPolygon(@id1, @id2) LINE // line(@id1, @id2) MULTI_LINE // multiLine(@id1, @id2) POINT // point(@ID) MULTI_POINT // multiPoint(@ID) RECT // rect(@ID) CIRCLE // circle(@ID) COLLECTION // collection(@ID) FUT_COLLECTION // featureCollection(@id1, @id2, @id3) RPAREN // ) LPAREN // ( )
func LookupKeyword ¶
func (Token) IsGeospatial ¶
func (Token) IsOperator ¶
func (Token) Precedence ¶
type TriggerLit ¶
type TriggerLit struct {
Repeat RepeatMode
Interval time.Duration
Value time.Duration
Times int
Pos Pos
}
A TriggerLit represents a repeat mode type.
func (*TriggerLit) String ¶
func (e *TriggerLit) String() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
spinix
command
|
|
|
spinix-cli
command
|
|
|
gen
|
|
|
internal
|
|
|
mocks
|
|
|
tracker
Package mocktracker is a generated GoMock package.
|
Package mocktracker is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.