diff --git a/assets/js/components/Optimize/ChargeChart.vue b/assets/js/components/Optimize/ChargeChart.vue index fe123f778..fa5caf7e9 100644 --- a/assets/js/components/Optimize/ChargeChart.vue +++ b/assets/js/components/Optimize/ChargeChart.vue @@ -89,15 +89,18 @@ export default defineComponent({ chartData(): ChartData { const datasets: any[] = []; - // 1. Solar Forecast (first, with increased tension) - datasets.push(...this.getSolarDatasets()); + // 1. Grid power data (import/export) + datasets.push(...this.getGridPowerDatasets()); - // 2. Battery power data - datasets.push(...this.getBatteryPowerDatasets()); + // 2. Solar Forecast + datasets.push(...this.getSolarDatasets()); // 3. Household Demand (power) datasets.push(...this.getHouseholdDatasets()); + // 4. Battery power data + datasets.push(...this.getBatteryPowerDatasets()); + return { labels: this.timeLabels, datasets: datasets, @@ -133,6 +136,16 @@ export default defineComponent({ label: (context) => { const label = context.dataset.label || ""; const value = context.parsed.y; + // Special handling for Grid Power + if (label === "Grid Power") { + if (value > 0) { + return `Grid Import: ${this.formatValue(Math.abs(value))} kW`; + } else if (value < 0) { + return `Grid Export: ${this.formatValue(Math.abs(value))} kW`; + } else { + return `Grid: 0 kW`; + } + } // Power axis (kW) return `${label}: ${this.formatValue(value)} kW`; }, @@ -159,23 +172,11 @@ export default defineComponent({ display: true, text: "Power (kW)", }, - stacked: true, + stacked: false, grid: { drawOnChartArea: true, - color: (context: any) => { - // Make zero axis black to highlight - if (context.tick?.value === 0) { - return "#000000"; - } - return colors.border || "#e0e0e0"; - }, - lineWidth: (context: any) => { - // Make zero axis slightly thicker - if (context.tick?.value === 0) { - return 2; - } - return 1; - }, + color: colors.border || "", + lineWidth: 1, }, // Keep scales purely based on values, no fixed boundaries }, @@ -207,7 +208,7 @@ export default defineComponent({ borderColor: colors.self, backgroundColor: colors.self, fill: false, - tension: 0.25, + tension: 0.2, borderJoinStyle: "round", borderCapStyle: "round", pointRadius: 0, @@ -215,6 +216,7 @@ export default defineComponent({ borderWidth: 3, yAxisID: "y", type: "line" as const, + stack: false, }, ]; }, @@ -253,7 +255,6 @@ export default defineComponent({ return datasets; }, getHouseholdDatasets() { - // Household Demand (as power, not energy like in SocChart) const householdPower = this.evopt.req.time_series.gt.map(this.convertWToKW); // Use the next color in the palette after all battery colors @@ -262,7 +263,7 @@ export default defineComponent({ return [ { - label: "Household Demand", + label: "Household", data: householdPower, backgroundColor: householdColor, borderWidth: 0, @@ -273,6 +274,41 @@ export default defineComponent({ ]; }, + getGridPowerDatasets() { + const datasets: any[] = []; + + // Get grid import and export data + const gridImport = this.evopt.res.grid_import || []; + const gridExport = this.evopt.res.grid_export || []; + + // Combine grid import and export into a single line + // Grid import is positive, grid export is negative (one is always zero) + const gridPower = gridImport.map((importValue, index) => { + const exportValue = gridExport[index] || 0; + const importKW = this.convertWToKW(importValue); + const exportKW = this.convertWToKW(exportValue); + // Return import as positive, export as negative + return importKW > 0 ? importKW : -exportKW; + }); + + datasets.push({ + label: "Grid Power", + data: gridPower, + borderColor: "#666666", // Dark gray + backgroundColor: "#666666", // Dark gray + fill: false, + tension: 0.2, + borderWidth: 2, // Same thickness as price chart lines + pointRadius: 0, + pointHoverRadius: 6, + yAxisID: "y", + type: "line" as const, + stack: false, + }); + + return datasets; + }, + convertWToKW: (watts: number): number => { return watts / 1000; }, diff --git a/assets/js/components/Optimize/CopyButton.vue b/assets/js/components/Optimize/CopyButton.vue new file mode 100644 index 000000000..50b56bfac --- /dev/null +++ b/assets/js/components/Optimize/CopyButton.vue @@ -0,0 +1,69 @@ + + + diff --git a/assets/js/components/Optimize/SocChart.vue b/assets/js/components/Optimize/SocChart.vue index bcd10747a..782572808 100644 --- a/assets/js/components/Optimize/SocChart.vue +++ b/assets/js/components/Optimize/SocChart.vue @@ -135,22 +135,9 @@ export default defineComponent({ }, grid: { drawOnChartArea: true, - color: (context: any) => { - // Make zero axis black to highlight - if (context.tick?.value === 0) { - return "#000000"; - } - return colors.border || "#e0e0e0"; - }, - lineWidth: (context: any) => { - // Make zero axis slightly thicker - if (context.tick?.value === 0) { - return 2; - } - return 1; - }, + color: colors.border || "", + lineWidth: 1, }, - // Remove fixed minimum to allow negative values }, }, }; diff --git a/assets/js/components/Optimize/TimeSeriesDataTable.vue b/assets/js/components/Optimize/TimeSeriesDataTable.vue index a69007428..082dcbc8e 100644 --- a/assets/js/components/Optimize/TimeSeriesDataTable.vue +++ b/assets/js/components/Optimize/TimeSeriesDataTable.vue @@ -30,31 +30,6 @@ {{ formatPower(value) }} - - - - {{ gridFeedinPriceLabel }} - - - {{ fmtPricePerKWh(value * 1000, currency, false, false) }} - - - - - {{ gridImportPriceLabel }} - - - {{ fmtPricePerKWh(value * 1000, currency, false, false) }} - - Household Demand (kW) + + + {{ gridImportPriceLabel }} + + + {{ fmtPricePerKWh(value * 1000, currency, false, false) }} + + + + + {{ gridFeedinPriceLabel }} + + + {{ fmtPricePerKWh(value * 1000, currency, false, false) }} + + @@ -125,7 +124,7 @@ class="battery-indicator me-2" :style="{ backgroundColor: batteryColors[batteryIndex] }" > - {{ getBatteryTitle(batteryIndex) }} Response + {{ getBatteryTitle(batteryIndex) }} diff --git a/assets/js/components/Optimize/compactJson.ts b/assets/js/components/Optimize/compactJson.ts new file mode 100644 index 000000000..6dc3965f5 --- /dev/null +++ b/assets/js/components/Optimize/compactJson.ts @@ -0,0 +1,56 @@ +/** + * Custom JSON formatter that keeps arrays of primitive values on a single line + */ +export function formatCompactJson(obj: any, indent: number = 2): string { + const spaces = " ".repeat(indent); + + function stringify(value: any, depth: number): string { + const currentIndent = spaces.repeat(depth); + const nextIndent = spaces.repeat(depth + 1); + + if (value === null) return "null"; + if (value === undefined) return "undefined"; + + // Handle primitive types + if (typeof value !== "object") { + return JSON.stringify(value); + } + + // Handle arrays + if (Array.isArray(value)) { + // Check if all elements are primitives (numbers, strings, booleans, null) + const allPrimitive = value.every( + (item) => item === null || item === undefined || typeof item !== "object" + ); + + if (allPrimitive && value.length > 0) { + // Format primitive array on single line + const items = value.map((item) => JSON.stringify(item)).join(", "); + return `[${items}]`; + } else if (value.length === 0) { + return "[]"; + } else { + // Format complex array with indentation + const items = value.map((item) => `${nextIndent}${stringify(item, depth + 1)}`).join(",\n"); + return `[\n${items}\n${currentIndent}]`; + } + } + + // Handle objects + const entries = Object.entries(value); + if (entries.length === 0) { + return "{}"; + } + + const items = entries + .map(([key, val]) => { + const formattedValue = stringify(val, depth + 1); + return `${nextIndent}${JSON.stringify(key)}: ${formattedValue}`; + }) + .join(",\n"); + + return `{\n${items}\n${currentIndent}}`; + } + + return stringify(obj, 0); +} diff --git a/assets/js/types/evcc.ts b/assets/js/types/evcc.ts index 8be868ed0..cfb963749 100644 --- a/assets/js/types/evcc.ts +++ b/assets/js/types/evcc.ts @@ -343,6 +343,7 @@ export type ValueOf = T[keyof T]; export interface EvOpt { req: OptimizationInput; res: OptimizationResult; + curl: string; details: OptimizationDetails; } diff --git a/assets/js/views/Optimize.vue b/assets/js/views/Optimize.vue index 995f81989..929726a6f 100644 --- a/assets/js/views/Optimize.vue +++ b/assets/js/views/Optimize.vue @@ -1,6 +1,6 @@