Skip to content

Commit

Permalink
summary.py: added charged/discharged kWh, using location to determine…
Browse files Browse the repository at this point in the history
… moved, small improvement in delta SOC
  • Loading branch information
ZuinigeRijder committed Sep 30, 2022
1 parent 22270f0 commit 0bf05a5
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 72 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,45 +188,45 @@ The summary.py standard output of the previous monitor.csv file: https://raw.git
output:
```
C:\Users\Rick\git\monitor>python summary.py
Label, date , driven km, charged%, discharged%, charges, drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 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, +6%, 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, +25%, 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, +28%, 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, +8%, 0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W38 , 470.7, +100%, -110, 6, 14, 6.1, 16.4, 18.94
MONTH, 2022-09 , 470.7, +106%, -110, 7, 14, 6.1, 16.4, 18.94
YEAR , 2022 , 470.7, +106%, -110, 7, 14, 6.1, 16.4, 18.94
Period, date , driven km, charged%, charged kWh, discharged%, discharged kWh, #charges, #drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 2.8, 0%, 0.0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-18, 0.0, +2%, 1.4, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W37 , 0.0, +6%, 4.2, 0%, 0.0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-19, 6.5, +0%, 0.0, -1%, -0.7, 0, 2, 0.0, 0.0, 0.00
DAY , 2022-09-20, 47.6, +0%, 0.0, -14%, -9.8, 0, 2, 4.9, 20.6, 2.41
DAY , 2022-09-21, 5.2, +26%, 18.2, -1%, -0.7, 2, 2, 0.0, 0.0, 0.00
DAY , 2022-09-22, 1.9, +2%, 1.4, -1%, -0.7, 1, 1, 0.0, 0.0, 0.00
DAY , 2022-09-23, 1.7, +29%, 20.3, 0%, 0.0, 2, 1, 0.0, 0.0, 0.00
DAY , 2022-09-24, 407.8, +37%, 25.9, -95%, -66.5, 1, 6, 6.1, 16.3, 16.36
DAY , 2022-09-25, 0.0, +8%, 5.6, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W38 , 470.7, +102%, 71.4, -112%, -78.4, 6, 14, 6.0, 16.7, 19.29
MONTH , 2022-09 , 470.7, +108%, 75.6, -112%, -78.4, 7, 14, 6.0, 16.7, 19.29
YEAR , 2022 , 470.7, +108%, 75.6, -112%, -78.4, 7, 14, 6.0, 16.7, 19.29
```

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.

Example output when filtering on DAY:
```
C:\Users\Rick\git\monitor>python summary.py day
Label, date , driven km, charged%, discharged%, charges, drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 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
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, +25%, 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, +28%, 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, +8%, 0, 0, 0, 0.0, 0.0, 0.00
Period, date , driven km, charged%, charged kWh, discharged%, discharged kWh, #charges, #drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 2.8, 0%, 0.0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-18, 0.0, +2%, 1.4, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
DAY , 2022-09-19, 6.5, +0%, 0.0, -1%, -0.7, 0, 2, 0.0, 0.0, 0.00
DAY , 2022-09-20, 47.6, +0%, 0.0, -14%, -9.8, 0, 2, 4.9, 20.6, 2.41
DAY , 2022-09-21, 5.2, +26%, 18.2, -1%, -0.7, 2, 2, 0.0, 0.0, 0.00
DAY , 2022-09-22, 1.9, +2%, 1.4, -1%, -0.7, 1, 1, 0.0, 0.0, 0.00
DAY , 2022-09-23, 1.7, +29%, 20.3, 0%, 0.0, 2, 1, 0.0, 0.0, 0.00
DAY , 2022-09-24, 407.8, +37%, 25.9, -95%, -66.5, 1, 6, 6.1, 16.3, 16.36
DAY , 2022-09-25, 0.0, +8%, 5.6, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
```

You can redirect this standard output to a file, e.g. summary.day.csv: https://raw.githubusercontent.com/ZuinigeRijder/hyundai_kia_connect_monitor/main/examples/summary.day.csv

Excel example using summary.day.csv: https://github.com/ZuinigeRijder/hyundai_kia_connect_monitor/blob/main/examples/summary.day.xlsx

