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
- func AppURL() string
- func ApplySampleUserPrices(ctx context.Context, d *sql.DB, store pricer) (int, error)
- func Enabled() bool
- func MisconfiguredOnly() bool
- func OnlyEnabled() bool
- 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 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 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 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 PresetsDir = "trips"
PresetsDir is where the preset files live, relative to this package.
const Username = "rivolt-public-demo"
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
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 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
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 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
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 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.