1212
1313class FAIROS :
1414
15+ EQUIVALENT_TESTS = {
16+ "IDENTIFIER_PERSISTENCE" : [
17+ "FUJI-F1-01" ,
18+ "ROCRATE-F1-01"
19+ ],
20+ "MINIMUM_METADATA" : [
21+ "FUJI-F2-01" ,
22+ "FUJI-F2-02" ,
23+ "ROCRATE-F2-01"
24+ ],
25+ "DATA_LINKAGE" : [
26+ "FUJI-F3-01" ,
27+ "ROCRATE-F3-01"
28+ ],
29+ "SCHEMA_OR_SEMANTIC_CONTEXT" : [
30+ "FUJI-I2-01" ,
31+ "ROCRATE-I2-01"
32+ ]
33+ }
34+
35+ def _compute_equivalent_results (test_results ):
36+ grouped = {}
37+ used_test_ids = set ()
38+
39+ # Evaluate declared equivalence groups
40+ for group_name , equivalent_ids in FAIROS .EQUIVALENT_TESTS .items ():
41+ matching_tests = [
42+ test for test in test_results
43+ if test .get ("outputFromTest" , {}).get ("@id" , "" ).split ("/" )[- 1 ] in equivalent_ids
44+ ]
45+
46+ if matching_tests :
47+ group_pass = any (test .get ("value" ) == "PASS" for test in matching_tests )
48+ grouped [group_name ] = {
49+ "tests" : [
50+ {
51+ "test_id" : test .get ("outputFromTest" , {}).get ("@id" , "" ).split ("/" )[- 1 ],
52+ "value" : test .get ("value" )
53+ }
54+ for test in matching_tests
55+ ],
56+ "value" : "PASS" if group_pass else "FAIL"
57+ }
58+ used_test_ids .update (
59+ test .get ("outputFromTest" , {}).get ("@id" , "" ).split ("/" )[- 1 ]
60+ for test in matching_tests
61+ )
62+
63+ # Keep non-equivalent tests as independent checks
64+ for test in test_results :
65+ test_id = test .get ("outputFromTest" , {}).get ("@id" , "" ).split ("/" )[- 1 ]
66+ if test_id not in used_test_ids :
67+ grouped [test_id ] = {
68+ "tests" : [
69+ {
70+ "test_id" : test_id ,
71+ "value" : test .get ("value" )
72+ }
73+ ],
74+ "value" : test .get ("value" )
75+ }
76+
77+ total = len (grouped )
78+ passed = sum (1 for item in grouped .values () if item ["value" ] == "PASS" )
79+ percentage = (passed / total ) * 100 if total else 0.0
80+
81+ return {
82+ "grouped_results" : grouped ,
83+ "passed" : passed ,
84+ "total" : total ,
85+ "percentage" : percentage
86+ }
1587
1688 def execute_algorithm (rocrate_filename , ticket ):
1789 # Current UTC time
@@ -69,21 +141,19 @@ def execute_algorithm(rocrate_filename, ticket):
69141 result_testset = dataset .execute_algorithm (element , ticket )
70142 doc ["hadMember" ] = doc ["hadMember" ]+ result_testset ["hadMember" ]
71143
72- percentage = 0
73- total = len (result_testset ["hadMember" ])
74- if total != 0 :
75- passed = sum (
76- 1 for test in result_testset ["hadMember" ]
77- if test .get ("value" ) == "PASS"
78- )
79- percentage = (passed / total ) * 100
144+ equivalent_result = FAIROS ._compute_equivalent_results (result_testset ["hadMember" ])
145+
146+ percentage = equivalent_result ["percentage" ]
147+ passed = equivalent_result ["passed" ]
148+ total = equivalent_result ["total" ]
80149
81150 percentages .append (percentage )
82151 log_entries .append ({
83152 "@id" : id ,
84- "passed" : passed if total != 0 else 0 ,
153+ "passed" : passed ,
85154 "total" : total ,
86- "percentage" : percentage
155+ "percentage" : percentage ,
156+ "grouped_results" : equivalent_result ["grouped_results" ]
87157 })
88158
89159 if percentages :
@@ -96,7 +166,7 @@ def execute_algorithm(rocrate_filename, ticket):
96166 logger .info ("Generating file assessment-results-" + str (ticket ))
97167
98168 # Write the JSON-LD to a file
99- output_file_results = f"C:\\ Users\\ egonzalez\\ tests_results \\ assessment-results-{ ticket } .jsonld"
169+ output_file_results = f"C:\\ Users\\ egonzalez\\ FAIROS \\ assessments \\ assessment-results-{ ticket } .jsonld"
100170 with open (output_file_results , "w" , encoding = "utf-8" ) as f :
101171 json .dump (doc , f , ensure_ascii = False , indent = 2 )
102172
@@ -110,7 +180,7 @@ def execute_algorithm(rocrate_filename, ticket):
110180 }
111181
112182 # Write the JSON-LD to a file
113- output_file_score = f"C:\\ Users\\ egonzalez\\ tests_results \\ score-{ ticket } .jsonld"
183+ output_file_score = f"C:\\ Users\\ egonzalez\\ FAIROS \\ scores \\ score-{ ticket } .jsonld"
114184 with open (output_file_score , "w" , encoding = "utf-8" ) as f :
115185 json .dump (score , f , ensure_ascii = False , indent = 2 )
116186
0 commit comments