def create_road_condition_action(road_condition_id: int, instrument_system_id: int, action_name: str, road_condition_action_goal_id: int, constraint: RoadConstraintInputObject, description: str, instrument_action_ids: graphene.List( graphene.Int), auto_resolver: bool = False) \ -> RoadConditionAction: instrument_system = get_instrument_system_with_id(instrument_system_id) road_condition_action_goal = get_road_condition_action_goal_by_id( road_condition_action_goal_id) new_constraint = create_road_condition_action_constraint(constraint) road_condition_action = RoadConditionAction( road_condition_action_goal=road_condition_action_goal, instrument_system=instrument_system, constraint=new_constraint, description=description) road_condition = get_road_condition_with_id(road_condition_id) update_road_condition_action_name(road_condition_action, action_name, auto_resolver) road_condition_action.save() RoadConditionToRoadConditionAction( road_condition=road_condition, road_condition_action=road_condition_action).save() replace_instrument_action(road_condition_action, instrument_action_ids) return road_condition_action
def test_condition_creation(self): condition_type = self.condition_types[0] parent = self.conditions[1] action = self.rc_actions[0] condition = create_road_condition("New_Name", None, 10, condition_type.id, [action.id, -1], parent.id, None) created_condition = get_road_condition_with_id(condition.id) self.assertEqual(condition, created_condition)
def delete_road_condition(road_condition_id: int): road_condition = get_road_condition_with_id(road_condition_id) delete_parents(road_condition) RoadConditionToRoadConditionAction.objects.filter( road_condition=road_condition).delete() from_road_condition = RoadConditionToRoadCondition.objects.filter( from_road_condition=road_condition).all() RoadConditionDate.objects.filter( road_condition_id=road_condition_id).delete() for link in from_road_condition: delete_road_condition(link.to_road_condition.id) link.delete() road_condition.delete()
def update_parents(road_condition: RoadCondition, parent_rs: int, parent_rc: int): if parent_rs and has_road_segment_with_id(parent_rs): delete_parents(road_condition) RoadSegmentToRoadCondition( road_segment=get_road_segment_with_id(parent_rs), road_condition=road_condition).save() elif parent_rc and has_road_condition_with_id(parent_rc): from_road_condition = get_road_condition_with_id(parent_rc) if check_road_conditions(from_road_condition, road_condition): delete_parents(road_condition) RoadConditionToRoadCondition( from_road_condition=from_road_condition, to_road_condition=road_condition).save()
def test_update_road_condition(self): condition = self.conditions[0] condition_type = self.condition_types[1] parent_rc = self.conditions[1] rc_action = self.rc_actions[1] update_road_condition(condition.id, condition.name, None, condition.value, condition_type.id, None, parent_rc.id, [rc_action.id]) updated_condition = get_road_condition_with_id(condition.id) self.assertEqual(condition_type, updated_condition.road_condition_type) self.assertEqual(parent_rc, get_road_condition_parents(updated_condition)[0]) self.assertEqual( rc_action, RoadConditionToRoadConditionAction.objects.filter( road_condition=updated_condition).first().road_condition_action )
def create_response_plan(road_segment_id: int, operator: str, road_condition_id: int, scenario_id: int, parent_id: int) -> ResponsePlan: if operator: response_plan = ResponsePlan(operator=operator) if road_segment_id: response_plan.road_segment = get_road_segment_with_id( road_segment_id) if road_condition_id: response_plan.road_condition = get_road_condition_with_id( road_condition_id) if scenario_id: response_plan.scenario = get_scenario_with_id(scenario_id) if parent_id: response_plan.parent = get_response_plan_with_id(parent_id) response_plan.save() return response_plan else: raise InvalidInputException()
def update_road_condition( road_condition_id: int, name: str, date: RoadConditionDateInputObject, value: str, road_condition_type_id: int, parent_rs: int, parent_rc: int, road_condition_action_ids: graphene.List(graphene.Int) ) -> RoadCondition: road_condition = get_road_condition_with_id(road_condition_id) road_condition.name = name if name else road_condition.name road_condition.value = value if value else road_condition.value if road_condition_type_id: road_condition.road_condition_type = get_road_condition_type_with_id( road_condition_type_id) if date: update_road_condition_date(road_condition, date) road_condition.save() if parent_rs or parent_rc: update_parents(road_condition, parent_rs, parent_rc) if road_condition_action_ids: replace_road_condition_actions(road_condition, road_condition_action_ids) return road_condition
def update_response_plan_road_condition(response_plan: ResponsePlan, road_condition_id: int): road_condition = get_road_condition_with_id(road_condition_id) response_plan.road_condition = road_condition
def test_get_condition_exception(self): with self.assertRaises(ObjectNotFoundException): get_road_condition_with_id(-1)
def test_has_and_get_condition(self): condition = self.conditions[0] getter_condition = get_road_condition_with_id(condition.id) self.assertEqual(condition, getter_condition) self.assertTrue(has_road_condition_with_id(condition.id))