Mark dashboard demo charging sessions

This commit is contained in:
TCFDONMEZ
2026-10-08 15:55:48 +03:00
parent ae036b9d65
commit c06c37761b
4 changed files with 6 additions and 0 deletions
+1
View File
@@ -57,6 +57,7 @@ export default async function ChargingPage() {
<div>
<div className="session-when">{dateTime(session.startedAt)}</div>
<div className="session-meta">
{session.isDemo && "Demo · "}
{duration(session.durationSeconds)}
{gained !== null && ` · %${num(session.startSocPercent as number)} → %${num(session.endSocPercent as number)}`}
</div>
+1
View File
@@ -45,6 +45,7 @@ export interface ChargingSession {
gridEnergyKwh: number;
pricePerKwh: number;
totalCost: number;
isDemo?: boolean;
startSocPercent?: number;
endSocPercent?: number;
curve: CurvePoint[];
+2
View File
@@ -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,
+2
View File
@@ -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);
});