demo

package
v0.37.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package demo seeds and identifies the public read-only demo account (B7). It is PREVIEW ONLY: Enabled requires RIVOLT_DEMO=true and RIVIAN_CLIENT=replay and RIVOLT_REPLAY_SOURCE=sample, so a production install (live client) never turns it on even if the variable leaks into its environment.

Index

Constants

View Source
const (
	HomeLat   = 34.1613
	HomeLon   = -118.1676
	HomeLabel = "Rose Bowl parking (sample)"
	// HomeRate is the demo's home $/kWh, USD.
	HomeRate = 0.16
)

The demo truck's "home": the sample generator's public, non- residential stadium parking lot (never anyone's address).

View Source
const PresetsDir = "trips"

PresetsDir is where the preset files live, relative to this package.

View Source
const Username = db.DemoUsername

Username is the demo account's username. It has no @, so it can't collide with a real (email-derived) sign-in, and nobody holds a credential for it: it is only ever reached through the anonymous, read-only allowlist.

Variables

This section is empty.

Functions

func AppURL added in v0.34.0

func AppURL() string

AppURL is the real app's origin (RIVOLT_APP_URL), where the standalone demo's sign-in and sign-up links point. Only a plain http(s) origin is accepted (no credentials, query or fragment); anything else is "" so the config never carries a link the operator didn't mean. A trailing slash and any path are dropped.

func ApplySampleUserPrices added in v0.33.0

func ApplySampleUserPrices(ctx context.Context, d *sql.DB, store pricer) (int, error)

ApplySampleUserPrices gives the demo truck's hand-priced session (the Las Vegas hotel L2, a flat $15 in the sample corpus) its user price after replay has recorded it. The recorder cannot invent a price only a person enters, so this is the demo's stand-in for that person. It uses the same store path as PATCH /charges/{id}/pricing, which stamps cost_source = user.

Only CLOSED charges with no cost source are touched: an open charge is still being upserted by the recorder, which would overwrite the price. Idempotent; returns how many rows it priced. The corpus loops, so the caller runs it again periodically.

func Enabled

func Enabled() bool

Enabled reports whether the demo is on: RIVOLT_DEMO=true on an install running the replay client over the GENERATED sample corpus (RIVOLT_REPLAY_SOURCE=sample). Replaying a recorded vehicle would publish a real person's history anonymously, so anything else fails closed.

func MisconfiguredOnly added in v0.34.0

func MisconfiguredOnly() bool

MisconfiguredOnly reports a half-configured standalone demo: RIVOLT_DEMO_ONLY=true and RIVOLT_DEMO=true, but not the replay sample setup the demo needs. The caller refuses to boot: serving a half-demo install to the public is worse than not starting.

func OnlyEnabled added in v0.34.0

func OnlyEnabled() bool

OnlyEnabled reports whether this install is the standalone public demo (demo.rivolt.dev): RIVOLT_DEMO_ONLY=true on an install where Enabled holds. It is a strict subset of Enabled, so a prod install (live client) can never turn it on even if the variable leaks into its environment. In this mode the process serves nothing but the demo: no sign-in, signup, mail, push or events, and every /api route outside the demo allowlist is a 404.

func PlanFixtures added in v0.37.0

func PlanFixtures() ([]rivian.PlanFixture, error)

PlanFixtures turns the preset trips into stored plans for the fixture planner (rivian.FixturePlanner): each preset's origin, destination and starting SoC with its plan. Presets with intermediate stops are left out, as the fixture planner matches two-point trips only.

func PresetIDs added in v0.34.0

func PresetIDs() []string

PresetIDs lists the preset ids in index order.

func PresetsErr added in v0.34.0

func PresetsErr() error

PresetsErr reports why the embedded presets were rejected, if they were.

func PriceCandidates added in v0.33.0

func PriceCandidates(ctx context.Context, cands []PriceCandidate, store pricer) (int, error)

PriceCandidates prices the candidates the sample corpus says a person priced by hand, and returns how many it priced.

func RunPlans added in v0.34.0

func RunPlans(ctx context.Context, d *sql.DB, sf *settings.Factory, every time.Duration, log func(msg string, args ...any))

RunPlans seeds the saved plans now and then every interval until ctx ends, so they follow the replay onto each loop's trip.

func RunPricing added in v0.33.0

func RunPricing(ctx context.Context, d *sql.DB, store pricer, every time.Duration, log func(msg string, args ...any))

RunPricing applies the sample user prices now and then every interval until ctx ends (replay backfill and corpus loops bring new sessions).

func SampleTripID added in v0.34.0

func SampleTripID(name string) uuid.UUID

SampleTripID is the saved trip id of the sample plan called name: fixed, so the demo's preset trip for it (internal/demo/trips) carries the same id on every install.

func SampleTripIDs added in v0.34.0

func SampleTripIDs() map[string]uuid.UUID

SampleTripIDs maps each sample plan's name to its saved trip id.

func Seed

func Seed(ctx context.Context, d Deps) error

Seed creates (or refreshes) the demo user, its settings, its replay session and a few older charges. Idempotent; safe at every boot. It does nothing unless Enabled.

func SeedCharges

func SeedCharges(uid uuid.UUID, now time.Time) []charges.Charge

SeedCharges are the hand-written older sessions that complete the cost-source set (the replay stream supplies home_rate, network_estimate, the Rivian-billed DC fast and, via ApplySampleUserPrices, the user-priced hotel L2): a pending (unpriced) AC session and a home-rate home session. They sit 50-60 days back, before the 45-day replay corpus, so they never overlap a replayed session. Times are day-aligned, so reseeding is stable.

func SeedPlans added in v0.34.0

func SeedPlans(ctx context.Context, d *sql.DB, sf *settings.Factory, now time.Time) (int, error)

SeedPlans writes the demo's saved plans for now, and returns how many rows it changed. Idempotent: a row is rewritten only when its plan or inputs changed (the next loop's trip, or new settings).

