Skip to content

Commit

Permalink
Merge branch 'dev-reliance'
Browse files Browse the repository at this point in the history
  • Loading branch information
esgg committed Apr 3, 2023
2 parents b0b59db + cbb924f commit 4b5e12a
Show file tree
Hide file tree
Showing 30 changed files with 2,262 additions and 386 deletions.
114 changes: 87 additions & 27 deletions code/FAIROs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from rocrate.rocrate import ROCrate
from rocrate_fairness.ro_fairness import ROCrateFAIRnessCalculator
from fuji_wrapper.fujiwrapper import FujiWrapper
<<<<<<<< HEAD:code/FAIROs.py
from somefFAIR.somefFAIR import SoftwareFAIRnessCalculator
========
from somef_wrapper.somefFAIR import SoftwareFAIRnessCalculator
>>>>>>>> dev-reliance:code/fair_assessment/full_ro_fairness.py
from foops_wrapper.foopswrapper import FoopsWrapper
import json
import validators
Expand Down Expand Up @@ -31,17 +35,43 @@ def create_component_output(self, name, identifier, type, tool_used, info=""):
"name": name,
"identifier": identifier,
"type": type,
"tool-used": tool_used,
"tool-used": [tool_used],
}
if info:
element["information"] = info
element["checks"] = []
return element

def evaluate_ro(self):

name = self.ro["title"]
identifier = self.ro["identifier"]
identifier_rocrate = self.ro["@id"]

element = self.create_component_output(
name, identifier, "ro-crate", "ro-crate-FAIR"
)

if validators.url(identifier):
fuji = FujiWrapper(identifier)

component = self.__build_component(
element["name"] if "name" in element else None,
fuji.get_identifier(),
"ro-crate",
"F-uji",
fuji.get_checks(),
)

self.__add_ro_metadata_checks(component, identifier_rocrate)


self.output["components"].append(component)

def extract_ro(self):
ro_output = self.ro_calculator.calculate_fairness()
name = ro_output["rocrate_path"]
identifier = self.ro_calculator.get_identifier()
name = self.ro["title"]
identifier = self.ro["identifier"]

element = self.create_component_output(
name, identifier, "ro-crate", "ro-crate-FAIR"
Expand All @@ -52,11 +82,25 @@ def extract_ro(self):
self.output["components"].append(element)

def __add_ro_metadata_checks(self, element, element_id):
element["tool-used"] += " + ro-metadata"
extra_checks = self.ro_calculator.get_element_basic_checks(element_id)

for ec in extra_checks:
element["checks"].append(ec)
#todo create urls for describing the terms of tools used
element["tool-used"].append("ro-crate-metadata")
for test in element["checks"]:
if test["status"]=="fail":
fuji_score = test["sources"][0]["score"]
extra_checks = self.ro_calculator.rocrate_principle_check(element_id,test["principle_id"])
test["sources"].append(extra_checks)
if "score" in extra_checks:
if fuji_score > extra_checks["score"]:
test["score"] = fuji_score
else:
test["score"] = extra_checks["score"]
test["total_score"] = extra_checks["total_score"]
if "assessment" in extra_checks and extra_checks["assessment"] == "pass":
test["status"] = "ok"
#extra_checks = self.ro_calculator.get_element_basic_checks(element_id)

#for ec in extra_checks:
#element["checks"].append(ec)

def __build_component(self, name, identifier, type, tool_used, checks, info=""):
element = self.create_component_output(name, identifier, type, tool_used, info)
Expand All @@ -69,13 +113,27 @@ def __generate_overall_score(self, aggregation_mode):
"score" : 0
}

score = 0.0
total_score = 0.0

for component in self.output["components"]:
for check in component["checks"]:
if "score" in check and "total_score" in check:
score += check["score"]
total_score += check["total_score"]

overall_score["score"] = round((score / total_score) * 100,2)