Screenshot of excel example with some graphs:
![alt text](https://raw.githubusercontent.com/ZuinigeRijder/hyundai_kia_connect_monitor/main/examples/summary.day.jpg)
![alt text](https://raw.githubusercontent.com/ZuinigeRijder/hyundai_kia_connect_monitor/main/examples/summary.day.png)

## python kml.py

Expand Down
20 changes: 10 additions & 10 deletions examples/summary.day.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Label, date , driven km, charged%, discharged%, charges, drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 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
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, +25%, 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, +28%, 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, +8%, 0, 0, 0, 0.0, 0.0, 0.00
Period, date , driven km, charged%, charged kWh, discharged%, discharged kWh, #charges, #drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 2.8, 0%, 0.0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-18, 0.0, +2%, 1.4, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
DAY , 2022-09-19, 6.5, +0%, 0.0, -1%, -0.7, 0, 2, 0.0, 0.0, 0.00
DAY , 2022-09-20, 47.6, +0%, 0.0, -14%, -9.8, 0, 2, 4.9, 20.6, 2.41
DAY , 2022-09-21, 5.2, +26%, 18.2, -1%, -0.7, 2, 2, 0.0, 0.0, 0.00
DAY , 2022-09-22, 1.9, +2%, 1.4, -1%, -0.7, 1, 1, 0.0, 0.0, 0.00
DAY , 2022-09-23, 1.7, +29%, 20.3, 0%, 0.0, 2, 1, 0.0, 0.0, 0.00
DAY , 2022-09-24, 407.8, +37%, 25.9, -95%, -66.5, 1, 6, 6.1, 16.3, 16.36
DAY , 2022-09-25, 0.0, +8%, 5.6, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
Binary file removed examples/summary.day.jpg
Binary file not shown.
Binary file added examples/summary.day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/summary.day.xlsx
Binary file not shown.
28 changes: 14 additions & 14 deletions examples/summary.py_output.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Label, date , driven km, charged%, discharged%, charges, drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 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, +6%, 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, +25%, 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, +28%, 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, +8%, 0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W38 , 470.7, +100%, -110, 6, 14, 6.1, 16.4, 18.94
MONTH, 2022-09 , 470.7, +106%, -110, 7, 14, 6.1, 16.4, 18.94
YEAR , 2022 , 470.7, +106%, -110, 7, 14, 6.1, 16.4, 18.94
Period, date , driven km, charged%, charged kWh, discharged%, discharged kWh, #charges, #drives, km/kWh, kWh/100km, cost Euro
DAY , 2022-09-17, 0.0, +4%, 2.8, 0%, 0.0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-18, 0.0, +2%, 1.4, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W37 , 0.0, +6%, 4.2, 0%, 0.0, 1, 0, 0.0, 0.0, 0.00
DAY , 2022-09-19, 6.5, +0%, 0.0, -1%, -0.7, 0, 2, 0.0, 0.0, 0.00
DAY , 2022-09-20, 47.6, +0%, 0.0, -14%, -9.8, 0, 2, 4.9, 20.6, 2.41
DAY , 2022-09-21, 5.2, +26%, 18.2, -1%, -0.7, 2, 2, 0.0, 0.0, 0.00
DAY , 2022-09-22, 1.9, +2%, 1.4, -1%, -0.7, 1, 1, 0.0, 0.0, 0.00
DAY , 2022-09-23, 1.7, +29%, 20.3, 0%, 0.0, 2, 1, 0.0, 0.0, 0.00
DAY , 2022-09-24, 407.8, +37%, 25.9, -95%, -66.5, 1, 6, 6.1, 16.3, 16.36
DAY , 2022-09-25, 0.0, +8%, 5.6, 0%, 0.0, 0, 0, 0.0, 0.0, 0.00
WEEK , 2022 W38 , 470.7, +102%, 71.4, -112%, -78.4, 6, 14, 6.0, 16.7, 19.29
MONTH , 2022-09 , 470.7, +108%, 75.6, -112%, -78.4, 7, 14, 6.0, 16.7, 19.29
YEAR , 2022 , 470.7, +108%, 75.6, -112%, -78.4, 7, 14, 6.0, 16.7, 19.29
55 changes: 32 additions & 23 deletions summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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}, cost {COST_CURRENCY}") # noqa pylint:disable=line-too-long
print(f"Period, date , driven {ODO_METRIC}, charged%, charged kWh, discharged%, discharged kWh, #charges, #drives, {ODO_METRIC}/kWh, kWh/100{ODO_METRIC}, cost {COST_CURRENCY}") # noqa pylint:disable=line-too-long


def print_summary(prefix, current, values):
Expand All @@ -85,19 +85,23 @@ def print_summary(prefix, current, values):
discharged = values[3]
charges = values[4]
drives = values[5]

charged_kwh = NET_BATTERY_SIZE_KWH / 100 * charged
discharged_kwh = NET_BATTERY_SIZE_KWH / 100 * discharged
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
if discharged < 0:
if discharged != -1: # small discharge means inaccurate calculation
cost = discharged_kwh * -AVERAGE_COST_PER_KWH
km_mi_per_kwh = delta_odo / -discharged_kwh
if km_mi_per_kwh > 0.0:
kwh_per_km_mi = 100 / km_mi_per_kwh
else:
# do not show small discharges
# do not show positive discharges
discharged = 0
if charged > 2 or discharged < 2 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}, {cost:9.2f}") # noqa pylint:disable=line-too-long
if charged > 0 or discharged < 0 or delta_odo > 1.0 or drives > 0:
print(f"{prefix:18}, {delta_odo:9.1f}, {charged:+7}%, {charged_kwh:11.1f}, {discharged:10}%, {discharged_kwh:14.1f}, {charges:8}, {drives:7}, {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 All @@ -106,29 +110,35 @@ def init(current_day, odo):


def keep_track_of_totals(values, split, prev_split):
""" add """
""" keep_track_of_totals """

debug("prev_split: " + str(prev_split))
debug(" split: " + str(split))

charged = values[2]
discharged = values[3]
charges = values[4]
drives = values[5]

odo = float(split[ODO].strip())
prev_odo = float(prev_split[ODO].strip())
moved = (
float(split[ODO].strip()) != float(prev_split[ODO].strip()) or
float(split[LAT].strip()) != float(prev_split[LAT].strip()) or
float(split[LON].strip()) != float(prev_split[LON].strip())
)

soc = int(split[SOC].strip())
prev_soc = int(prev_split[SOC].strip())
delta_soc = soc - prev_soc
delta_soc = int(split[SOC].strip()) - int(prev_split[SOC].strip())

charging = split[CHARGING].strip() == "True"
prev_charging = prev_split[CHARGING].strip() == "True"
no_charging = not charging and not prev_charging

engine_on = split[ENGINEON].strip() == "True"
engine_on_2 = prev_split[ENGINEON].strip() == "True"

if delta_soc != 0:
debug("Delta SOC: " + str(delta_soc))
if delta_soc > 0:
if not charging and delta_soc == 1:
if delta_soc == 1 and no_charging and not moved:
# small SOC difference can occur due to
# temperature difference (morning/evening),
# so correct discharged for delta_soc of 1
Expand All @@ -138,18 +148,17 @@ def keep_track_of_totals(values, split, prev_split):
else:
discharged += delta_soc

debug(f"CHARGES: {charging} {prev_charging}")
if charging and not prev_charging:
charges += 1
debug("CHARGES: " + str(charges))
if delta_soc > 1 and not charging and not prev_charging:
if delta_soc > 1 and no_charging:
charges += 1
debug("charges: DELTA_SOC > 1: " + str(charges))

if engine_on and not engine_on_2:
drives += 1
debug("ENGINE_ON: " + str(drives))
if odo != prev_odo and not engine_on and not engine_on_2:
if moved and not engine_on and not engine_on_2:
drives += 1
debug("ODO: " + str(drives))

Expand Down Expand Up @@ -187,15 +196,15 @@ def handle_line( # pylint: disable=too-many-arguments
if not same_day(current_day, first_d[0]):
if DAY:
print_summary(
"DAY , " + first_d[0].strftime("%Y-%m-%d"),
"DAY , " + first_d[0].strftime("%Y-%m-%d"),
current_day_values,
first_d
)
first_d = current_day_values
if not same_week(current_day, first_w[0]):
if WEEK:
print_summary(
"WEEK , " + str(first_y[0].year) + " W" +
"WEEK , " + str(first_y[0].year) + " W" +
str(first_w[0].isocalendar().week),
current_day_values,
first_w
Expand All @@ -204,15 +213,15 @@ def handle_line( # pylint: disable=too-many-arguments
if not same_month(current_day, first_m[0]):
if MONTH:
print_summary(
"MONTH, " + first_m[0].strftime("%Y-%m"),
"MONTH , " + first_m[0].strftime("%Y-%m"),
current_day_values,
first_m
)
first_m = current_day_values
if not same_year(current_day, first_y[0]):
if YEAR:
print_summary(
"YEAR , " + str(first_y[0].year),
"YEAR , " + str(first_y[0].year),
current_day_values,
first_y
)
Expand Down

0 comments on commit 0bf05a5

Please sign in to comment.