Skip to content

Commit

Permalink
model all info
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciroye committed Jul 18, 2023
1 parent 1807ddf commit 8488e58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions backend/app/api/endpoints/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,8 @@ def get_models_per_user(user_id: int):
@router.get("/delete_model/{model_id}")
def delete_model(model_id: int):
return ModelService().delete_model(model_id)


@router.get("/get_all_model_info_by_id/{model_id}")
def get_all_model_info_by_id(model_id: int):
return ModelService().get_all_model_info_by_id(model_id)
6 changes: 6 additions & 0 deletions backend/app/domain/services/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,9 @@ def update_model_status(self, model_id: int):

def get_models_per_user(self, user_id: int):
return self.model_repository.get_models_per_user(user_id)

def delete_model(self, model_id: int):
return self.model_repository.delete_model(model_id)

def get_all_model_info_by_id(self, model_id: int):
return self.model_repository.get_all_model_info_by_id(model_id)
29 changes: 27 additions & 2 deletions backend/app/infrastructure/repositories/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def get_model_info_by_id(self, model_id: int) -> dict:
instance = (
self.session.query(self.model).filter(self.model.id == model_id).one()
)
instance = self.instance_converter.instance_to_dict(instance)
return instance
return self.instance_converter.instance_to_dict(instance)

def get_model_in_the_loop(self, task_id: int) -> dict:
models_in_the_loop = (
Expand Down Expand Up @@ -166,6 +165,32 @@ def get_total_models_per_user_id(self, user_id):
return self.session.query(self.model).filter(self.model.uid == user_id).count()

def delete_model(self, model_id: int):
self.session.query(Score).filter(Score.mid == model_id).delete()
self.session.query(self.model).filter(self.model.id == model_id).delete()
self.session.flush()
self.session.commit()

def get_all_model_info_by_id(self, model_id: int):
return (
self.session.query(
Model.id,
Model.name,
Model.desc,
Model.params,
Model.languages,
Model.light_model,
Model.deployment_status,
Model.is_in_the_loop,
Model.is_published,
Model.upload_datetime,
ChallengesTypes.name.label("community"),
Task.name.label("task"),
func.avg(Score.perf).label("score"),
)
.join(Task, Task.id == self.model.tid)
.join(ChallengesTypes, ChallengesTypes.id == Task.challenge_type)
.join(Score, Score.mid == self.model.id)
.filter(self.model.id == model_id)
.group_by(self.model.id)
.first()
)

0 comments on commit 8488e58

Please sign in to comment.