"""
if aggregation_mode == 0:
description = "The score is calculated by adding all the scores of the different components together. All passed tests and all total tests are added together and then the percentage is calculated"
passed, total = 0, 0
for component in self.output["components"]:
for check in component["checks"]:
passed += check["total_passed_tests"]
total += check["total_tests_run"]
#passed += check["total_passed_tests"]
#total += check["total_tests_run"]
passed += 1
total += 1
overall_score["score"] = round((passed / total)*100, 2)
overall_score["total_sum"] = {"total_passed_tests" : passed, "total_run_tests": total}
Expand All @@ -90,13 +148,13 @@ def __generate_overall_score(self, aggregation_mode):
principles_scores.append(round((score_category["tests_passed"] / score_category["total_tests"]) * 100 , 2))
component_scores.append(round(sum(principles_scores)/len(principles_scores),2))
overall_score["score"] = round(sum(component_scores)/len(component_scores),2)

overall_score["description"] = description
"""
overall_score["description"] = "Formula: score of each principle / total score"
self.output["overall_score"] = overall_score

def __generate_partial_scores(self):
for component in self.output["components"]:
tmp = {"tests_passed": 0, "total_tests": 0}
tmp = {"tests_passed": 0, "total_tests": 0, "score": 0, "total_score":0}
score = {
"Findable": dict(tmp),
"Accessible": dict(tmp),
Expand All @@ -106,8 +164,12 @@ def __generate_partial_scores(self):

for check in component["checks"]:
cat = check["category_id"]
score[cat]["tests_passed"] += check["total_passed_tests"]
score[cat]["total_tests"] += check["total_tests_run"]
if "sources" in check and all(key in check["sources"][0] for key in ('assessment', 'score','total_score')):
#score[cat]["tests_passed"] += 1 if check["sources"][0]["assessment"] == "pass" else 0
#score[cat]["total_tests"] += 1
if "score" in check and "total_score" in check:
score[cat]["score"] += check["score"]
score[cat]["total_score"] += check["total_score"]
component["score"] = score

def __evaluate_dataset(self, element, evaluate_ro_metadata):
Expand All @@ -122,8 +184,8 @@ def __evaluate_dataset(self, element, evaluate_ro_metadata):
fuji.get_checks(),
)

if evaluate_ro_metadata:
self.__add_ro_metadata_checks(component, element["@id"])

self.__add_ro_metadata_checks(component, element["@id"])

self.output["components"].append(component)

Expand Down Expand Up @@ -226,23 +288,21 @@ def __evaluate_other(self, element, evaluate_ro_metadata):
def __calculate_fairness(self, evaluate_ro_metadata, aggregation_mode):
self.output["components"] = []

self.extract_ro()
self.evaluate_ro()

for element in self.ro_parts:

type = element["@type"]

if type == "Dataset":
type = element["@type"]
if "Dataset" in type and not "http://purl.org/wf4ever/wf4ever#Folder" in type:
self.__evaluate_dataset(element, evaluate_ro_metadata)

elif type == "SoftwareApplication":
self.__evaluate_software_application(element, evaluate_ro_metadata)

elif type == "Ontology":
self.__evaluate_ontology(element, evaluate_ro_metadata)

else:
self.__evaluate_other(element, evaluate_ro_metadata)
elif "File" in type:
self.__evaluate_dataset(element, evaluate_ro_metadata)


self.__generate_partial_scores()
Expand All @@ -254,8 +314,8 @@ def calculate_fairness(self, evaluate_ro_metadata, aggregation_mode, output_name
self.__calculate_fairness(evaluate_ro_metadata, aggregation_mode)
self.save_to_file(output_name)

if show_diagram:
visualizer.generate_visual_graph(output_name)
#if show_diagram:
# visualizer.generate_visual_graph(output_name)


def parse_boolean(value):
Expand Down
Loading

0 comments on commit 4b5e12a

Please sign in to comment.