Browse Source

Correct display of grid recharge cycles in the battery level graph

master
Youen 6 days ago
parent
commit
6d9d3aa2da
  1. 2
      simulator/src/simulator-ui.ts
  2. 11
      simulator/src/simulator.ts

2
simulator/src/simulator-ui.ts

@ -117,7 +117,7 @@ function initializeSimulator(container: HTMLElement) {
batteryChargeGraph.viewport.setData({ x: 0, y: 0, width: 365*24, height: parameters.batteryCapacity });
batteryChargeGraph.viewport.setView({ x: marginLeft, y: batteryChargeGraph.height - marginBottom, width: batteryChargeGraph.width - (marginLeft+marginRight), height: -batteryChargeGraph.height+(marginTop+marginBottom) });
batteryChargeGraph.graph(simulationResult.batteryLevel, simulationResult.batteryLevel.map((x, idx) => x == 0 || idx == simulationResult.batteryLevel.length - 2 ? 1 : 0), [{className: ''}, {className: 'grid-recharge'}]);
batteryChargeGraph.graph(simulationResult.batteryLevel, simulationResult.gridCharge.map(x => x ? 1 : 0), [{className: ''}, {className: 'grid-recharge'}]);
let months = ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jui', 'Jui', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'];
let monthWidth = 365*24/12
for(let month = 0; month < 12; ++month) {

11
simulator/src/simulator.ts

@ -105,6 +105,7 @@ namespace Simulator {
vehicle: Vehicle;
batteryLevel: number[]; // Remaining energy in the battery over time (one entry per hour), in Wh
gridCharge: boolean[]; // Indicates when the battery has to be charged from grid power (one entry per hour)
gridChargeCount: number;
cumulatedGridRechargeEnergy: number; // Cumulated energy added to the battery from the power grid, in Wh of battery charge (actual power grid consumption will be slightly higer due to losses)
cumulatedSolarRechargeEnergy: number; // Cumulated energy added to the battery from the solar panel, in Wh of battery charge (actual generated power is slightly higher due to losses)
@ -127,6 +128,7 @@ namespace Simulator {
vehicle: vehicle,
batteryLevel: [],
gridCharge: [],
gridChargeCount: 0,
cumulatedGridRechargeEnergy: 0,
cumulatedSolarRechargeEnergy: 0,
@ -179,6 +181,7 @@ namespace Simulator {
for(let day = 0; day < 365; ++day) {
for(let hour = 0; hour < 24; ++hour) {
let hourIdx = day * 24 + hour;
result.gridCharge[hourIdx] = false;
planning.getOuting(day % 7, hour, outing);
@ -202,12 +205,13 @@ namespace Simulator {
solarCharge -= remainingBatteryCharge - vehicle.batteryCapacity;
remainingBatteryCharge = vehicle.batteryCapacity;
}
else if(remainingBatteryCharge <= lowBatteryThreshold || (day==364 && hour==23)) {
else if(remainingBatteryCharge <= lowBatteryThreshold) {
gridRechargeFrom = remainingBatteryChargeBeforeOuting;
let rechargeEnergy = vehicle.batteryCapacity - remainingBatteryChargeBeforeOuting;
remainingBatteryCharge += rechargeEnergy;
result.cumulatedGridRechargeEnergy += rechargeEnergy;
result.gridCharge[hourIdx] = true;
result.gridChargeCount += 1;
if(remainingBatteryCharge < 0)
@ -222,6 +226,7 @@ namespace Simulator {
let secondRechargeEnergy = vehicle.batteryCapacity;
remainingBatteryCharge = vehicle.batteryCapacity;
result.cumulatedGridRechargeEnergy += secondRechargeEnergy;
result.gridCharge[hourIdx] = true;
result.gridChargeCount += 1;
gridRechargeFrom = 0;
}
@ -231,6 +236,10 @@ namespace Simulator {
result.cumulatedSolarRechargeEnergy += solarCharge;
result.batteryLevel[hourIdx] = gridRechargeFrom >= 0 ? gridRechargeFrom : remainingBatteryCharge;
if(hourIdx > 0 && result.gridCharge[hourIdx - 1])
{
result.batteryLevel[hourIdx] = vehicle.batteryCapacity;
}
}
}

Loading…
Cancel
Save