Skip to content

Commit

Permalink
added cost to summary.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuinigeRijder committed Sep 27, 2022
1 parent f4af916 commit a9e87cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Usage:
```
python summary.py
```
- INPUTFILE: summary.cfg (configuration of kilometers or miles and net battery size in kWh)
- INPUTFILE: summary.cfg (configuration of kilometers or miles, net battery size in kWh, average cost per kWh and cost currency)
- INPUTFILE: monitor.csv
- standard output: summary per DAY, WEEK, MONTH, YEAR in csv format

Expand Down Expand Up @@ -177,20 +177,20 @@ The summary of the previous monitor.csv file.
output:
```
C:\Users\Rick\git\monitor>python summary.py
Label, date , driven km, charged%, discharged%, charges, drives, km/kWh, kWh/100km
DAY , 2022-09-17, 0.0, +3%, 0, 1, 0, 0.0, 0.0
DAY , 2022-09-18, 0.0, +2%, 0, 0, 0, 0.0, 0.0
WEEK , 2022 W37 , 0.0, +5%, 0, 1, 0, 0.0, 0.0
DAY , 2022-09-19, 6.5, +0%, 0, 0, 2, 0.0, 0.0
DAY , 2022-09-20, 47.6, +0%, -14, 0, 2, 4.9, 20.6
DAY , 2022-09-21, 5.2, +19%, 0, 2, 2, 0.0, 0.0
DAY , 2022-09-22, 1.9, +2%, 0, 1, 1, 0.0, 0.0
DAY , 2022-09-23, 1.7, +24%, 0, 2, 1, 0.0, 0.0
DAY , 2022-09-24, 407.8, +37%, -95, 1, 6, 6.1, 16.3
DAY , 2022-09-25, 0.0, +6%, 0, 0, 0, 0.0, 0.0
WEEK , 2022 W38 , 470.7, +88%, -98, 6, 14, 6.9, 14.6
MONTH, 2022-09 , 470.7, +93%, -97, 7, 14, 6.9, 14.4
YEAR , 2022 , 470.7, +93%, -97, 7, 14, 6.9, 14.4
Label, date , driven km, charged%, discharged%, charges, drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +3%, 0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-18, 0.0, +2%, 0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W37 , 0.0, +5%, 0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-19, 6.5, +0%, 0, 0, 2, 0.0, 0.0, 0.00
DAY , 2022-09-20, 47.6, +0%, -14, 0, 2, 4.9, 20.6, 2.41
DAY , 2022-09-21, 5.2, +19%, 0, 2, 2, 0.0, 0.0, 0.00
DAY , 2022-09-22, 1.9, +2%, 0, 1, 1, 0.0, 0.0, 0.00
DAY , 2022-09-23, 1.7, +24%, 0, 2, 1, 0.0, 0.0, 0.00
DAY , 2022-09-24, 407.8, +37%, -95, 1, 6, 6.1, 16.3, 16.36
DAY , 2022-09-25, 0.0, +6%, 0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W38 , 470.7, +88%, -98, 6, 14, 6.9, 14.6, 16.88
MONTH, 2022-09 , 470.7, +93%, -97, 7, 14, 6.9, 14.4, 16.70
YEAR , 2022 , 470.7, +93%, -97, 7, 14, 6.9, 14.4, 16.70
```

2022-09-24 I did a trip from 100% SOC to 5% SOC, have driven 407.8 km and started charging when back at home.
Expand Down
8 changes: 6 additions & 2 deletions summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

ODO_METRIC = monitor_settings['odometer_metric']
NET_BATTERY_SIZE_KWH = float(monitor_settings['net_battery_size_kwh'])
AVERAGE_COST_PER_KWH = float(monitor_settings['average_cost_per_kwh'])
COST_CURRENCY = monitor_settings['cost_currency']

# indexes to splitted monitor.csv items
DT = 0 # datetime
Expand Down Expand Up @@ -66,7 +68,7 @@ def same_day(d_1: datetime, d_2: datetime):
return d_1.year == d_2.year


print(f"Label, date , driven {ODO_METRIC}, charged%, discharged%, charges, drives, {ODO_METRIC}/kWh, kWh/100{ODO_METRIC}") # noqa pylint:disable=line-too-long
print(f"Label, date , driven {ODO_METRIC}, charged%, discharged%, charges, drives, {ODO_METRIC}/kWh, kWh/100{ODO_METRIC}, cost {COST_CURRENCY}") # noqa pylint:disable=line-too-long


def compute_deltas(prefix, current, values):
Expand All @@ -81,15 +83,17 @@ def compute_deltas(prefix, current, values):
drives = values[5]
km_mi_per_kwh = 0.0
kwh_per_km_mi = 0.0
cost = 0.00
if discharged < -2:
cost = NET_BATTERY_SIZE_KWH / 100 * -discharged * AVERAGE_COST_PER_KWH
km_mi_per_kwh = delta_odo / (NET_BATTERY_SIZE_KWH / 100 * -discharged)
if km_mi_per_kwh > 0.0:
kwh_per_km_mi = 100 / km_mi_per_kwh
else:
# do not show small discharges
discharged = 0
if charged > 0 or discharged < 0 or delta_odo > 1.0 or drives > 0:
print(f"{prefix:17}, {delta_odo:9.1f}, {charged:+7}%, {discharged:11}, {charges:7}, {drives:6}, {km_mi_per_kwh:6.1f}, {kwh_per_km_mi:9.1f}") # noqa pylint:disable=line-too-long
print(f"{prefix:17}, {delta_odo:9.1f}, {charged:+7}%, {discharged:11}, {charges:7}, {drives:6}, {km_mi_per_kwh:6.1f}, {kwh_per_km_mi:9.1f}, {cost:9.2f}") # noqa pylint:disable=line-too-long


def init(current_day, odo):
Expand Down

0 comments on commit a9e87cf

Please sign in to comment.