Skip to content

Commit 7ab937e

Browse files
committed
Changed SOC% into float, because newer Kona and ccNC cars can return half percentages
1 parent 56ee426 commit 7ab937e

File tree

4 files changed

+318
-295
lines changed

4 files changed

+318
-295
lines changed

summary.py

+39-16
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,20 @@ class Totals:
159159

160160
current_day: datetime
161161
odo: float
162-
charged_perc: int
163-
discharged_perc: int
162+
charged_perc: float
163+
discharged_perc: float
164164
charges: int
165165
trips: int
166166
elapsed_minutes: int
167-
soc_cur: int
167+
soc_cur: float
168168
soc_avg: float
169-
soc_min: int
170-
soc_max: int
169+
soc_min: float
170+
soc_max: float
171171
volt12_cur: int
172172
volt12_avg: float
173173
volt12_min: int
174174
volt12_max: int
175-
soc_charged: int
175+
soc_charged: float
176176

177177

178178
@dataclass
@@ -276,7 +276,30 @@ def init(current_day: datetime, odo: float, soc: int, volt12: int) -> Totals:
276276
return totals
277277

278278

279-
COLUMN_WIDTHS = [13, 10, 5, 7, 8, 8, 8, 5, 5, 8, 3, 3, 3, 3, 3, 3, 3, 3, 6, 6, 4, 99]
279+
COLUMN_WIDTHS = [
280+
13, # Period
281+
10, # Date
282+
5, # Info
283+
7, # Odometer
284+
8, # Delta km
285+
8, # +kWh
286+
8, # -kWh
287+
5, # km/kWh
288+
5, # kWh/100km
289+
8, # Cost
290+
4, # SOC%
291+
4, # SOC% Avg
292+
4, # Soc% Min
293+
4, # SOC% Max
294+
3, # 12V%
295+
3, # 12V% Avg
296+
3, # 12V% Min
297+
3, # 12V% Max
298+
6, # #Charging
299+
6, # #Trips
300+
4, # Range
301+
99, # Address
302+
]
280303

281304

282305
def print_output_and_update_queue(output: str) -> None:
@@ -634,7 +657,7 @@ def print_summary(
634657
)
635658
if charged_kwh > 3.0:
636659
write_charge_csv(
637-
f"{date}, {odo:.1f}, {float_to_string_no_trailing_zero(charged_kwh)}, {t_soc_charged}" # noqa
660+
f"{date}, {odo:.1f}, {float_to_string_no_trailing_zero(charged_kwh)}, {float_to_string_no_trailing_zero(t_soc_charged)}" # noqa
638661
)
639662

