From fddbf0d24d5081e86fc4680bee5a974289e59be3 Mon Sep 17 00:00:00 2001 From: Tom Gebhardt Date: Thu, 19 Oct 2023 16:32:32 +0200 Subject: [PATCH] the new route /csh/study runs now --- app/main.py | 2 ++ app/models/csh.py | 68 ++++++++++++++++++++++++++++++--------- app/routers/csh_router.py | 17 +++++++--- 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/app/main.py b/app/main.py index 4d69ad8..c4f1680 100644 --- a/app/main.py +++ b/app/main.py @@ -3,6 +3,7 @@ from fastapi.middleware.cors import CORSMiddleware from app.routers.router import base_router +from app.routers.csh_router import csh_router from app.metrics.assessments_lifespan import get_tasks_definitions from app.dependencies.settings import get_settings @@ -49,6 +50,7 @@ lifespan=get_tasks_definitions, ) app.include_router(base_router) +app.include_router(csh_router) config = get_settings() origins = config.allowed_origins diff --git a/app/models/csh.py b/app/models/csh.py index e11b790..446c706 100644 --- a/app/models/csh.py +++ b/app/models/csh.py @@ -1,20 +1,58 @@ -# identifier exists [resource -> resource identifier] +import re +from pydantic import BaseModel -def evaluate(json_data, schema_version): - if(schema_version == "3.1"): - current_pos = check_route(json_data, ["resource", "resource_identifier"]) +class Score(BaseModel): + overall: int =0 + F: int = 0 + A: int = 0 + I: int = 0 + R: int = 0 - print(current_pos) +class study_evaluation: + def __init__(self,json_data, schema): + print("TEWESTTS") + self.schema = schema + self.metadata = json_data + self.score = Score() + + -def check_route(json_data, route_keys): - current_position = json_data + def evaluate(self): + print("the schema is: ") + print(self.schema) + if(self.schema == "3.1"): + ###### here will be the list of assessments for schema 3.1 + #check identifier + # + identifier = self.check_route(["resource", "resource_identifier"]) + self.score.F += self.check_identifier(identifier) - for key in route_keys: - if key in current_position: - current_position = current_position[key] - else: - #if a key is missing return false - return False - #if the route exists return the value - return current_position \ No newline at end of file + ###### + print(self.score) + return self.score + + def check_route(self, route_keys): + current_position = self.metadata + + for key in route_keys: + if key in current_position: + current_position = current_position[key] + else: + #if a key is missing return false + return False + #if the route exists return the value + return current_position + + # function to check the identifier for uniqueness and persistancy + def check_identifier(self, identifier): + if(self.is_doi(identifier)): + return 1 + elif(identifier.startswith("DRKS")): + return 1 + + @staticmethod + def is_doi(doi): + doi_pattern = r'^10\.\d{4,9}/[-._;()/:A-Z0-9]+$' + # Use the re.match function to check if the string matches the pattern + return bool(re.match(doi_pattern, doi)) \ No newline at end of file diff --git a/app/routers/csh_router.py b/app/routers/csh_router.py index 7e102b0..d402908 100644 --- a/app/routers/csh_router.py +++ b/app/routers/csh_router.py @@ -1,6 +1,6 @@ from fastapi import APIRouter import json -from app.models.csh import evaluate +from app.models.csh import study_evaluation, Score csh_router = APIRouter() @@ -9,7 +9,7 @@ @csh_router.get("/csh/study", tags=["Study"]) -def csh_study() -> str: #metadata, schema_version +def csh_study() -> Score: #metadata, schema_version """ **Parameters:** - *metadata*: json containing the metadata of a CSH entry @@ -25,13 +25,20 @@ def csh_study() -> str: #metadata, schema_version json_data = json.load(json_file) - print(json_data) + #print(json_data) ####----------------#### schema_version = "3.1" - evaluate(json_data, schema_version) + evaluation = study_evaluation(json_data, schema_version) - return "checkiiii" + score: Score + score = evaluation.evaluate() + + print("!") + print(evaluation.score) + print(score) + print("?") + return score print("Checki-di-check-check") \ No newline at end of file