Help us shape the future of Go! Take the 2026 Go Developer Survey

insights

package
v0.40.22 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package insights computes read-only breakdowns of the user's own recorded data. Efficiency: miles per kWh bucketed by outside temperature, average speed and drive mode over a period.

Index

Constants

View Source
const MinBucketMiles = 25.0

MinBucketMiles is the distance below which a bucket's efficiency is flagged not_enough_data: a few short drives, each quantized to a percent of SoC, don't make a figure. The UI decides how to show it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	Key           string   `json:"key"`
	Label         string   `json:"label"`
	Distance      float64  `json:"distance"`
	EnergyKWh     float64  `json:"energy_kwh"`
	Efficiency    *float64 `json:"efficiency"`
	Drives        int      `json:"drives"`
	NotEnoughData bool     `json:"not_enough_data"`
}

Bucket is one row of a breakdown. Efficiency is distance over energy across the bucket's drives (so weighted by distance, not by drive): nil without energy.

type DriveInput

type DriveInput struct {
	ID           string
	VehicleID    string
	StartedAt    time.Time
	EndedAt      time.Time
	CreatedAt    time.Time
	Source       string
	DistanceMi   float64
	EnergyKWh    float64
	AvgSpeedMph  float64
	OutsideTempC *float64
	DriveMode    string
	// Trailer is whether a trailer was connected (the user's correction, else what was recorded): the connector, not
	// the load. Such a drive is left out of every breakdown and the total, and is reported on its own (WithTrailer).
	Trailer bool
}

DriveInput is one recorded drive with the conditions it was driven in. OutsideTempC is the median non-zero outside temperature over the drive's samples (nil without any); DriveMode the mode it spent the most samples in, as the vehicle reports it ("everyday", "distance", ...).

type Efficiency

type Efficiency struct {
	Units          Units  `json:"units"`
	DistanceUnit   string `json:"distance_unit"`   // "mi" | "km"
	EfficiencyUnit string `json:"efficiency_unit"` // "mi/kWh" | "km/kWh"
	// MinBucketDistance is MinBucketMiles in DistanceUnit.
	MinBucketDistance float64 `json:"min_bucket_distance"`
	Total             Bucket  `json:"total"`
	// WithTrailer is the drives with a trailer connected, which the total and the breakdowns leave out so that
	// towing does not drag the truck's own figures. Drives is 0 when there are none.
	WithTrailer Bucket `json:"with_trailer"`
	// ByTemperature has a row per band, coldest first. Drives without an
	// outside temperature are left out and counted in Excluded.
	//
	// Later: energy_edge_compute.graphs.cold_weather_soc (Parallax, the
	// #343 capture; scratchpad parallax-next.md) carries the vehicle's own
	// share of SoC lost to cold and its range impact. Once promoted it
	// can sit beside these bands as Rivian's figure for the cold buckets.
	ByTemperature []Bucket `json:"by_temperature"`
	// BySpeed has a row per average-speed band, slowest first.
	BySpeed []Bucket `json:"by_speed"`
	// ByDriveMode has a row per mode, most distance first. Drives with no
	// recorded mode are left out and counted in Excluded.
	ByDriveMode []Bucket `json:"by_drive_mode"`
	Excluded    Excluded `json:"excluded"`
}

Efficiency is the response of /api/insights/efficiency.

func BuildEfficiency

func BuildEfficiency(ds []DriveInput, u Units) Efficiency

BuildEfficiency computes the breakdowns over ds (the period's drives).

type Excluded

type Excluded struct {
	// NoEnergy: no energy recorded, or a figure outside the plausible
	// range; left out of every breakdown and the total.
	NoEnergy int `json:"no_energy"`
	// Trailer: drives with a trailer connected; left out of the total and every breakdown, reported as WithTrailer.
	Trailer int `json:"trailer"`
	// Duplicates: overlapping duplicate recordings (the Money ledger's
	// rule); the kept recording counts.
	Duplicates int `json:"duplicates"`
	// NoTemperature / NoDriveMode: in the total, not in that breakdown.
	NoTemperature int `json:"no_temperature"`
	NoDriveMode   int `json:"no_drive_mode"`
}

Excluded counts the drives in the period left out of the breakdowns.

type Units

type Units string

Units picks the distance, speed and temperature units of the labels and figures.

const (
	Imperial Units = "imperial"
	Metric   Units = "metric"
)

Jump to

Keyboard shortcuts

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