diff --git a/eval_records.py b/eval_records.py index eba0251..777cb75 100644 --- a/eval_records.py +++ b/eval_records.py @@ -7,7 +7,7 @@ import dateutil.parser as dup from jay_diff import jay_merge_full from matplotlib import pyplot as plot import eval_records_settings as settings - +from record.types.charging import ChargingState def has_diff_entries(diff): handled = False @@ -267,35 +267,62 @@ if __name__ == '__main__': # calc speed speed = [0] + dt = settings.t_interval_s for i in range(1, len(time_h)): - dt = float(time_h[i] - time_h[i - 1]) dv = v_odo[i] - v_odo[i-1] speed.append(dv/dt*60*60) # Convert x-axis dt_h = (np.array(time_h) - time_h[0]) / 3600 / 24 + settings.sel_days[0] + v_energy = [] + v_consumption = [] + energy = 0 + consumption = 0 + chg_state_last = 0 + odo_last = v_odo[0] + odo_diff_last = 0 + # Calc charging energy + for chgpwr, chgstate, odo in zip(v_chgpwr, v_chg_state, v_odo): + energy += chgpwr/3600*dt + if chg_state_last != chgstate: + chg_state_last = chgstate + if ChargingState[chgstate] == ChargingState.charging: + odo_diff = odo - odo_last + odo_last = odo + if odo_diff_last > 0: + consumption = 100 * energy / odo_diff_last + odo_diff_last = odo_diff + energy = 0 + + v_consumption.append(consumption) + v_energy.append(energy) # plot data - plot.subplot(5, 1, 1) + NUM_PLOTS = 6 + plot.subplot(NUM_PLOTS, 1, 1) plot.plot(dt_h, np.array(v_odo) - v_odo[0]) - plot.title("Kilometerstand") + plot.ylabel("Kilometerstand") plot.grid() - plot.subplot(5, 1, 2) + plot.subplot(NUM_PLOTS, 1, 2) plot.plot(dt_h, speed) - plot.title("Speed") + plot.ylabel("Speed") plot.grid() - plot.subplot(5, 1, 3) + plot.subplot(NUM_PLOTS, 1, 3) plot.plot(dt_h, v_soc, dt_h, v_chgpwr) - plot.title("Akkustand") + plot.ylabel("Akkustand") plot.grid() - plot.subplot(5, 1, 4) + plot.subplot(NUM_PLOTS, 1, 4) plot.plot(dt_h, v_range) - plot.title("Range") + plot.ylabel("Range") plot.grid() - plot.subplot(5, 1, 5) + plot.subplot(NUM_PLOTS, 1, 5) plot.plot(dt_h, v_chg_state) - plot.title("Charge state") + plot.ylabel("Charge state") + plot.grid() + plot.subplot(NUM_PLOTS, 1, 6) + plot.plot(dt_h, v_energy, dt_h, v_consumption) + plot.ylabel("Charge energy") plot.grid() plot.show() diff --git a/record/types/charging.py b/record/types/charging.py index bbe4d63..2d13609 100644 --- a/record/types/charging.py +++ b/record/types/charging.py @@ -7,6 +7,8 @@ class ChargingState(enum.Enum): chargePurposeReachedAndNotConservationCharging = 2 chargePurposeReachedAndConservation = 3 error = 4 + conservation = 5 + readyForCharging = 6 print(ChargingState["charging"].value)