diff --git a/web/src/app/charging/page.tsx b/web/src/app/charging/page.tsx index 0f0c9c6..16f8279 100644 --- a/web/src/app/charging/page.tsx +++ b/web/src/app/charging/page.tsx @@ -57,6 +57,7 @@ export default async function ChargingPage() {
{dateTime(session.startedAt)}
+ {session.isDemo && "Demo · "} {duration(session.durationSeconds)} {gained !== null && ` · %${num(session.startSocPercent as number)} → %${num(session.endSocPercent as number)}`}
diff --git a/web/src/lib/mongo.ts b/web/src/lib/mongo.ts index 4bac775..230422c 100644 --- a/web/src/lib/mongo.ts +++ b/web/src/lib/mongo.ts @@ -45,6 +45,7 @@ export interface ChargingSession { gridEnergyKwh: number; pricePerKwh: number; totalCost: number; + isDemo?: boolean; startSocPercent?: number; endSocPercent?: number; curve: CurvePoint[]; diff --git a/web/src/lib/validate.ts b/web/src/lib/validate.ts index 333a916..2f9447a 100644 --- a/web/src/lib/validate.ts +++ b/web/src/lib/validate.ts @@ -49,6 +49,7 @@ export function validateChargingSession(body: unknown, pathSessionId: string): C }); const startSocPercent = record.startSocPercent; const endSocPercent = record.endSocPercent; + const isDemo = record.isDemo; const energyKwh = bounded(record.energyKwh, 0, 1000, "energyKwh"); const pricePerKwh = bounded(record.pricePerKwh, 0, 1_000_000, "pricePerKwh"); const chargingLossPercent = 10; @@ -64,6 +65,7 @@ export function validateChargingSession(body: unknown, pathSessionId: string): C gridEnergyKwh, pricePerKwh, totalCost: gridEnergyKwh * pricePerKwh, + ...(isDemo === true ? { isDemo: true } : {}), ...(startSocPercent === undefined ? {} : { startSocPercent: bounded(startSocPercent, 0, 100, "startSocPercent") }), ...(endSocPercent === undefined ? {} : { endSocPercent: bounded(endSocPercent, 0, 100, "endSocPercent") }), curve, diff --git a/web/test/validate.test.ts b/web/test/validate.test.ts index ab1144c..eeef907 100644 --- a/web/test/validate.test.ts +++ b/web/test/validate.test.ts @@ -56,6 +56,7 @@ test("a charging session must match the id in its path", () => { gridEnergyKwh: 34.54, pricePerKwh: 7.5, totalCost: 235.5, + isDemo: true, startSocPercent: 18, endSocPercent: 72, curve: [{ timestampMs: 1_760_000_060_000, powerKw: 84.2, socPercent: 20 }], @@ -66,6 +67,7 @@ test("a charging session must match the id in its path", () => { assert.equal(record.chargingLossPercent, 10); assert.equal(record.gridEnergyKwh, 34.54); assert.equal(record.totalCost, 259.05); + assert.equal(record.isDemo, true); assert.throws(() => validateChargingSession(body, "11111111-2222-4333-8444-555555555556"), ValidationError); });