forked from enviPath/enviPy
[FIX] Fixed Search Output, Legacy API Model Endpoint, Handle ObjectsDoesNotExists in views (#297)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#297
This commit is contained in:
@ -5,27 +5,31 @@ from django.conf import settings as s
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from ninja import Field, Form, Router, Schema, Query
|
||||
from ninja import Field, Form, Query, Router, Schema
|
||||
from ninja.security import SessionAuth
|
||||
|
||||
from utilities.chem import FormatConverter
|
||||
from utilities.misc import PackageExporter
|
||||
|
||||
from .logic import GroupManager, PackageManager, SettingManager, UserManager, SearchManager
|
||||
from .logic import GroupManager, PackageManager, SearchManager, SettingManager, UserManager
|
||||
from .models import (
|
||||
Compound,
|
||||
CompoundStructure,
|
||||
Edge,
|
||||
EnviFormer,
|
||||
EPModel,
|
||||
MLRelativeReasoning,
|
||||
Node,
|
||||
PackageBasedModel,
|
||||
ParallelRule,
|
||||
Pathway,
|
||||
Reaction,
|
||||
Rule,
|
||||
RuleBasedRelativeReasoning,
|
||||
Scenario,
|
||||
SimpleAmbitRule,
|
||||
User,
|
||||
UserPackagePermission,
|
||||
ParallelRule,
|
||||
)
|
||||
|
||||
Package = s.GET_PACKAGE_MODEL()
|
||||
@ -237,11 +241,11 @@ def search(request, search: Query[Search]):
|
||||
if "Compound Structures" in search_res:
|
||||
res["structure"] = search_res["Compound Structures"]
|
||||
|
||||
if "Reaction" in search_res:
|
||||
res["reaction"] = search_res["Reaction"]
|
||||
if "Reactions" in search_res:
|
||||
res["reaction"] = search_res["Reactions"]
|
||||
|
||||
if "Pathway" in search_res:
|
||||
res["pathway"] = search_res["Pathway"]
|
||||
if "Pathways" in search_res:
|
||||
res["pathway"] = search_res["Pathways"]
|
||||
|
||||
if "Rules" in search_res:
|
||||
res["rule"] = search_res["Rules"]
|
||||
@ -1753,26 +1757,46 @@ class ModelWrapper(Schema):
|
||||
class ModelSchema(Schema):
|
||||
aliases: List[str] = Field([], alias="aliases")
|
||||
description: str = Field(None, alias="description")
|
||||
evalPackages: List["SimplePackage"] = Field([])
|
||||
evalPackages: List["SimplePackage"] = Field([], alias="eval_packages")
|
||||
id: str = Field(None, alias="url")
|
||||
identifier: str = "relative-reasoning"
|
||||
# "info" : {
|
||||
# "Accuracy (Single-Gen)" : "0.5932962678936605" ,
|
||||
# "Area under PR-Curve (Single-Gen)" : "0.5654653182134282" ,
|
||||
# "Area under ROC-Curve (Single-Gen)" : "0.8178302405034772" ,
|
||||
# "Precision (Single-Gen)" : "0.6978730822873083" ,
|
||||
# "Probability Threshold" : "0.5" ,
|
||||
# "Recall/Sensitivity (Single-Gen)" : "0.4484149210261006"
|
||||
# } ,
|
||||
info: dict = Field({}, alias="info")
|
||||
name: str = Field(None, alias="name")
|
||||
pathwayPackages: List["SimplePackage"] = Field([])
|
||||
pathwayPackages: List["SimplePackage"] = Field([], alias="pathway_packages")
|
||||
reviewStatus: str = Field(None, alias="review_status")
|
||||
rulePackages: List["SimplePackage"] = Field([])
|
||||
rulePackages: List["SimplePackage"] = Field([], alias="rule_packages")
|
||||
scenarios: List["SimpleScenario"] = Field([], alias="scenarios")
|
||||
status: str
|
||||
statusMessage: str
|
||||
threshold: str
|
||||
type: str
|
||||
status: str = Field(None, alias="model_status")
|
||||
statusMessage: str = Field(None, alias="status_message")
|
||||
threshold: str = Field(None, alias="threshold")
|
||||
type: str = Field(None, alias="model_type")
|
||||
|
||||
@staticmethod
|
||||
def resolve_info(obj: EPModel):
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def resolve_status_message(obj: EPModel):
|
||||
for k, v in PackageBasedModel.PROGRESS_STATUS_CHOICES.items():
|
||||
if k == obj.model_status:
|
||||
return v
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def resolve_threshold(obj: EPModel):
|
||||
return f"{obj.threshold:.2f}"
|
||||
|
||||
@staticmethod
|
||||
def resolve_model_type(obj: EPModel):
|
||||
if isinstance(obj, RuleBasedRelativeReasoning):
|
||||
return "RULEBASED"
|
||||
elif isinstance(obj, MLRelativeReasoning):
|
||||
return "ECC"
|
||||
elif isinstance(obj, EnviFormer):
|
||||
return "ENVIFORMER"
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@router.get("/model", response={200: ModelWrapper, 403: Error})
|
||||
|
||||
Reference in New Issue
Block a user