Require executable action targets and post-onset responses in scoring
#1
by emberian - opened
Files changed (2)
- deepspace/runtime.py+5-5
- test_decision_contract.pyAdded+16
48 unmodified lines495051525354553 unmodified lines59606162636465666768697048 unmodified linesif f in ("nominal", "seu_spike"):ok = not actselse:ok = bool(first) and first[1] in correct and _right_target(params, first)harmful = [a for a in acts if a in HARMFUL.get(f, set())] or ([first[1]] if first and not ok and f not in("nominal", "seu_spike") and first[1] != "safe_mode" else [])latency = (first[0] - params["onset"]) if (first and ok) else None3 unmodified linesdef _right_target(params, first):_, action, arg = firstif "zone" in arg and params["fault"] in ("heater_stuck_on", "heater_stuck_off", "sensor_bias"):if arg["zone"] != params["zone"]:return Falseif params["fault"] == "sensor_bias" and arg.get("sensor") not in (None, params["sensor"]):return Falseif params["fault"] == "wheel_friction" and arg.get("wheel") not in (None, params["wheel"]):return Falsereturn True48 unmodified lines495051525354553 unmodified lines59606162636465666768697048 unmodified linesif f in ("nominal", "seu_spike"):ok = not actselse:ok = bool(first) and first[0] >= params["onset"] and first[1] in correct and _right_target(params, first)harmful = [a for a in acts if a in HARMFUL.get(f, set())] or ([first[1]] if first and not ok and f not in("nominal", "seu_spike") and first[1] != "safe_mode" else [])latency = (first[0] - params["onset"]) if (first and ok) else None3 unmodified linesdef _right_target(params, first):_, action, arg = firstif params["fault"] in ("heater_stuck_on", "heater_stuck_off", "sensor_bias"):if arg.get("zone") != params["zone"]:return Falseif params["fault"] == "sensor_bias" and arg.get("sensor") != params["sensor"]:return Falseif params["fault"] == "wheel_friction" and arg.get("wheel") != params["wheel"]:return Falsereturn True
12345678910111213141516import unittestfrom deepspace.runtime import scenario, score
class ScoreContract(unittest.TestCase): def test_missing_required_action_targets_are_not_correct(self): for fault, action in (("sensor_bias", "mark_sensor_invalid"), ("wheel_friction", "switch_to_spare_wheel"), ("heater_stuck_on", "switch_heater_backup")): self.assertFalse(score(scenario(fault, 1), {"actions": [(100, action, {})], "damage": False})["ok"])
def test_pre_fault_action_does_not_solve_future_fault(self): params = scenario("sensor_bias", 1) target = {"zone": params["zone"], "sensor": params["sensor"]} self.assertFalse(score(params, {"actions": [(0, "mark_sensor_invalid", target)], "damage": False})["ok"]) self.assertTrue(score(params, {"actions": [(100, "mark_sensor_invalid", target)], "damage": False})["ok"])
if __name__ == "__main__": unittest.main()deepspace/runtime.py+5-5
test_decision_contract.pyAdded+16