Skip to content

Commit a760119

Browse files
committed
Separate test/function per dataset so the rest report is a bit more verbose
1 parent 5f9309f commit a760119

File tree

2 files changed

+97
-41
lines changed

2 files changed

+97
-41
lines changed

.github/workflows/divert_sim.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ jobs:
9494
with:
9595
name: test_results
9696
path: |
97-
${{ github.ref_name }}_test_results.pdf
98-
${{ github.ref_name }}_test_results.png
9997
OpenEVSE_WiFi/divert_sim/output
10098
OpenEVSE_WiFi/divert_sim/view.html
99+
100+
- name: Publish Unit Test Results
101+
uses: EnricoMi/publish-unit-test-result-action/composite@v2
102+
if: always()
103+
with:
104+
junit_files: output/*.xml
105+
check_name: Test Results

divert_sim/test_divert.py

Lines changed: 90 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# PYTHON_ARGCOMPLETE_OK
33

44
from os import path
5+
import os
56
from subprocess import PIPE, Popen
67
from datetime import datetime
78

@@ -22,7 +23,15 @@
2223

2324
KWH_ROUNDING = 2
2425

25-
def run_test_with_dataset(summary_file, dataset: str,
26+
def setup():
27+
"""Create the output directory"""
28+
print("Setting up test environment")
29+
if not path.exists('output'):
30+
os.mkdir('output')
31+
with open(path.join('output', 'summary.csv'), 'w', encoding="utf-8") as summary_file:
32+
summary_file.write('"Dataset","Total Solar (kWh)","Total EV Charge (kWh)","Charge from solar (kWh)","Charge from grid (kWh)","Number of charges","Min time charging","Max time charging","Total time charging"\n')
33+
34+
def run_test_with_dataset(dataset: str,
2635
expected_solar_kwh: float,
2736
expected_ev_kwh : float,
2837
expected_kwh_from_solar : float,
@@ -129,7 +138,8 @@ def run_test_with_dataset(summary_file, dataset: str,
129138
kwh_from_solar=wh_from_solar / 1000
130139
kwh_from_grid=wh_from_grid / 1000
131140

132-
summary_file.write(f'"{dataset}",{solar_kwh},{ev_kwh},{kwh_from_solar},{kwh_from_grid},{number_of_charges},{min_time_charging},{max_time_charging},{total_time_charging}\n')
141+
with open(path.join('output', 'summary.csv'), 'a', encoding="utf-8") as summary_file:
142+
summary_file.write(f'"{dataset}",{solar_kwh},{ev_kwh},{kwh_from_solar},{kwh_from_grid},{number_of_charges},{min_time_charging},{max_time_charging},{total_time_charging}\n')
133143

134144
assert round(solar_kwh, KWH_ROUNDING) == expected_solar_kwh
135145
assert round(ev_kwh, KWH_ROUNDING) == expected_ev_kwh
@@ -140,43 +150,84 @@ def run_test_with_dataset(summary_file, dataset: str,
140150
assert max_time_charging == expected_max_time_charging
141151
assert total_time_charging == expected_total_time_charging
142152

143-
144-
def test_divert() -> None:
145-
"""Run the divert_sim process on all the datasets in the data directory"""
146-
with open(path.join('output', 'summary.csv'), 'w', encoding="utf-8") as summary_file:
147-
summary_file.write('"Dataset","Total Solar (kWh)","Total EV Charge (kWh)","Charge from solar (kWh)","Charge from grid (kWh)","Number of charges","Min time charging","Max time charging","Total time charging"\n')
148-
run_test_with_dataset(summary_file, 'almostperfect',
149-
21.08, 17.24, 17.05, 0.19, 1, 30060, 30060, 30060)
150-
run_test_with_dataset(summary_file, 'CloudyMorning',
151-
16.64, 13.03, 12.67, 0.36, 1, 22200, 22200, 22200)
152-
run_test_with_dataset(summary_file, 'day1',
153-
10.12, 7.48, 6.71, 0.77, 5, 660, 10080, 13740)
154-
run_test_with_dataset(summary_file, 'day2',
155-
12.35, 9.88, 9.86, 0.02, 1, 19920, 19920, 19920)
156-
run_test_with_dataset(summary_file, 'day3',
157-
5.09, 2.22, 1.60, 0.62, 5, 660, 2400, 5340)
158-
run_test_with_dataset(summary_file, 'day1_grid_ie',
159-
15.13, 8.83, 8.47, 0.36, 5, 660, 7800, 19860,
160-
grid_ie_col=2)
161-
run_test_with_dataset(summary_file, 'day2_grid_ie',
162-
10.85, 7.66, 6.16, 1.50, 10, 420, 7980, 16260,
163-
grid_ie_col=2)
164-
run_test_with_dataset(summary_file, 'day3_grid_ie',
165-
12.13, 6.32, 6.27, 0.05, 2, 3660, 9840, 13500,
166-
grid_ie_col=2)
167-
run_test_with_dataset(summary_file, 'solar-vrms',
168-
13.85, 12.26, 12.10, 0.17, 1, 22080, 22080, 22080,
169-
voltage_col=2)
170-
run_test_with_dataset(summary_file, 'Energy_and_Power_Day_2020-03-22',
171-
41.87, 38.52, 38.41, 0.11, 1, 28800, 28800, 28800,
172-
separator=';', is_kw=True, config='{"divert_decay_smoothing_factor":0.4}')
173-
run_test_with_dataset(summary_file, 'Energy_and_Power_Day_2020-03-31',
174-
23.91, 18.78, 18.66, 0.12, 1, 22500, 22500, 22500,
175-
separator=';', is_kw=True, config='{"divert_decay_smoothing_factor":0.4}')
176-
run_test_with_dataset(summary_file, 'Energy_and_Power_Day_2020-04-01',
177-
38.89, 36.72, 36.41, 0.32, 1, 27000, 27000, 27000,
178-
separator=';', is_kw=True, config='{"divert_decay_smoothing_factor":0.4}')
153+
def test_divert_almostperfect() -> None:
154+
"""Run the divert test with the almostperfect dataset"""
155+
run_test_with_dataset('almostperfect',
156+
21.08, 17.24, 17.05, 0.19, 1, 30060, 30060, 30060)
157+
158+
def test_divert_CloudyMorning() -> None:
159+
"""Run the divert test with the CloudyMorning dataset"""
160+
run_test_with_dataset('CloudyMorning',
161+
16.64, 13.03, 12.67, 0.36, 1, 22200, 22200, 22200)
162+
163+
def test_divert_day1() -> None:
164+
"""Run the divert test with the day1 dataset"""
165+
run_test_with_dataset('day1',
166+
10.12, 7.48, 6.71, 0.77, 5, 660, 10080, 13740)
167+
168+
def test_divert_day2() -> None:
169+
"""Run the divert test with the day2 dataset"""
170+
run_test_with_dataset('day2',
171+
12.35, 9.88, 9.86, 0.02, 1, 19920, 19920, 19920)
172+
173+
def test_divert_day3() -> None:
174+
"""Run the divert test with the day3 dataset"""
175+
run_test_with_dataset('day3',
176+
5.09, 2.22, 1.60, 0.62, 5, 660, 2400, 5340)
177+
178+
def test_divert_day1_grid_ie() -> None:
179+
"""Run the divert test with the day1_grid_ie dataset"""
180+
run_test_with_dataset('day1_grid_ie',
181+
15.13, 8.83, 8.47, 0.36, 5, 660, 7800, 19860,
182+
grid_ie_col=2)
183+
184+
def test_divert_day2_grid_ie() -> None:
185+
"""Run the divert test with the day2_grid_ie dataset"""
186+
run_test_with_dataset('day2_grid_ie',
187+
10.85, 7.66, 6.16, 1.50, 10, 420, 7980, 16260,
188+
grid_ie_col=2)
189+
190+
def test_divert_day3_grid_ie() -> None:
191+
"""Run the divert test with the day3_grid_ie dataset"""
192+
run_test_with_dataset('day3_grid_ie',
193+
12.13, 6.32, 6.27, 0.05, 2, 3660, 9840, 13500,
194+
grid_ie_col=2)
195+
196+
def test_divert_solar_vrms() -> None:
197+
"""Run the divert test with the solar-vrms dataset"""
198+
run_test_with_dataset('solar-vrms',
199+
13.85, 12.26, 12.10, 0.17, 1, 22080, 22080, 22080,
200+
voltage_col=2)
201+
202+
def test_divert_Energy_and_Power_Day_2020_03_22() -> None:
203+
"""Run the divert test with the Energy_and_Power_Day_2020-03-22 dataset"""
204+
run_test_with_dataset('Energy_and_Power_Day_2020-03-22',
205+
41.87, 38.52, 38.41, 0.11, 1, 28800, 28800, 28800,
206+
separator=';', is_kw=True, config='{"divert_decay_smoothing_factor":0.4}')
207+
208+
def test_divert_Energy_and_Power_Day_2020_03_31() -> None:
209+
"""Run the divert test with the Energy_and_Power_Day_2020-03-31 dataset"""
210+
run_test_with_dataset('Energy_and_Power_Day_2020-03-31',
211+
23.91, 18.78, 18.66, 0.12, 1, 22500, 22500, 22500,
212+
separator=';', is_kw=True, config='{"divert_decay_smoothing_factor":0.4}')
213+
214+
def test_divert_Energy_and_Power_Day_2020_04_01() -> None:
215+
"""Run the divert test with the Energy_and_Power_Day_2020-04-01 dataset"""
216+
run_test_with_dataset('Energy_and_Power_Day_2020-04-01',
217+
38.89, 36.72, 36.41, 0.32, 1, 27000, 27000, 27000,
218+
separator=';', is_kw=True, config='{"divert_decay_smoothing_factor":0.4}')
179219

180220
if __name__ == '__main__':
181221
# Run the script
182-
test_divert()
222+
test_divert_almostperfect()
223+
test_divert_CloudyMorning()
224+
test_divert_day1()
225+
test_divert_day2()
226+
test_divert_day3()
227+
test_divert_day1_grid_ie()
228+
test_divert_day2_grid_ie()
229+
test_divert_day3_grid_ie()
230+
test_divert_solar_vrms()
231+
test_divert_Energy_and_Power_Day_2020_03_22()
232+
test_divert_Energy_and_Power_Day_2020_03_31()
233+
test_divert_Energy_and_Power_Day_2020_04_01()

0 commit comments

Comments
 (0)