def update_stats_after_task_state_change( project_id: int, user_id: int, last_state: TaskStatus, new_state: TaskStatus, action="change", ): """ Update stats when a task has had a state change """ if new_state in [ TaskStatus.READY, TaskStatus.LOCKED_FOR_VALIDATION, TaskStatus.LOCKED_FOR_MAPPING, ]: return # No stats to record for these states project = ProjectService.get_project_by_id(project_id) user = UserService.get_user_by_id(user_id) project, user = StatsService._update_tasks_stats( project, user, last_state, new_state, action) UserService.upsert_mapped_projects(user_id, project_id) project.last_updated = timestamp() # Transaction will be saved when task is saved return project, user
def update_stats_after_task_state_change(project_id: int, user_id: int, new_state: TaskStatus, task_id: int): """ Update stats when a task has had a state change """ if new_state in [ TaskStatus.READY, TaskStatus.LOCKED_FOR_VALIDATION, TaskStatus.LOCKED_FOR_MAPPING ]: return # No stats to record for these states project = ProjectService.get_project_by_id(project_id) user = UserService.get_user_by_id(user_id) if new_state == TaskStatus.MAPPED: StatsService._set_counters_after_mapping(project, user) elif new_state == TaskStatus.INVALIDATED: StatsService._set_counters_after_invalidated( task_id, project, user) elif new_state == TaskStatus.VALIDATED: StatsService._set_counters_after_validated(project, user) elif new_state == TaskStatus.BADIMAGERY: StatsService._set_counters_after_bad_imagery(project) UserService.upsert_mapped_projects(user_id, project_id) project.last_updated = timestamp() # Transaction will be saved when task is saved return project, user
def test_upsert_inserts_project_if_not_exists(self): if self.skip_tests: return # Arrange UserService.upsert_mapped_projects(self.test_user.id, self.test_project.id) # Act projects = UserService.get_mapped_projects(self.test_user.username, 'en') # Assert mapped_project = projects.mapped_projects[0] self.assertEqual(mapped_project.project_id, self.test_project.id) # We should find we've mapped the test project