refactored

This commit is contained in:
2025-03-30 13:10:48 +02:00
parent 7eb0ab96ef
commit 8eaafb6bda
6 changed files with 109 additions and 100 deletions
+3 -2
View File
@@ -34,8 +34,7 @@ def deep_merge(d, u, only_existing=True):
d[k] = u[k] d[k] = u[k]
return d return d
def main() -> None:
if __name__ == '__main__':
files = [ files = [
"results/WVWZZZE1ZMP010760/2024/10/18/vehicle_WVWZZZE1ZMP010760_2024-10-15T12-05-23.json", "results/WVWZZZE1ZMP010760/2024/10/18/vehicle_WVWZZZE1ZMP010760_2024-10-15T12-05-23.json",
"results/WVWZZZE1ZMP010760/2024/10/19/vehicle_WVWZZZE1ZMP010760_2024-10-19T00-00-34.json", "results/WVWZZZE1ZMP010760/2024/10/19/vehicle_WVWZZZE1ZMP010760_2024-10-19T00-00-34.json",
@@ -72,3 +71,5 @@ if __name__ == '__main__':
# Check integrity # Check integrity
assert src == merged_list assert src == merged_list
if __name__ == '__main__':
main()
+4 -2
View File
@@ -235,8 +235,7 @@ def make_values(_ts_list, _ep: Endpoint, ic=0):
return v_list return v_list
def main() -> None:
if __name__ == '__main__':
end_points = [] end_points = []
for k in settings.eps_defs.keys(): for k in settings.eps_defs.keys():
end_points.append(Endpoint(k, settings.eps_defs[k])) end_points.append(Endpoint(k, settings.eps_defs[k]))
@@ -326,3 +325,6 @@ if __name__ == '__main__':
plot.grid() plot.grid()
plot.show() plot.show()
if __name__ == '__main__':
main()
+25 -21
View File
@@ -29,32 +29,33 @@ def model_bat_dcr(temperature: float, soc: float, p: Params):
return rb * np.exp(p.alpha*(t2 - tb2) + p.beta*(_t - tb)) return rb * np.exp(p.alpha*(t2 - tb2) + p.beta*(_t - tb))
temps = [0, 5, 10, 20, 25, 40] def main() -> None:
pl = 10000 temps = [0, 5, 10, 20, 25, 40]
il = 100 pl = 10000
ul = 100 il = 100
rl = ul/il ul = 100
p_ = np.linspace(0, 20000, 100) rl = ul/il
i_ = p_/ul p_ = np.linspace(0, 20000, 100)
i_ = p_/ul
bat_params = Params(alpha=0.0007545, beta=-0.07033) bat_params = Params(alpha=0.0007545, beta=-0.07033)
rt_ = [] rt_ = []
for t in temps: for t in temps:
rt_.append(model_bat_dcr(t, 100, bat_params)) rt_.append(model_bat_dcr(t, 100, bat_params))
plot.figure() plot.figure()
plot.plot(temps, rt_) plot.plot(temps, rt_)
r, t = bas(100) r, t = bas(100)
plot.title(f"DCR vs temperature (Base DCR={r}@{t}°C)") plot.title(f"DCR vs temperature (Base DCR={r}@{t}°C)")
plot.xlabel("Temperature [°C]") plot.xlabel("Temperature [°C]")
plot.ylabel("R [Ohm]") plot.ylabel("R [Ohm]")
plot.grid() plot.grid()
titles = [ titles = [
"Battery power loss vs internal battery resistance (DCR)", "Battery power loss vs internal battery resistance (DCR)",
"Batter power consumption vs internal battery resistance (DCR)" "Batter power consumption vs internal battery resistance (DCR)"
] ]
for sp, name, title in zip([0, 1], ["P_loss [kW]", "P_batt [kW]"], titles): for sp, name, title in zip([0, 1], ["P_loss [kW]", "P_batt [kW]"], titles):
plot.figure() plot.figure()
legs = [] legs = []
plot.grid() plot.grid()
@@ -71,4 +72,7 @@ for sp, name, title in zip([0, 1], ["P_loss [kW]", "P_batt [kW]"], titles):
plot.legend(legs) plot.legend(legs)
plot.ylabel(name) plot.ylabel(name)
plot.show() plot.show()
if __name__ == '__main__':
main()
+3 -3
View File
@@ -120,9 +120,7 @@ def jay_merge_full(_old, _diff):
return res return res
def main() -> None:
if __name__ == '__main__':
result = jay_diff_add({}, {'a': 'hamburger', 'b': 'fries', 'c': {'e': 'coke', 'f': 'coffee'}}) result = jay_diff_add({}, {'a': 'hamburger', 'b': 'fries', 'c': {'e': 'coke', 'f': 'coffee'}})
assert result == {'a':'hamburger', 'b':'fries', 'c': {'e': 'coke', 'f': 'coffee'}} assert result == {'a':'hamburger', 'b':'fries', 'c': {'e': 'coke', 'f': 'coffee'}}
@@ -566,3 +564,5 @@ if __name__ == '__main__':
result = jay_merge_full(old, {'update':update, 'add':add, 'delete':delete}) result = jay_merge_full(old, {'update':update, 'add':add, 'delete':delete})
assert result == old assert result == old
if __name__ == '__main__':
main()
+39 -37
View File
@@ -54,7 +54,6 @@ car_list = [
def rho(temperature_degc: float, p_pa: float =g_p0): def rho(temperature_degc: float, p_pa: float =g_p0):
return p_pa/(g_RS*(temperature_degc + 273.15)) return p_pa/(g_RS*(temperature_degc + 273.15))
# Force : N = kg·m·s2 # Force : N = kg·m·s2
def fd(rho: float, velocity_kmh: float, c_val: float, area: float): def fd(rho: float, velocity_kmh: float, c_val: float, area: float):
vel = velocity_kmh / 3.6 vel = velocity_kmh / 3.6
@@ -62,15 +61,15 @@ def fd(rho: float, velocity_kmh: float, c_val: float, area: float):
res = 0.5*rho*vel*vel*cwa res = 0.5*rho*vel*vel*cwa
return res return res
def main() -> None:
# Fd vs. velocity, param: temperature
temps_list = [-20, -10, 0, 10, 20, 30]
vel_list = [20, 40, 60, 80, 100, 120, 130, 140, 160]
reference = fd(rho(20), 100, c_val_id3, area_id3)
temps_list_leg = [f"{t}°C" for t in temps_list]
# Fd vs. velocity, param: temperature plot.figure()
temps_list = [-20, -10, 0, 10, 20, 30] for temp_degc in temps_list:
vel_list = [20, 40, 60, 80, 100, 120, 130, 140, 160]
reference = fd(rho(20), 100, c_val_id3, area_id3)
temps_list_leg = [f"{t}°C" for t in temps_list]
plot.figure()
for temp_degc in temps_list:
rho_t = rho(temp_degc) rho_t = rho(temp_degc)
y_fd = [] y_fd = []
for vel_kmh in vel_list: for vel_kmh in vel_list:
@@ -79,22 +78,22 @@ for temp_degc in temps_list:
plot.plot(vel_list, y_fd) plot.plot(vel_list, y_fd)
plot.title("Windwiderstand vs Geschwindigkeit") plot.title("Windwiderstand vs Geschwindigkeit")
plot.ylabel("Windwiderstand [%]") plot.ylabel("Windwiderstand [%]")
plot.xlabel("Geschwindigkeit [km/h]") plot.xlabel("Geschwindigkeit [km/h]")
plot.legend(temps_list_leg) plot.legend(temps_list_leg)
plot.grid() plot.grid()
# Fd vs. velocity, param: car # Fd vs. velocity, param: car
temp = 20 temp = 20
vel_list = [20, 40, 60, 80, 100, 120, 130, 140, 160] vel_list = [20, 40, 60, 80, 100, 120, 130, 140, 160]
car_list_leg = [f"{t['car']}" for t in car_list] car_list_leg = [f"{t['car']}" for t in car_list]
rho_t = rho(temp) rho_t = rho(temp)
reference = fd(rho_t, 100, c_val_id3, area_id3) reference = fd(rho_t, 100, c_val_id3, area_id3)
plot.figure() plot.figure()
for car in car_list: for car in car_list:
y_fd = [] y_fd = []
for vel_kmh in vel_list: for vel_kmh in vel_list:
fd_t = (fd(rho_t, vel_kmh, car['cw'], car['area'])/reference - 1) * 100 fd_t = (fd(rho_t, vel_kmh, car['cw'], car['area'])/reference - 1) * 100
@@ -102,23 +101,26 @@ for car in car_list:
plot.plot(vel_list, y_fd) plot.plot(vel_list, y_fd)
plot.ylabel("Windwiderstand ID.3 [%]") plot.ylabel("Windwiderstand ID.3 [%]")
plot.xlabel("Geschwindigkeit [km/h]") plot.xlabel("Geschwindigkeit [km/h]")
plot.title("Windwiderstand vs Geschwindigkeit") plot.title("Windwiderstand vs Geschwindigkeit")
plot.legend(car_list_leg) plot.legend(car_list_leg)
plot.grid() plot.grid()
plot.figure() plot.figure()
y_fd = [] y_fd = []
for vel_kmh in vel_list: for vel_kmh in vel_list:
fd_t = fd(rho_t, vel_kmh, c_val_id3, area_id3) fd_t = fd(rho_t, vel_kmh, c_val_id3, area_id3)
y_fd.append(fd_t) y_fd.append(fd_t)
plot.plot(vel_list, y_fd) plot.plot(vel_list, y_fd)
plot.ylabel("Windwiderstand [N]") plot.ylabel("Windwiderstand [N]")
plot.xlabel("Geschwindigkeit [km/h]") plot.xlabel("Geschwindigkeit [km/h]")
plot.title("Windwiderstand vs Geschwindigkeit") plot.title("Windwiderstand vs Geschwindigkeit")
plot.legend(car_list_leg) plot.legend(car_list_leg)
plot.grid() plot.grid()
plot.show() plot.show()
if __name__ == '__main__':
main()
+4 -4
View File
@@ -23,7 +23,6 @@ domains = [
"measurements" "measurements"
] ]
class WeCollector: class WeCollector:
def __init__(self, user): def __init__(self, user):
# Init collecting records # Init collecting records
@@ -92,7 +91,6 @@ class WeCollector:
except Exception as e: except Exception as e:
print(f"Exception: {e}") print(f"Exception: {e}")
def request_loop(wc: WeCollector): def request_loop(wc: WeCollector):
_date_last = None _date_last = None
_file_timestamp = None _file_timestamp = None
@@ -122,8 +120,7 @@ def request_loop(wc: WeCollector):
time_to_wait = 0 time_to_wait = 0
time.sleep(time_to_wait) time.sleep(time_to_wait)
def main() -> None:
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog="We Collect", description="Collects vehicle data") parser = argparse.ArgumentParser(prog="We Collect", description="Collects vehicle data")
parser.add_argument("username", help="Username to collect data for (must exist in credentials.py)") parser.add_argument("username", help="Username to collect data for (must exist in credentials.py)")
parser.add_argument("--loop", help="Execute once or create event loop", type=bool, default=False) parser.add_argument("--loop", help="Execute once or create event loop", type=bool, default=False)
@@ -142,3 +139,6 @@ if __name__ == '__main__':
print(f"Terminated with Exception {e}") print(f"Terminated with Exception {e}")
print(f"Terminated Normally") print(f"Terminated Normally")
if __name__ == '__main__':
main()