Skip to content

Commit

Permalink
first implementation of all indicators for the CSH
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gebhardt authored and Tom Gebhardt committed Jan 9, 2024
1 parent f4da5bc commit 9e160aa
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 320 deletions.
10 changes: 8 additions & 2 deletions app/celery/automated_tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from .f1_model_persistent_identifier_task import f1_model_persistent_identifier
from .f4_model_metadata_harvestable_task import f4_model_metadata_harvestable
from .csh_fair import csh_f1_2_globally_unique_identifier, csh_a1_contains_access_information
from .csh_fair import csh_f1_2_globally_unique_identifier, csh_a1_contains_access_information, csh_i3_01_ref_other_metadata, csh_i3_02_ref_other_data, csh_i3_03_qual_ref_other_metadata, csh_i3_04_qual_ref_other_data, csh_r1_1_01_has_reuse_license, csh_r1_1_02_has_standard_reuse_license



__all__ = [
f1_model_persistent_identifier,
f4_model_metadata_harvestable,
csh_f1_2_globally_unique_identifier,
csh_a1_contains_access_information
csh_a1_contains_access_information,
csh_i3_01_ref_other_metadata,
csh_i3_02_ref_other_data,
csh_i3_03_qual_ref_other_metadata,
csh_i3_04_qual_ref_other_data,
csh_r1_1_01_has_reuse_license,
csh_r1_1_02_has_standard_reuse_license
]
118 changes: 106 additions & 12 deletions app/celery/automated_tasks/csh_fair.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

config = get_settings()

def is_doi(identifier):
def is_doi(identifier: str):
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, identifier))
print("identifier: ", identifier)
match = re.match(doi_pattern, identifier)
print("?? match")
print("doi match: ", match)
return False
#return bool(re.match(doi_pattern, identifier))



