-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtypes.ts
More file actions
280 lines (242 loc) · 8.46 KB
/
Copy pathtypes.ts
File metadata and controls
280 lines (242 loc) · 8.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/**
* Battery state naming convention:
* - SOE (State of Energy): Absolute energy in kWh (0-30 kWh typical)
* - SOC (State of Charge): Relative charge in % (0-100%)
* - USE batterySocEnd for battery level displays (clear and unambiguous)
*/
/**
* Unified formatting interface for all user-facing values
*/
export interface FormattedValue {
value: number; // Raw numeric value for calculations/sorting
display: string; // Formatted number without unit ("84.87", "700")
unit: string; // Unit label (currency code, "kWh", "Wh", "%")
text: string; // Complete formatted text ("84.87 EUR", "700 Wh")
}
export interface HourlyData {
// Core display fields (use these for UI)
period: number; // Period index (0-23 for hourly, 0-95 for quarterly)
// Economic fields (use these for cost calculations)
batteryCycleCost?: number; // battery wear cost
gridCost?: number; // net grid cost
hourlyCost?: number; // total cost
hourlySavings?: number; // savings
// Battery state (established in SOC/SOE naming fix)
batterySoeStart?: number; // kWh
batterySoeEnd?: number; // kWh
// Detailed energy flows (all FormattedValue — backend serializes via safe_format)
solarToHome?: FormattedValue;
solarToBattery?: FormattedValue;
solarToGrid?: FormattedValue;
gridToHome?: FormattedValue;
gridToBattery?: FormattedValue;
batteryToHome?: FormattedValue;
batteryToGrid?: FormattedValue;
// Control and decision fields
strategicIntent?: string; // strategy name
observedIntent?: string; // what actually happened (set for past periods only)
// All user-facing data via FormattedValue - canonical naming
buyPrice?: FormattedValue;
sellPrice?: FormattedValue;
solarProduction?: FormattedValue;
homeConsumption?: FormattedValue;
gridImported?: FormattedValue;
gridExported?: FormattedValue;
batteryCharged?: FormattedValue;
batteryDischarged?: FormattedValue;
batterySocStart?: FormattedValue;
batterySocEnd?: FormattedValue;
batteryAction?: FormattedValue;
// Additional economic fields
solarOnlyCost?: number;
gridOnlyCost?: number;
batterySavings?: number;
solarSavings?: number; // Solar-Only vs Grid-Only savings
// Metadata
dataSource?: string; // 'actual' | 'predicted' | others
timestamp?: string; // ISO format
}
export interface ScheduleSummary {
// Baseline costs (what scenarios would cost)
gridOnlyCost: number; // cost if only using grid
solarOnlyCost: number; // cost if solar + grid (no battery)
optimizedCost: number; // cost with battery optimization
// Component costs (breakdown of optimized scenario)
totalGridCost: number; // net grid costs
totalBatteryCycleCost: number; // battery wear costs
// Savings calculations (vs baselines)
totalSavings: number; // total savings vs grid-only
solarSavings: number; // savings from solar vs grid-only
batterySavings: number; // additional savings from battery
// Energy totals (for context)
totalSolarProduction: number; // kWh
totalHomeConsumption: number; // kWh
totalBatteryCharged: number; // kWh
totalBatteryDischarged: number; // kWh
totalGridImported: number; // kWh
totalGridExported: number; // kWh
// Efficiency metrics
cycleCount: number; // number of battery cycles
}
export interface BatterySettings {
// Capacity settings (kWh)
totalCapacity: number; // kWh total capacity
reservedCapacity: number; // kWh reserved (unusable)
// State of charge limits (%)
minSoc: number; // % minimum charge
maxSoc: number; // % maximum charge
// Power limits (kW)
maxChargePowerKw: number; // kW max charge power
maxDischargePowerKw: number; // kW max discharge power
// Economic settings
cycleCostPerKwh: number; // wear cost per kWh
chargingPowerRate: number; // % of max power to use
dischargingPowerRate: number; // % of max power to use for discharge
// Efficiency settings (%)
efficiencyCharge: number; // % charging efficiency
efficiencyDischarge: number; // % discharge efficiency
// AC-coupled PV: route SOLAR_STORAGE through grid charging
externalSolarMode?: boolean;
// Consumption estimate
estimatedConsumption: number; // kWh daily estimate
consumptionStrategy: string; // "sensor", "fixed", or "influxdb_7d_avg"
// Price settings
useActualPrice?: boolean; // use actual vs estimated prices
}
export interface ElectricitySettings {
markupRate: number;
vatMultiplier: number;
additionalCosts: number;
taxReduction: number;
area: string;
}
export interface ScheduleData {
hourlyData: HourlyData[];
summary: ScheduleSummary;
}
export type HealthStatus = "OK" | "WARNING" | "ERROR" | "UNKNOWN" | "NOT_CONFIGURED";
export interface HealthCheckResult {
name: string;
key: string | null;
entity_id?: string | null;
status: HealthStatus;
rawValue: any; // Original sensor value for logic/comparisons
displayValue: string; // Human-readable with units (required, no fallbacks)
error: string | null;
message?: string | null;
}
export interface ComponentHealthStatus {
name: string;
description: string;
required: boolean;
status: HealthStatus;
checks: HealthCheckResult[];
last_run: string;
}
export interface SystemHealthData {
timestamp: string;
system_mode: string;
checks: ComponentHealthStatus[];
}
export interface PredictionSnapshot {
snapshotTimestamp: string;
optimizationPeriod: number;
predictedDailySavings: FormattedValue;
totalExpectedSavings: FormattedValue;
periodCount: number;
actualCount: number;
growattScheduleCount: number;
}
export interface PeriodDeviation {
period: number;
predictedBatteryAction: FormattedValue;
actualBatteryAction: FormattedValue;
batteryActionDeviation: FormattedValue;
predictedConsumption: FormattedValue;
actualConsumption: FormattedValue;
consumptionDeviation: FormattedValue;
predictedSolar: FormattedValue;
actualSolar: FormattedValue;
solarDeviation: FormattedValue;
predictedGridImport: FormattedValue;
actualGridImport: FormattedValue;
gridImportDeviation: FormattedValue;
predictedGridExport: FormattedValue;
actualGridExport: FormattedValue;
gridExportDeviation: FormattedValue;
predictedSavings: FormattedValue;
actualSavings: FormattedValue;
savingsDeviation: FormattedValue;
deviationType: string;
}
export interface SnapshotComparison {
snapshotTimestamp: string;
snapshotPeriod: number;
comparisonTime: string;
periodDeviations: PeriodDeviation[];
totalPredictedSavings: FormattedValue;
totalActualSavings: FormattedValue;
savingsDeviation: FormattedValue;
primaryDeviationCause: string;
// Full-day savings breakdown at snapshot time (actuals + predicted = total)
snapshotTotalSavings: FormattedValue;
snapshotActualSavings: FormattedValue;
snapshotPredictedSavings: FormattedValue;
// Full-day savings breakdown now (actuals + predicted = total)
currentTotalSavings: FormattedValue;
currentActualSavings: FormattedValue;
currentPredictedSavings: FormattedValue;
predictedGrowattSchedule: any[];
currentGrowattSchedule: any[];
}
export interface SnapshotDataPoint {
solar: FormattedValue;
consumption: FormattedValue;
batteryAction: FormattedValue;
batterySoe: FormattedValue;
gridImport: FormattedValue;
gridExport: FormattedValue;
cost: FormattedValue;
gridOnlyCost: FormattedValue;
savings: FormattedValue;
dataSource: string;
}
export interface PeriodComparison {
period: number;
snapshotA: SnapshotDataPoint;
snapshotB: SnapshotDataPoint;
delta: Omit<SnapshotDataPoint, 'dataSource'>;
}
export interface SnapshotToSnapshotComparison {
snapshotAPeriod: number;
snapshotATimestamp: string;
snapshotBPeriod: number;
snapshotBTimestamp: string;
periodComparisons: PeriodComparison[];
growattScheduleA: any[];
growattScheduleB: any[];
}
export interface StrategyForecast {
name: string;
isActive: boolean;
available: boolean;
error: string | null;
totalKwh: FormattedValue | null;
hourlyProfile: FormattedValue[];
mae: FormattedValue | null;
}
export interface ConsumptionForecastComparison {
activeStrategy: string;
strategies: StrategyForecast[];
actualHourlyProfile: (FormattedValue | null)[];
actualHoursAvailable: number;
}
export interface RuntimeFailure {
id: string;
timestamp: string;
operation: string;
category: string;
error_message: string;
error_type: string;
retry_count: number;
}