cattrack

package
v0.0.0-...-4c2d33b Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GyroscopeProps = []string{"GyroscopeX", "GyroscopeY", "GyroscopeZ"}
View Source
var GyroscopeStableThresholdReading = 0.01

Functions

func IsCatContinuous

func IsCatContinuous(a, b CatTrack) bool

func MustContinuousTimeOffset

func MustContinuousTimeOffset(a, b CatTrack) time.Duration

MustContinuousTimeOffset is more than it seems. It returns the time offset between two tracks, but with magic/opinionated/adhoc caveats. If the offset is more than 24 hours, it resets to 1 second. If the offset is negative, it resets to 0.

func MustTimeOffset

func MustTimeOffset(a, b CatTrack) time.Duration

MustTimeOffset gets the time offset between two tracks, assuming a track happens before b track.

func NewDedupeLRUFunc

func NewDedupeLRUFunc(size int) func(CatTrack) bool

func SlicesSortFunc

func SlicesSortFunc(a, b CatTrack) int

SlicesSortFunc implements the slices.SortFunc for CatTrack slices. Sorting is done by time (chronologically, at 1 second granularity); then, in case of equivalence, by accuracy. > cmp(a, b) should return a negative number when a < b, > a positive number when a > b, and zero when a == b

func WithTimeOffset

func WithTimeOffset(ctx context.Context, in <-chan CatTrack) chan CatTrack

Types

type CatLap

type CatLap geojson.Feature

func NewCatLap

func NewCatLap(tracks []*CatTrack) *CatLap

func (*CatLap) BearingDeltaRate

func (cl *CatLap) BearingDeltaRate() float64

BearingDeltaRate is an experiment in spikeball identification.

func (*CatLap) DistanceTraversed

func (cl *CatLap) DistanceTraversed() (distance float64)

func (*CatLap) Duration

func (cl *CatLap) Duration() time.Duration

func (*CatLap) IsValid

func (cl *CatLap) IsValid() bool

func (CatLap) MarshalJSON

func (cl CatLap) MarshalJSON() ([]byte, error)

func (*CatLap) SelfIntersectionRate

func (cl *CatLap) SelfIntersectionRate() float64

func (*CatLap) UnmarshalJSON

func (cl *CatLap) UnmarshalJSON(data []byte) error

type CatNap

type CatNap geojson.Feature

func NewCatNap

func NewCatNap(tracks []*CatTrack) *CatNap

func (*CatNap) IsValid

func (cn *CatNap) IsValid() bool

func (CatNap) MarshalJSON

func (cn CatNap) MarshalJSON() ([]byte, error)

func (*CatNap) UnmarshalJSON

func (cn *CatNap) UnmarshalJSON(data []byte) error

type CatTrack

type CatTrack geojson.Feature

CatTrack is a track a cat makes. It's an alias of geojson.Feature, with definite point geometry, and a time property. (This might want to - someday - become a more generic type of type; for example, a struct with a geojson.Feature embedded, or pure []byte's.) A geojson.Feature is a data structure with a type, geometry, and properties, which implements a special encoding spec (GeoJSON), which is conventional for geographic data. Notably, a geojson.Feature has no concept of time, but a CatTrack is as much a point in time as it is a point in space. catd and Cat Tracks use `properties.Time` and `properties.UnixTime` almost interchangeably, and they're in use constantly. UnixTime is preferred, since it represents 1-second granularity, which Cat Tracks asserts.

func Lap2Track

func Lap2Track(lap CatLap) CatTrack

func Lap2TrackP

func Lap2TrackP(lap *CatLap) *CatTrack

func Nap2Track

func Nap2Track(nap CatNap) CatTrack

func Nap2TrackP

func Nap2TrackP(nap *CatNap) *CatTrack

func NewCatTrack

func NewCatTrack(geometry orb.Geometry) *CatTrack

NewCatTrack creates and initializes a GeoJSON feature given the required attributes.

func Sanitize

func Sanitize(ct CatTrack) CatTrack

Sanitize normalizes and streamlines a track. It sets an Alias (cat alias/catID/conceptual.CatID/nee-Name) property unless already set. It removes unnecessary properties, and sets a zero-value ID.

func SetTimeOffset

func SetTimeOffset(old, next CatTrack) CatTrack

func (*CatTrack) CatID

func (ct *CatTrack) CatID() conceptual.CatID

CatID conceptually returns the CatID of the track.

func (*CatTrack) Copy

func (ct *CatTrack) Copy() *CatTrack

Copy returns a deep copy of the track.

func (*CatTrack) DeletePropertySafe

func (ct *CatTrack) DeletePropertySafe(key string)

DeletePropertySafe deletes properties in thread safety. See SetPropertySafe.

func (*CatTrack) HasRawB64Image

func (ct *CatTrack) HasRawB64Image() bool

func (*CatTrack) HasS3URL

func (ct *CatTrack) HasS3URL() bool

func (*CatTrack) IsEmpty

func (ct *CatTrack) IsEmpty() bool

IsEmpty is useful for dealing with zero-value tracks.

func (*CatTrack) IsGyroOK

func (ct *CatTrack) IsGyroOK() bool

IsGyroOK checks the gyro properties for presence and validity.

func (*CatTrack) IsSnap

func (ct *CatTrack) IsSnap() bool

func (*CatTrack) IsValid

func (ct *CatTrack) IsValid() bool

func (CatTrack) MarshalJSON

func (ct CatTrack) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CatTrack) MustActivity

func (ct *CatTrack) MustActivity() activity.Activity