Expand Down Expand Up @@ -49,13 +54,9 @@ def incoperate_results(task_dict: dict, result: 'app.models.TaskStatus', test: b
# Works, but does not trigger updating of children
# redis_app.json().set(f"session:{session_id}", f".tasks.{task_id}.status", obj=result)



@app.task
def csh_f1_2_globally_unique_identifier(
task_dict: dict, data: dict, test: bool = False
):
print("f1_2_glob")
def csh_f1_2_globally_unique_identifier(task_dict: dict, data: dict, test: bool = False):
print(" ")
"""
Representation of celery task to evaluate an assessment.
These celery tasks should be in the format:
Expand All @@ -80,15 +81,18 @@ def assessment_task(task_dict: dict, data: dict) -> None:


identifier = check_route(data, ["resource", "resource_identifier"])

print("grabbed identifier: ", identifier)
#could also retrive "type" from data instead of using .startswith

if(is_doi(identifier)):
if(identifier is False):
result = "failed"
elif(is_doi(identifier)):
result = "success"
elif(identifier.startswith("DRKS")):
result = "success"
else:
result = "failed"

print("!!!!!!!!!!!!! ---- ", result)

incoperate_results(task_dict, result, test)

Expand Down Expand Up @@ -153,4 +157,94 @@ def csh_a1_contains_access_information(task_dict: dict, data: dict, test: bool =
else:
result = "failed"

incoperate_results(task_dict, result, test)
incoperate_results(task_dict, result, test)
print("working?")

@app.task
def csh_i3_01_ref_other_metadata(task_dict: dict, data: dict, test: bool = False):
#check if other metadata is referenced
ref_resources = check_route(data, ["resource", "ids"])
print("INFO - csh-i3-01")
result = "not_applicable"
if(ref_resources != False):
print("IDs: ", ref_resources, type(ref_resources))
for res in ref_resources:
print(res, type(res))
print(res.get('typeGeneral'))
if(res.get('typeGeneral') != 'Dataset'):
result = "success"
incoperate_results(task_dict, result, test)

@app.task
def csh_i3_02_ref_other_data(task_dict: dict, data: dict, test: bool = False):
#check if other data is referenced
ref_resources = check_route(data, ["resource", "ids"])
print("INFO - csh-i3-02")
result = "not_applicable"
if(ref_resources != False):
for res in ref_resources:
print(res)
print(res.get('typeGeneral'))
if(res.get('typeGeneral') == 'Dataset'):
result = "success"
incoperate_results(task_dict, result, test)

@app.task
def csh_i3_03_qual_ref_other_metadata(task_dict: dict, data: dict, test: bool = False):
#check if other metadata is referenced
ref_resources = check_route(data, ["resource", "ids"])
print("INFO - csh-i3-03")
result = "not_applicable"
if(ref_resources != False):
for res in ref_resources:
if(res.get('typeGeneral') != 'Dataset'):
#set to fail if ONE refed metadata has no relationType
if(result == "not_applicable"):
result = "success"
if(res.get('relationType') == None):
result = "failed"
incoperate_results(task_dict, result, test)

@app.task
def csh_i3_04_qual_ref_other_data(task_dict: dict, data: dict, test: bool = False):
#check if other data is referenced
ref_resources = check_route(data, ["resource", "ids"])
print("INFO - csh-i3-04")
result = "not_applicable"
if(ref_resources != False):
for res in ref_resources:
if(res.get('typeGeneral') == 'Dataset'):
#set to fail if ONE refed metadata has no relationType
if(result == "not_applicable"):
result = "success"
if(res.get('relationType') == None):
result = "failed"
incoperate_results(task_dict, result, test)

##### Reusability
@app.task
def csh_r1_1_01_has_reuse_license(task_dict: dict, data: dict, test: bool = False):
resource_type = check_route(data, ["resource", "classification", "type"])
if(resource_type == False): resource_type = check_route(data, ["resource", "resource_classification", "resource_type"])
if(resource_type in ["Study", "Substudy/Data collection event"]):
result = "warning" #TODO: Ask others to specify how this can be checked
else:
license_info = check_route(data, ["resource", "nonStudyDetails", "useRights"])
if(license_info != False):
result = "success"
else:
result = "failed"
incoperate_results(task_dict, result, test)

@app.task #TODO: verify if this automated task really works since it depends on a parent task
def csh_r1_1_02_has_standard_reuse_license(task_dict: dict, data: dict, test: bool = False):
#check if userights label is a fitting license
license_label = check_route(data,["resource", "nonStudyDetails", "nonStudyDetails", "useRights"])
if(license_label in ["Creative Commons Zero v1.0 Universal", "Creative Commons Attribution 4.0 International", "Creative Commons Attribution Non Commercial 4.0 International", "Creative Commons Attribution Share Alike 4.0 International", "Creative Commons Attribution Non Commercial Share Alike 4.0 International"]):
result = "success"
elif(license_label == "Other"):
result = "warning"
else:
result = "failed"
incoperate_results(task_dict, result, test)

3 changes: 1 addition & 2 deletions app/celery/automated_tasks/csh_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

def check_route(metadata, route_keys):
current_position = json.loads(metadata)

for key in route_keys:
if key in current_position:

current_position = current_position[key]
else:
print("the key {} form the route{} is not in the dict".format(key, route_keys), )
#if a key is missing return false
return False
#if the route exists return the value
Expand Down
13 changes: 7 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
tags_metadata = [
{
"name": "Indicators",
"description": "FAIR Combine assessments. Endpoints to retrieve the descriptions of the assessments done by "
"description": "FAIR assessments. Endpoints to retrieve the descriptions of the assessments done by "
"the application "
"to evaluate how FAIR a resource is/",
},
Expand All @@ -29,22 +29,23 @@
]

description = """
FAIR Combine is a web application designed to help users assess how FAIR their
their Combine resources are.
FAIR Eval is a web application designed to help users assess how FAIR their
their scientific resources are. Currently supported are FAIR Combine and CSH resources.
Users may submit their Combine model, and the application will create a list
of assessments following the FAIR principle. Some of these assessments will run
in the background while others will need to be filled by the users.
Users may also make API requests to evalutate the metadata of a CSH resource.
Once all assessments are completed, the application returns a set of scores
describing how FAIR their model is.
describing how FAIR their resource is.
"""


app = FastAPI(
title="FAIR Combine API",
title="FAIR Eval API",
description=description,
version="0.0.1",
version="0.1.0",
openapi_tags=tags_metadata,
lifespan=get_tasks_definitions,
)
Expand Down
17 changes: 16 additions & 1 deletion app/metrics/metrics.csv
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,19 @@
"CSH-RDA-A1-03M","Essential","Metadata identifier resolves to a metadata record","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-A1-04M","Essential","Metadata is accessed through standardised protocol","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-A1.1-01M","Essential","Metadata is accessible through a free access protocol","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-A2-01M","Essential","Metadata is guaranteed to remain available after data is no longer available","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-A2-01M","Essential","Metadata is guaranteed to remain available after data is no longer available","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I1-01M","Important","Metadata uses knowledge representation expressed in standardised format","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I1-02M","Important","Metadata uses machine-understandable knowledge representation","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I2-01M","Important","Metadata uses FAIR-compliant vocabularies","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I3-01M","Important","Metadata includes references to other metadata","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I3-02M","Useful","Metadata includes references to other data","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I3-03M","Important","Metadata includes qualified references to other metadata","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-I3-04M","Useful","Metadata includes qualified references to other data","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1-01M","Essential","Plurality of accurate and relevant attributes are provided to allow reuse","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.1-01M","Essential","Metadata includes information about the licence under which the data can be reused","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.1-02M","Important","Metadata refers to a standard reuse licence","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.1-03M","Important","Metadata refers to a machine-understandable reuse licence","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.2-01M","Important","Metadata includes provenance information according to community-specific standards","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.2-02M","Useful","Metadata includes provenance information according to a cross-community language","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.3-01M","Essential","Metadata complies with a community standard","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
"CSH-RDA-R1.3-02M","Essential","Metadata is expressed in compliance with a machine-understandable community standard","---Add a description about the indicator (probably adapt from RDA schema)---","Add an explanation on how this indicator is technically evaluated"
Loading

0 comments on commit 9e160aa

Please sign in to comment.