Skip to content

Commit 98e2273

Browse files
Merge pull request #636 from OpenEVSE/divert_sim_summary
Separate test/function per dataset so the rest report is a bit more verbose
2 parents 09b7100 + bd1cc31 commit 98e2273

File tree

3 files changed

+106
-42
lines changed

3 files changed

+106
-42
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
run: echo "github.ref_name = '${{ github.ref_name }}'"
3939

4040
build:
41+
name: Build ${{ matrix.env }} with ${{ matrix.gui.name }}
4142
runs-on: ubuntu-latest
4243

4344
strategy:
@@ -133,6 +134,7 @@ jobs:
133134
path: .pio/build/${{ matrix.env }}/firmware.bin
134135

135136
release:
137+
name: Upload release assets
136138
runs-on: ubuntu-latest
137139
needs: build
138140
if: github.ref_name == 'master' || startsWith(github.ref_name, 'v')

.github/workflows/divert_sim.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
name: Build OpenEVSE divert simulator
44

5+
# Allow dependabot to update checks
56
permissions:
7+
checks: write
8+
actions: write
69
contents: write
10+
issues: read
11+
pull-requests: write
712

813
on:
914
push:
@@ -13,6 +18,7 @@ on:
1318

1419
jobs:
1520
build:
21+
name: Build and test divert_sim
1622
runs-on: ubuntu-latest
1723

1824
steps:
@@ -87,14 +93,19 @@ jobs:
8793
run: |
8894
cd OpenEVSE_WiFi/divert_sim
8995
mkdir -p output
90-
pytest -v --color=yes --code-highlight yes --junitxml=output/test_results.xml
96+
pytest -v --color=yes --code-highlight yes --junit-xml=output/test_results.xml
9197
9298
- name : Upload test results
9399
uses: actions/upload-artifact@v3
94100
with:
95101
name: test_results
96102
path: |
97-
${{ github.ref_name }}_test_results.pdf
98-
${{ github.ref_name }}_test_results.png
99103
OpenEVSE_WiFi/divert_sim/output
100104
OpenEVSE_WiFi/divert_sim/view.html
105+
106+
- name: Publish Unit Test Results
107+
uses: EnricoMi/publish-unit-test-result-action/composite@v2
108+
if: always()
109+
with:
110+
junit_files: OpenEVSE_WiFi/divert_sim/output/*.xml
111+
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)