func StrayOnly added in v0.34.0

func StrayOnly() bool

StrayOnly reports RIVOLT_DEMO_ONLY=true without RIVOLT_DEMO=true: not a demo install at all, just a stray variable. It is ignored (the caller logs a loud warning) rather than refused, so it can never take a real install down.

func UserID

func UserID() uuid.UUID

UserID is the demo account's user id.

func VehicleID

func VehicleID() string

VehicleID is the demo vehicle's Rivian id.

Types

type Deps

type Deps struct {
	DB       *sql.DB
	Settings *settings.Factory
	Charges  *charges.Factory
	Secrets  *secrets.Store
	Now      func() time.Time
}

Deps are what Seed writes through.

type Preset added in v0.34.0

type Preset struct {
	ID      string          `json:"id"`
	Name    string          `json:"name"`
	Inputs  json.RawMessage `json:"inputs"`
	Summary PresetSummary   `json:"summary"`
	// RoutePolyline is the route's road shape (Valhalla's, simplified)
	// through every waypoint, as a Google encoded polyline of precision
	// 6, for the map: the demo can't ask Valhalla for it.
	RoutePolyline string `json:"route_polyline"`
}

Preset is one preset trip in index.json.

type PresetBlob added in v0.34.0

type PresetBlob struct {
	Body []byte
	ETag string
}

PresetBlob is a static JSON document with its ETag.

func PresetPlan added in v0.34.0

func PresetPlan(id string) (PresetBlob, bool)

PresetPlan returns the stored plan for a preset id.

func PresetsIndex added in v0.34.0

func PresetsIndex() PresetBlob

PresetsIndex is the preset list document, `{"trips":[...]}`. Empty list when the data is absent or malformed (see PresetsErr).

type PresetIndex added in v0.34.0

type PresetIndex struct {
	Trips []Preset `json:"trips"`
}

PresetIndex is index.json.

type PresetSummary added in v0.34.0

type PresetSummary struct {
	DistanceMi    float64 `json:"distance_mi"`
	DurationMin   float64 `json:"duration_min"`
	ChargeStops   int     `json:"charge_stops"`
	ArrivalSoCPct float64 `json:"arrival_soc_pct"`
}

PresetSummary is what the preset list shows.

type PriceCandidate added in v0.33.0

type PriceCandidate struct {
	ID        string
	StartedAt time.Time
}

PriceCandidate is a closed, unpriced demo charge.

type SamplePlan added in v0.34.0

type SamplePlan struct {
	ID       uuid.UUID // fixed: SampleTripID(Name)
	Name     string
	SavedAt  time.Time
	Inputs   json.RawMessage // the planner's SavedTripInputs
	Plan     json.RawMessage // rivian.TripPlan plus costs, as /api/trips/plan returns it
	DepartAt time.Time
}

SamplePlan is one saved trip as the planner stores it.

func SamplePlans added in v0.34.0

func SamplePlans(now, since time.Time, cfg settings.ChargingConfig, nets []settings.ChargingNetwork) ([]SamplePlan, error)

SamplePlans returns the demo's saved plans for the latest sample road trip over by now that started at or after since (the demo truck's first recorded frame, so the trip is recorded whole), priced with the demo user's charging settings (cfg, nets) as /api/trips/plan prices a plan. Nil when there is no such trip.

Jump to

Keyboard shortcuts

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