blips

package
v0.40.21 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package blips is the repair for wake-blip charges: rows the recorder wrote when a truck woke from sleep, its first vehicleState frame replayed the pre-sleep "charging_active" and the next frame, about a second later, said complete (fixed in the recorder by liveCharge.blip, #1254). A blip is a live charge shorter than 20 s that moved the battery less than half a point.

Unlike internal/repair/phantom this tool FINDS its candidates, by that one predicate, and an apply must present the count and the sha256 of the sorted id list of an approved dry run: anything else aborts the transaction. It deletes in one transaction, backs every row and its cascading dependents up (CSV and charges_deleted_backup, the phantom repair's format, so phantom.Restore and phantom.RestoreRows undo it), and refuses rows a user touched.

Index

Constants

View Source
const (
	MaxDuration = 20 * time.Second
	MaxSoCDelta = 0.5
	// RecentOpenWindow: an open live charge touched within this long means a truck is charging
	// now; the repair does not run then (the recorder is writing, and it is not a quiet hour).
	RecentOpenWindow = 15 * time.Minute
)

The recorder's bounds (internal/rivian liveChargeBlipMax and liveChargeBlipSoC): the repair uses the same predicate on stored rows.

Variables

View Source
var ErrDrift = errors.New("blips: the rows to delete differ from the approved dry run; nothing deleted")

ErrDrift: the rows no longer match the approved dry run (nothing was deleted).

View Source
var ErrOpenCharge = errors.New("blips: a live charge was written in the last 15 minutes; run in a quiet hour")

ErrOpenCharge: a truck is charging now; the repair does not run.

Functions

func Apply

func Apply(ctx context.Context, d *sql.DB, batchID uuid.UUID, wantCount int, wantDigest, reason string, allowOpen bool, sink func([]phantom.BackupRow) error) (int, error)

Apply deletes the blips in ONE transaction. It locks and re-selects the candidates, re-applies the rule, and aborts unless the count AND the digest of the sorted ids equal the approved dry run's. The backup rows (the charges and their cascading pack-health samples) go to sink (the durable CSV; an error aborts before anything is deleted) and to charges_deleted_backup when it exists. It aborts if the deleted count differs.

func Digest

func Digest(ids []uuid.UUID) string

Digest is the sha256 (hex) of the sorted ids, one per line: what a dry run prints and an apply must match.

func OpenCharges

func OpenCharges(ctx context.Context, q Queryer) (int, error)

OpenCharges counts live charges that are open and were written within RecentOpenWindow: a truck charging now.

Types

type Plan

type Plan struct {
	Delete  []Row
	Skipped map[string]int // reason -> count
}

Plan is the classified candidates.

func MakePlan

func MakePlan(rows []Row) Plan

MakePlan classifies rows.

func (Plan) ByMonth

func (p Plan) ByMonth() map[string]int

ByMonth counts the rows to delete per month of their start (UTC, "2006-01").

func (Plan) ByVehicle

func (p Plan) ByVehicle() map[uuid.UUID]int

ByVehicle counts the rows to delete per vehicle id.

func (Plan) IDs

func (p Plan) IDs() []uuid.UUID

IDs returns the ids to delete, sorted.

type Queryer

type Queryer interface {
	QueryContext(ctx context.Context, q string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, q string, args ...any) *sql.Row
}

Queryer is *sql.DB or *sql.Tx.

type Row

type Row struct {
	ID         uuid.UUID
	UserID     uuid.UUID
	VehicleID  uuid.UUID
	StartedAt  time.Time
	EndedAt    time.Time
	StartSoC   *float64
	EndSoC     *float64
	FinalState string
	Source     string
	CostSource string
	// What a person or another table says about the row.
	HasRestamp bool
	HasReceipt bool
	Edited     bool // a place or location override, a note or a tag
	HasPack    bool // a pack-health sample points at it (cascades; backed up)
}

Row is a candidate: a live charge shorter than MaxDuration, with what the rule needs.

func Select

func Select(ctx context.Context, q Queryer, forUpdate bool) ([]Row, error)

Select loads the candidates (every live charge shorter than MaxDuration), classified later. With forUpdate the rows are locked, for the transaction that deletes them.

type Verdict

type Verdict struct {
	Delete bool
	Reason string // why a row is skipped ("" when Delete)
}

Verdict is the rule's answer for one row.

func Classify

func Classify(r Row) Verdict

Classify applies the rule. User edits and anything open are refused before the physics test.

Jump to

Keyboard shortcuts

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