Skip to content

Commit

Permalink
the new route /csh/study runs now
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gebhardt authored and Tom Gebhardt committed Oct 19, 2023
1 parent 415615f commit fddbf0d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
68 changes: 53 additions & 15 deletions app/models/csh.py
Original file line number Diff line number Diff line change
@@ -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
######
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))
17 changes: 12 additions & 5 deletions app/routers/csh_router.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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
Expand All @@ -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")

0 comments on commit fddbf0d

Please sign in to comment.