func (*CatTrack) MustS3Key

func (ct *CatTrack) MustS3Key() string

MustS3Key returns the conventional "key" for use primarily with catsnaps. If AWS S3 upload configured, that uses: AWS_BUCkETNAME/this-key. It is a cat/device/time-unique value.

func (*CatTrack) MustTime

func (ct *CatTrack) MustTime() time.Time

MustTime gets the time or panics.

func (CatTrack) Point

func (ct CatTrack) Point() orb.Point

Point returns the Point a cat is or was at.

func (*CatTrack) S3SnapBucketName

func (ct *CatTrack) S3SnapBucketName() string

S3SnapBucketName returns the bucket name from the imgS3 field, conventionally using the first of (two) /-delimited values.

func (*CatTrack) SetPropertiesSafe

func (ct *CatTrack) SetPropertiesSafe(props map[string]interface{})

SetPropertiesSafe sets properties in thread safety. See SetPropertySafe.

func (*CatTrack) SetPropertySafe

func (ct *CatTrack) SetPropertySafe(key string, val any)

SetPropertySafe sets a property on a track in a thread safe way. Thread safe is not atomic, nor guaranteed stable. Unexpected side effects may occur.

func (*CatTrack) StringPretty

func (ct *CatTrack) StringPretty() string

func (*CatTrack) Time

func (ct *CatTrack) Time() (time.Time, error)

Time Here's a big deal. Cat Tracks only deals in tracks with a granularity of 1 second. Cat Tracks prefers the UnixTime property, but if it's not there, falls back to Time, which should be a string in RFC3339 format. If both times exist, they must be within 1 second of each other.

func (*CatTrack) UnmarshalJSON

func (ct *CatTrack) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*CatTrack) Validate

func (ct *CatTrack) Validate() error

Validate checks the track for basic validity. It returns the first error it encounters. TODO: JSON schema?

func (*CatTrack) ValidateSnap

func (ct *CatTrack) ValidateSnap() error

type Indexer

type Indexer interface {
	// FromCatTrack associates a given cattrack value with an Indexer.
	// The indexer can choose to maintain a reference to the CatTrack or not.
	// Since the Indexer is responsible for managing the/a/some CatTrack's properties,
	// it should be able to read relevant data from the cattrack too,
	// and this is where you do that.
	// It should return a new Indexer instance.
	FromCatTrack(ct CatTrack) Indexer

	// IsEmpty returns true if the Indexer has no data.
	// The initial 'loaded' index value of an Indexer is considered always empty,
	// and may be nil.
	IsEmpty() bool

	// Index applies the next Indexer to the current Indexer.
	// This is where this accumulator is seduced.
	// The Indexer should return a new Indexer instance.
	Index(old, next Indexer) Indexer

	// ApplyToCatTrack applies the Indexer a given CatTrack,
	// usually the one that was used to create the Indexer.
	// The Indexer should return a new CatTrack value ref.
	// This is where you install the properties, or modify the geometry,
	// or do whatever cat track magic you need to do.
	ApplyToCatTrack(idxr Indexer, ct CatTrack) CatTrack
}

Indexer is an interface that defines the methods for indexing a CatTrack. By another name, a Reducer. Maybe, a dimension reducer. CatTrack asserts here its own opinion that it is the only type of data that can be indexed. Some day, the Indexer (actually, Reducer) will take the Index and IsEmpty interface methods for its own, and will deal in any kind of data structure you want. Then, FromCatTrack might become Unmarshal/Decode, and ApplyToCatTrack might become Marshal/Encode.

type OffsetIndexT

type OffsetIndexT struct {
	Count int

	// VisitCount is the number of times the cat has entered and left this cell.
	// It is bounded by a time threshold which the cat needs to exceed
	// in order to be considered as "having left".
	VisitCount     int
	VisitThreshold time.Duration

	FirstTime time.Time
	LastTime  time.Time

	// TotalTimeOffset is the sum of the time (track offsets) spent in the cell.
	TotalTimeOffset time.Duration

	// Activity is the primary activity mode of the cat while in the cell.
	Activity activity.Activity

	// AMx are the activity tallies measured in cumulative time offset seconds.
	AMUnknown    float64
	AMStationary float64
	AMWalking    float64
	AMRunning    float64
	AMBike       float64
	AMAutomotive float64
	AMFly        float64
}

OffsetIndexT is an Indexer implementation that tracks the number of times a cat has entered and left a cell, as well as the total time spent in the cell. It also tracks the activity mode of the cat while in the cell, and the first and last times the cat was in the cell. TODO: Pull apart into OffsetIndexT and OffsetIndexActivityT.

func (*OffsetIndexT) ApplyToCatTrack

func (*OffsetIndexT) ApplyToCatTrack(idxr Indexer, ct CatTrack) CatTrack

func (*OffsetIndexT) FromCatTrack

func (*OffsetIndexT) FromCatTrack(ct CatTrack) Indexer

func (*OffsetIndexT) Index

func (ix *OffsetIndexT) Index(old, next Indexer) Indexer

func (*OffsetIndexT) IsEmpty

func (ix *OffsetIndexT) IsEmpty() bool

type SinkerErrFn

type SinkerErrFn func(track CatTrack) error

type SinkerFn

type SinkerFn func(track CatTrack)

type TransformerErrFn

type TransformerErrFn func(track CatTrack) (CatTrack, error)

type TransformerFn

type TransformerFn func(track CatTrack) CatTrack

Jump to

Keyboard shortcuts

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