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
- Variables
- func AppURL() string
- func ApplySampleUserPrices(ctx context.Context, d *sql.DB, store pricer) (int, error)
- func ApplySampleWeather(ctx context.Context, d *sql.DB) (int64, error)
- func DemoNetworks() []settings.ChargingNetwork
- func DemoSchedule() offpeak.Schedule
- func Enabled() bool
- func MisconfiguredOnly() bool
- func OnlyEnabled() bool
- func PlanFixtures() ([]rivian.PlanFixture, error)
- func PresetIDs() []string
- func PresetsErr() error
- func PriceCandidates(ctx context.Context, cands []PriceCandidate, store pricer) (int, error)
- func RunPlans(ctx context.Context, d *sql.DB, sf *settings.Factory, every time.Duration, ...)
- func RunPricing(ctx context.Context, d *sql.DB, store pricer, every time.Duration, ...)
- func RunWeather(ctx context.Context, d *sql.DB, every time.Duration, ...)
- func SampleHistoryChargeRow(veh string, c rivian.SampleHistoryCharge) charges.Charge
- func SampleHistoryDriveRow(veh string, d rivian.SampleHistoryDrive) drives.Drive
- func SampleTripID(name string) uuid.UUID
- func SampleTripIDs() map[string]uuid.UUID
- func Seed(ctx context.Context, d Deps) error
- func SeedCharges(uid uuid.UUID, now time.Time) []charges.Charge
- func SeedDCFCharges(uid uuid.UUID, now time.Time) []charges.Charge
- func SeedDrives(uid uuid.UUID, now time.Time) []drives.Drive
- func SeedPlans(ctx context.Context, d *sql.DB, sf *settings.Factory, now time.Time) (int, error)
- func StrayOnly() bool
- func UserID() uuid.UUID
- func VehicleID() string
- type Deps
- type Preset
- type PresetBlob
- type PresetIndex
- type PresetSummary
- type PriceCandidate
- type SampleHistoryResult
- type SampleHistoryWriter
- type SamplePlan
Constants ¶
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).
const DemoOffpeakRate = 0.09
DemoOffpeakRate is the example overnight rate of the demo's schedule, USD per kWh, against HomeRate for every other hour. An example, not any utility's tariff.
const PresetsDir = "trips"
PresetsDir is where the preset files live, relative to this package.
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 ¶
var ( // ErrSampleHistoryRefused: the deployment is not one where this may run (prod, or no sim controls). ErrSampleHistoryRefused = errors.New("the sample history can only be written where the live Rivian client is forbidden and the sim controls are on") // ErrSampleHistoryDemo: the public demo account has its own seeded history. ErrSampleHistoryDemo = errors.New("the public demo account's history is not written here") // ErrNoRecordedHistory: the account has no recorded drive or charge to end the older history before. ErrNoRecordedHistory = errors.New("the account has no recorded history yet; connect the sample truck and let it record first") )
var PresetCostsAt = time.Date(2026, 10, 20, 0, 0, 0, 0, time.UTC)
PresetCostsAt is the date the preset plans' costs were priced: the observed third-party prices in them (dcfcrates, hand-copied from DCFC Tracker) were checked on this day, and the presets are static files, so they are built "as of" it and the test that compares them with the corpus stays deterministic.
REFRESH BY OCTOBER 2027: an observed price is hidden from live plans 12 months after its month, but a preset file keeps showing the figure it was built with (with its month in the label). When the figures in dcfcrates/observed.go are re-checked, move this date, regenerate the preset plans (see presets_gen_test.go) and the sample-trip pages built from them; if they are not re-checked, regenerate with no observed prices, so the demo stops showing a figure the live planner would hide.
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
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 ApplySampleWeather ¶ added in v0.38.4
ApplySampleWeather fills the sample weather. Idempotent; returns the rows added. The corpus loops and the replay records new drives, so the caller runs it again periodically.
func DemoNetworks ¶ added in v0.38.8
func DemoNetworks() []settings.ChargingNetwork
DemoNetworks is the demo user's price book: sample rates the "sample owner" has entered, so the demo's fast-charging sessions (priced from the user's own rate) keep their network estimates. The planner and the ledger no longer price anything from the dated built-in table, which shows no rate until a user enters one; these are fixtures like the rest of the demo, 2 cents off the table so that they read as the user's own (a row equal to the table's number is treated as never edited).
func DemoSchedule ¶ added in v0.38.10
DemoSchedule is the demo owner's example off-peak schedule: weekday nights from 21:00 to 06:00 in the home's time zone (Pasadena, Pacific time). It is what the public demo's savings card is computed from, shown as "Sample truck · example schedule". Normalized (the same checks as a user's schedule); the panic is for a programming error caught by the tests.
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 RunWeather ¶ added in v0.38.4
func RunWeather(ctx context.Context, d *sql.DB, every time.Duration, log func(msg string, args ...any))
RunWeather applies the sample weather now and then every interval until ctx ends.
func SampleHistoryChargeRow ¶ added in v1.3.5
func SampleHistoryChargeRow(veh string, c rivian.SampleHistoryCharge) charges.Charge
SampleHistoryChargeRow is the stored form of one generated charge.
func SampleHistoryDriveRow ¶ added in v1.3.5
func SampleHistoryDriveRow(veh string, d rivian.SampleHistoryDrive) drives.Drive
SampleHistoryDriveRow is the stored form of one generated drive.
func SampleTripID ¶ added in v0.34.0
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
SampleTripIDs maps each sample plan's name to its saved trip id.
func Seed ¶
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 ¶
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 SeedDCFCharges ¶ added in v0.38.4
SeedDCFCharges are three DC fast stops at 62, 79 and 96 days back that add 58% of the battery (from 18%), with effective pack figures of 129 to 133 kWh, so the capacity chart has enough qualifying charges over enough days. They are user-priced like the hotel L2 so they don't read as pending.
func SeedDrives ¶ added in v0.38.4
SeedDrives are short daily-commute drives from 47 to 119 days back, one every other day, 9 to 17 mi at the sample truck's 2.3 mi/kWh. They keep every calendar month in that span above the trend's 50 mi.
func SeedPlans ¶ added in v0.34.0
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).
Types ¶
type Deps ¶
type Deps struct {
DB *sql.DB
Settings *settings.Factory
Charges *charges.Factory
Drives *drives.Factory // optional: without it the older history is not seeded
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
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
PriceCandidate is a closed, unpriced demo charge.
type SampleHistoryResult ¶ added in v1.3.5
type SampleHistoryResult struct {
From time.Time `json:"from"`
Before time.Time `json:"before"`
Drives int `json:"drives"`
Charges int `json:"charges"`
Weather int64 `json:"weather"`
}
SampleHistoryResult is what a run wrote.
type SampleHistoryWriter ¶ added in v1.3.5
type SampleHistoryWriter struct {
DB *sql.DB
Drives *drives.Factory
Charges *charges.Factory
Getenv func(string) string
}
SampleHistoryWriter writes the older history for one account.
func (*SampleHistoryWriter) Allowed ¶ added in v1.3.5
func (w *SampleHistoryWriter) Allowed() bool
Allowed reports whether this deployment may write the sample history at all.
func (*SampleHistoryWriter) Run ¶ added in v1.3.5
func (w *SampleHistoryWriter) Run(ctx context.Context, uid uuid.UUID) (SampleHistoryResult, error)
Run writes uid's older history, ending before the account's first recorded row. Idempotent.
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.