Skip to content

Commit

Permalink
feat: add threshold dynalab
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciroye committed Jan 9, 2024
1 parent d6073de commit 83fed13
Show file tree
Hide file tree
Showing 6 changed files with 373 additions and 307 deletions.
5 changes: 5 additions & 0 deletions backend/app/api/endpoints/base/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ async def check_sign_consent(model: CheckSignConsentRequest):
@router.post("/update_config_yaml", response_model={})
async def update_config_yaml(model: UpdateYamlConfiguration):
return TaskService().update_config_yaml(model.task_id, model.config_yaml)


@router.get("/allow_update_dynalab_submissions/{task_id}/{user_id}", response_model={})
async def allow_update_dynalab_submissions(task_id: int, user_id: int):
return TaskService().allow_update_dynalab_submissions(task_id, user_id)
9 changes: 9 additions & 0 deletions backend/app/domain/services/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,12 @@ def download_model_results(self, task_id: int):
}
)
return json.dumps(results_models_list, cls=CustomJSONEncoder)

def amount_of_models_uploaded_in_hr_diff(self, task_id: int, user_id: int):
hr_diff = self.task_repository.get_dynalab_hr_diff(task_id)
amount_of_models_uploaded_in_hr_diff = (
self.model_repository.get_amount_of_models_uploaded_in_hr_diff(
task_id, user_id, hr_diff
)
)
return amount_of_models_uploaded_in_hr_diff
12 changes: 12 additions & 0 deletions backend/app/domain/services/base/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,15 @@ def sign_in_consent(self, task_id: int, user_id: int):

def update_config_yaml(self, task_id: int, config_yaml: str):
return self.task_repository.update_config_yaml(task_id, config_yaml)

def allow_update_dynalab_submissions(self, task_id: int, user_id: int):
dynalab_threshold = self.task_repository.get_dynalab_threshold(
task_id
).dynalab_threshold
hr_diff = self.task_repository.get_dynalab_hr_diff(task_id)
amount_of_models_uploaded_in_hr_diff = (
self.model_repository.get_amount_of_models_uploaded_in_hr_diff(
task_id, user_id, hr_diff
)
)
return amount_of_models_uploaded_in_hr_diff < dynalab_threshold
15 changes: 15 additions & 0 deletions backend/app/infrastructure/repositories/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,18 @@ def download_model_results(self, task_id: int):
.all()
)
return query

def get_amount_of_models_uploaded_in_hr_diff(
self, task_id: int, user_id: int, hr_diff: int
):
# hr_diff is in hours
return (
self.session.query(func.count(self.model.id))
.filter(
self.model.tid == task_id,
self.model.uid == user_id,
func.timediff(func.now(), self.model.upload_datetime)
< f"0:{hr_diff}:0",
)
.scalar()
)
14 changes: 14 additions & 0 deletions backend/app/infrastructure/repositories/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,17 @@ def get_max_amount_examples_on_a_day(self, task_id: int):
.filter(self.model.id == task_id)
.first()
)

def get_dynalab_threshold(self, task_id: int):
return (
self.session.query(self.model.dynalab_threshold)
.filter(self.model.id == task_id)
.first()
)

def get_dynalab_hr_diff(self, task_id: int):
return (
self.session.query(self.model.dynalab_hr_diff)
.filter(self.model.id == task_id)
.first()
)
Loading

0 comments on commit 83fed13

Please sign in to comment.