11from rocrate .rocrate import ROCrate
22from rocrate_fairness .ro_fairness import ROCrateFAIRnessCalculator
33from fuji_wrapper .fujiwrapper import FujiWrapper
4+ < << << << < HEAD :code / FAIROs .py
45from somefFAIR .somefFAIR import SoftwareFAIRnessCalculator
6+ == == == ==
7+ from somef_wrapper .somefFAIR import SoftwareFAIRnessCalculator
8+ > >> >> >> > dev - reliance :code / fair_assessment / full_ro_fairness .py
59from foops_wrapper .foopswrapper import FoopsWrapper
610import json
711import validators
@@ -31,17 +35,43 @@ def create_component_output(self, name, identifier, type, tool_used, info=""):
3135 "name" : name ,
3236 "identifier" : identifier ,
3337 "type" : type ,
34- "tool-used" : tool_used ,
38+ "tool-used" : [ tool_used ] ,
3539 }
3640 if info :
3741 element ["information" ] = info
3842 element ["checks" ] = []
3943 return element
4044
45+ def evaluate_ro (self ):
46+
47+ name = self .ro ["title" ]
48+ identifier = self .ro ["identifier" ]
49+ identifier_rocrate = self .ro ["@id" ]
50+
51+ element = self .create_component_output (
52+ name , identifier , "ro-crate" , "ro-crate-FAIR"
53+ )
54+
55+ if validators .url (identifier ):
56+ fuji = FujiWrapper (identifier )
57+
58+ component = self .__build_component (
59+ element ["name" ] if "name" in element else None ,
60+ fuji .get_identifier (),
61+ "ro-crate" ,
62+ "F-uji" ,
63+ fuji .get_checks (),
64+ )
65+
66+ self .__add_ro_metadata_checks (component , identifier_rocrate )
67+
68+
69+ self .output ["components" ].append (component )
70+
4171 def extract_ro (self ):
4272 ro_output = self .ro_calculator .calculate_fairness ()
43- name = ro_output [ "rocrate_path " ]
44- identifier = self .ro_calculator . get_identifier ()
73+ name = self . ro [ "title " ]
74+ identifier = self .ro [ "identifier" ]
4575
4676 element = self .create_component_output (
4777 name , identifier , "ro-crate" , "ro-crate-FAIR"
@@ -52,11 +82,25 @@ def extract_ro(self):
5282 self .output ["components" ].append (element )
5383
5484 def __add_ro_metadata_checks (self , element , element_id ):
55- element ["tool-used" ] += " + ro-metadata"
56- extra_checks = self .ro_calculator .get_element_basic_checks (element_id )
57-
58- for ec in extra_checks :
59- element ["checks" ].append (ec )
85+ #todo create urls for describing the terms of tools used
86+ element ["tool-used" ].append ("ro-crate-metadata" )
87+ for test in element ["checks" ]:
88+ if test ["status" ]== "fail" :
89+ fuji_score = test ["sources" ][0 ]["score" ]
90+ extra_checks = self .ro_calculator .rocrate_principle_check (element_id ,test ["principle_id" ])
91+ test ["sources" ].append (extra_checks )
92+ if "score" in extra_checks :
93+ if fuji_score > extra_checks ["score" ]:
94+ test ["score" ] = fuji_score
95+ else :
96+ test ["score" ] = extra_checks ["score" ]
97+ test ["total_score" ] = extra_checks ["total_score" ]
98+ if "assessment" in extra_checks and extra_checks ["assessment" ] == "pass" :
99+ test ["status" ] = "ok"
100+ #extra_checks = self.ro_calculator.get_element_basic_checks(element_id)
101+
102+ #for ec in extra_checks:
103+ #element["checks"].append(ec)
60104
61105 def __build_component (self , name , identifier , type , tool_used , checks , info = "" ):
62106 element = self .create_component_output (name , identifier , type , tool_used , info )
@@ -69,13 +113,27 @@ def __generate_overall_score(self, aggregation_mode):
69113 "score" : 0
70114 }
71115
116+ score = 0.0
117+ total_score = 0.0
118+
119+ for component in self .output ["components" ]:
120+ for check in component ["checks" ]:
121+ if "score" in check and "total_score" in check :
122+ score += check ["score" ]
123+ total_score += check ["total_score" ]
124+
125+ overall_score ["score" ] = round ((score / total_score ) * 100 ,2 )
126+
127+ """
72128 if aggregation_mode == 0:
73129 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"
74130 passed, total = 0, 0
75131 for component in self.output["components"]:
76132 for check in component["checks"]:
77- passed += check ["total_passed_tests" ]
78- total += check ["total_tests_run" ]
133+ #passed += check["total_passed_tests"]
134+ #total += check["total_tests_run"]
135+ passed += 1
136+ total += 1
79137 overall_score["score"] = round((passed / total)*100, 2)
80138 overall_score["total_sum"] = {"total_passed_tests" : passed, "total_run_tests": total}
81139
@@ -90,13 +148,13 @@ def __generate_overall_score(self, aggregation_mode):
90148 principles_scores.append(round((score_category["tests_passed"] / score_category["total_tests"]) * 100 , 2))
91149 component_scores.append(round(sum(principles_scores)/len(principles_scores),2))
92150 overall_score["score"] = round(sum(component_scores)/len(component_scores),2)
93-
94- overall_score ["description" ] = description
151+ """
152+ overall_score ["description" ] = "Formula: score of each principle / total score"
95153 self .output ["overall_score" ] = overall_score
96154
97155 def __generate_partial_scores (self ):
98156 for component in self .output ["components" ]:
99- tmp = {"tests_passed" : 0 , "total_tests" : 0 }
157+ tmp = {"tests_passed" : 0 , "total_tests" : 0 , "score" : 0 , "total_score" : 0 }
100158 score = {
101159 "Findable" : dict (tmp ),
102160 "Accessible" : dict (tmp ),
@@ -106,8 +164,12 @@ def __generate_partial_scores(self):
106164
107165 for check in component ["checks" ]:
108166 cat = check ["category_id" ]
109- score [cat ]["tests_passed" ] += check ["total_passed_tests" ]
110- score [cat ]["total_tests" ] += check ["total_tests_run" ]
167+ if "sources" in check and all (key in check ["sources" ][0 ] for key in ('assessment' , 'score' ,'total_score' )):
168+ #score[cat]["tests_passed"] += 1 if check["sources"][0]["assessment"] == "pass" else 0
169+ #score[cat]["total_tests"] += 1
170+ if "score" in check and "total_score" in check :
171+ score [cat ]["score" ] += check ["score" ]
172+ score [cat ]["total_score" ] += check ["total_score" ]
111173 component ["score" ] = score
112174
113175 def __evaluate_dataset (self , element , evaluate_ro_metadata ):
@@ -122,8 +184,8 @@ def __evaluate_dataset(self, element, evaluate_ro_metadata):
122184 fuji .get_checks (),
123185 )
124186
125- if evaluate_ro_metadata :
126- self .__add_ro_metadata_checks (component , element ["@id" ])
187+
188+ self .__add_ro_metadata_checks (component , element ["@id" ])
127189
128190 self .output ["components" ].append (component )
129191
@@ -226,23 +288,21 @@ def __evaluate_other(self, element, evaluate_ro_metadata):
226288 def __calculate_fairness (self , evaluate_ro_metadata , aggregation_mode ):
227289 self .output ["components" ] = []
228290
229- self .extract_ro ()
291+ self .evaluate_ro ()
230292
231293 for element in self .ro_parts :
232294
233- type = element ["@type" ]
234-
235- if type == "Dataset" :
295+ type = element ["@type" ]
296+ if "Dataset" in type and not "http://purl.org/wf4ever/wf4ever#Folder" in type :
236297 self .__evaluate_dataset (element , evaluate_ro_metadata )
237-
298+
238299 elif type == "SoftwareApplication" :
239300 self .__evaluate_software_application (element , evaluate_ro_metadata )
240301
241302 elif type == "Ontology" :
242303 self .__evaluate_ontology (element , evaluate_ro_metadata )
243-
244- else :
245- self .__evaluate_other (element , evaluate_ro_metadata )
304+ elif "File" in type :
305+ self .__evaluate_dataset (element , evaluate_ro_metadata )
246306
247307
248308 self .__generate_partial_scores ()
@@ -254,8 +314,8 @@ def calculate_fairness(self, evaluate_ro_metadata, aggregation_mode, output_name
254314 self .__calculate_fairness (evaluate_ro_metadata , aggregation_mode )
255315 self .save_to_file (output_name )
256316
257- if show_diagram :
258- visualizer .generate_visual_graph (output_name )
317+ # if show_diagram:
318+ # visualizer.generate_visual_graph(output_name)
259319
260320
261321def parse_boolean (value ):
0 commit comments