Skip to content

Commit

Permalink
change default setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobuenaposada committed Jan 5, 2025
1 parent 1013f63 commit ea0f7e3
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 59 deletions.
64 changes: 26 additions & 38 deletions default_setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@
"sectors": [
{
"lo": 0,
"hi": 100,
"color": "#46877f"
"hi": 70,
"color": "#cc2c24"
},
{
"lo": 86,
"hi": 255,
"color": "#cc2c24"
}
]
},
Expand All @@ -61,13 +66,7 @@
"tag": "gauge7",
"label": "CAM",
"suffix": "",
"sectors": [
{
"lo": 0,
"hi": 100,
"color": "#46877f"
}
]
"sectors": []
},
"bat": {
"tag": "gauge6",
Expand All @@ -77,13 +76,13 @@
"sectors": [
{
"lo": 0,
"hi": 12,
"hi": 13,
"color": "#cc2c24"
},
{
"lo": 12,
"hi": 20,
"color": "#46877f"
"lo": 15,
"hi": 26,
"color": "#cc2c24"
}
]
},
Expand All @@ -95,8 +94,8 @@
"sectors": [
{
"lo": 0,
"hi": 100,
"color": "#46877f"
"hi": 110,
"color": "#41748d"
}
]
},
Expand All @@ -107,9 +106,9 @@
"suffix": "",
"sectors": [
{
"lo": 0,
"hi": 70,
"color": "#46877f"
"lo": 60,
"hi": 150,
"color": "#cc2c24"
}
]
},
Expand All @@ -120,14 +119,14 @@
"suffix": "",
"sectors": [
{
"lo": 94,
"hi": 150,
"color": "#cc2c24"
"lo": -40,
"hi": 60,
"color": "#46877f"
},
{
"lo": 0,
"hi": 94,
"color": "#46877f"
"lo": 104,
"hi": 150,
"color": "#cc2c24"
}
]
},
Expand All @@ -140,16 +139,11 @@
"sectors": [
{
"lo": 0,
"hi": 12,
"hi": 11.6,
"color": "#cc2c24"
},
{
"lo": 12,
"hi": 16,
"color": "#46877f"
},
{
"lo": 16,
"lo": 14.71,
"hi": 30,
"color": "#cc2c24"
}
Expand All @@ -161,13 +155,7 @@
"decimals": 1,
"label": "MAP",
"suffix": "",
"sectors": [
{
"lo": 0,
"hi": 3,
"color": "#46877f"
}
]
"sectors": []
},
"an0": {
"tag": "not use",
Expand Down
2 changes: 1 addition & 1 deletion src/bench/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
backend.ecu.ecu.data5 = [0 for _ in range(20)]

while True:
numbers = range(random.choice(range(255)), random.choice(range(255)))
numbers = range(255)
numbers = numbers if bool(random.getrandbits(1)) else reversed(numbers)
for number in numbers:
backend.ecu.ecu.data0 = [number for _ in range(38)]
Expand Down
52 changes: 36 additions & 16 deletions src/devices/setup_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def update(self, setup):
setup = self._update_to_3_5_0(setup)
if setup["version"] == "3.5.0":
setup = self._update_to_3_6_0(setup)
if setup["version"] == "3.6.0":
setup = self._update_to_4_0_0(setup)

return setup

@staticmethod
Expand Down Expand Up @@ -130,21 +133,38 @@ def _update_to_3_6_0(setup):
def _update_to_4_0_0(setup):
"""From 3.6.0 to 4.0.0"""
setup["version"] = "4.0.0"
setup["tps"]["tag"] = "bar3"
setup.update()
if "tag" in setup:
setup["tps"]["tag"] = "bar3"
setup["template"] = "basic"
setup["o2"].pop("max", None)
setup["map"].pop("max", None)
setup["iat"].pop("max", None)
setup["eth"].pop("max", None)
setup["ect"].pop("max", None)
setup["cam"].pop("max", None)
setup["bat"].pop("max", None)
setup["an0"].pop("max", None)
setup["an1"].pop("max", None)
setup["an2"].pop("max", None)
setup["an3"].pop("max", None)
setup["an4"].pop("max", None)
setup["an5"].pop("max", None)
setup["an6"].pop("max", None)
setup["an7"].pop("max", None)
if "o2" in setup:
setup["o2"].pop("max", None)
if "map" in setup:
setup["map"].pop("max", None)
if "iat" in setup:
setup["iat"].pop("max", None)
if "eth" in setup:
setup["eth"].pop("max", None)
if "ect" in setup:
setup["ect"].pop("max", None)
if "cam" in setup:
setup["cam"].pop("max", None)
if "bat" in setup:
setup["bat"].pop("max", None)
if "an0" in setup:
setup["an0"].pop("max", None)
if "an1" in setup:
setup["an1"].pop("max", None)
if "an2" in setup:
setup["an2"].pop("max", None)
if "an3" in setup:
setup["an3"].pop("max", None)
if "an4" in setup:
setup["an4"].pop("max", None)
if "an5" in setup:
setup["an5"].pop("max", None)
if "an6" in setup:
setup["an6"].pop("max", None)
if "an7" in setup:
setup["an7"].pop("max", None)
return setup
15 changes: 13 additions & 2 deletions src/tests/devices/setup_updater/test_setup_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,21 @@ def test_update_3_4_0(self):
assert m__update_to_3_5_0.called is True

def test_update_3_5_0(self):
assert SetupUpdater().update({"version": "3.5.0"}) == {"version": "3.6.0"}
with mock.patch(
"devices.setup_updater.SetupUpdater._update_to_3_6_0"
) as m__update_to_3_6_0:
SetupUpdater().update({"version": "3.5.0"})
assert m__update_to_3_6_0.called is True

def test_update_3_6_0(self):
assert SetupUpdater().update({"version": "3.6.0"}) == {"version": "3.6.0"}
with mock.patch(
"devices.setup_updater.SetupUpdater._update_to_4_0_0"
) as m__update_to_4_0_0:
SetupUpdater().update({"version": "3.6.0"})
assert m__update_to_4_0_0.called is True

def test_update_4_0_0(self):
assert SetupUpdater().update({"version": "4.0.0"}) == {"version": "4.0.0"}

def test__update_to_2_4_0(self, fixtures_dir):
with open(os.path.join(fixtures_dir, "default_setup_2_3_2.json")) as file:
Expand Down
4 changes: 2 additions & 2 deletions src/tests/devices/test_setup_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ def test_update_key(self):
assert self.setup.get_value("tps") == {
"label": "TPS",
"max": 100,
"sectors": [{"color": "#46877f", "hi": 100, "lo": 0}],
"sectors": [{"color": "#41748d", "hi": 110, "lo": 0}],
"suffix": "",
"tag": "bar3",
}
self.setup.update_key("tps", {"label": "foo"})
assert self.setup.get_value("tps") == {
"label": "foo",
"max": 100,
"sectors": [{"color": "#46877f", "hi": 100, "lo": 0}],
"sectors": [{"color": "#41748d", "hi": 110, "lo": 0}],
"suffix": "",
"tag": "bar3",
}
Expand Down

0 comments on commit ea0f7e3

Please sign in to comment.