640663
if TRIP and prefix.startswith("TRIP "):
@@ -662,9 +685,9 @@ def print_summary(
662685
last_upd_dt = last_updated_at[1]
663686
location_last_upd_dt = location_last_updated_at[1]
664687
SHEET_ROW_A = f"{TR.last_run},{TR.vehicle_upd},{TR.gps_update},{TR.last_entry},{TR.last_address},{TR.odometer} {ODO_METRIC},{TR.driven} {ODO_METRIC},+kWh,-kWh,{ODO_METRIC}/kWh,kWh/100{ODO_METRIC},{TR.cost} {COST_CURRENCY},{TR.soc_perc},{TR.avg} {TR.soc_perc},{TR.min} {TR.soc_perc},{TR.max} {TR.soc_perc},{TR.volt12_perc},{TR.avg} {TR.volt12_perc},{TR.min} {TR.volt12_perc},{TR.max} {TR.volt12_perc},{TR.charges},{TR.trips},{TR.ev_range}" # noqa
665-
SHEET_ROW_B = f"{last_run_dt},{last_upd_dt},{location_last_upd_dt},{last_line},{location_str},{odo:.1f},{float_to_string_no_trailing_zero(delta_odo)},{float_to_string_no_trailing_zero(charged_kwh)},{float_to_string_no_trailing_zero(discharged_kwh)},{km_mi_per_kwh_str},{kwh_per_km_mi_str},{cost_str},{t_soc_cur},{t_soc_avg},{t_soc_min},{t_soc_max},{t_volt12_cur},{t_volt12_avg},{t_volt12_min},{t_volt12_max},{t_charges},{t_trips},{ev_range}" # noqa
688+
SHEET_ROW_B = f"{last_run_dt},{last_upd_dt},{location_last_upd_dt},{last_line},{location_str},{odo:.1f},{float_to_string_no_trailing_zero(delta_odo)},{float_to_string_no_trailing_zero(charged_kwh)},{float_to_string_no_trailing_zero(discharged_kwh)},{km_mi_per_kwh_str},{kwh_per_km_mi_str},{cost_str},{float_to_string_no_trailing_zero(t_soc_cur)},{float_to_string_no_trailing_zero(t_soc_avg)},{float_to_string_no_trailing_zero(t_soc_min)},{float_to_string_no_trailing_zero(t_soc_max)},{t_volt12_cur},{t_volt12_avg},{t_volt12_min},{t_volt12_max},{t_charges},{t_trips},{ev_range}" # noqa
666689
else:
667-
output = f"{prefix},{odo_str},{delta_odo_str},{charged_kwh_str},{discharged_kwh_str},{km_mi_per_kwh_str},{kwh_per_km_mi_str},{cost_str},{t_soc_cur},{t_soc_avg},{t_soc_min},{t_soc_max},{t_volt12_cur},{t_volt12_avg},{t_volt12_min},{t_volt12_max},{t_charges_str},{t_trips_str},{ev_range},{location_str}" # noqa
690+
output = f"{prefix},{odo_str},{delta_odo_str},{charged_kwh_str},{discharged_kwh_str},{km_mi_per_kwh_str},{kwh_per_km_mi_str},{cost_str},{float_to_string_no_trailing_zero(t_soc_cur)},{float_to_string_no_trailing_zero(t_soc_avg)},{float_to_string_no_trailing_zero(t_soc_min)},{float_to_string_no_trailing_zero(t_soc_max)},{t_volt12_cur},{t_volt12_avg},{t_volt12_min},{t_volt12_max},{t_charges_str},{t_trips_str},{ev_range},{location_str}" # noqa
668691
print_output_and_update_queue(output)
669692

670693

@@ -816,14 +839,14 @@ def keep_track_of_totals(
816839
) != to_float(prev_split[LON])
817840
moved = coord_changed or delta_odo != 0.0
818841

819-
soc = to_int(split[SOC])
820-
prev_soc = to_int(prev_split[SOC])
842+
soc = to_float(split[SOC])
843+
prev_soc = to_float(prev_split[SOC])
821844
delta_soc = soc - prev_soc
822-
if (soc == 0 or prev_soc == 0) and abs(delta_soc) > 5:
845+
if (soc == 0.0 or prev_soc == 0.0) and abs(delta_soc) > 5:
823846
# possibly wrong readout, take largest
824847
soc = max(soc, prev_soc)
825848
prev_soc = soc
826-
delta_soc = 0
849+
delta_soc = 0.0
827850

828851
if delta_odo > 0.0:
829852
t_trips += 1
@@ -855,7 +878,7 @@ def keep_track_of_totals(
855878
prev_charging = is_true(prev_split[CHARGING])
856879
no_charging = not charging and not prev_charging
857880

858-
if delta_soc != 0:
881+
if delta_soc != 0.0:
859882
if D:
860883
dbg(
861884
f"Delta SOC: {delta_soc}, no_charging: {no_charging}, moved: {moved}, elapsed_minutes: {elapsed_minutes}" # noqa
@@ -888,7 +911,7 @@ def keep_track_of_totals(
888911
if charging and not prev_charging:
889912
t_charges += 1
890913
_ = D and dbg("CHARGES: " + str(t_charges))
891-
elif delta_soc > 1 and no_charging:
914+
elif delta_soc > 1.0 and no_charging:
892915
t_charges += 1
893916
_ = D and dbg("charges: DELTA_SOC > 1: " + str(t_charges))
894917

0 commit comments

Comments
 (0)