55from utils import load
66
77
8+ def remove_in_class (name : str ) -> str :
9+ in_class = "_in_class"
10+ idx = name .find (in_class )
11+ if idx == - 1 :
12+ return name
13+ return name [:idx ] + name [idx :].removeprefix (in_class )
14+
15+
16+ def update_from_counter_name (key_word : str , name : str , labels : dict ) -> str :
17+ if name == f"total_{ key_word } " :
18+ labels ["type" ] = "total"
19+ return key_word
20+ if name .startswith (key_word ):
21+ labels ["type" ] = name .removeprefix (f"{ key_word } _" )
22+ return key_word
23+ return name
24+
25+
26+ def update_from_coverage (name : str , labels : dict ) -> str :
27+ coverage_key = "bytecode_instruction_coverage"
28+ idx = name .find (coverage_key )
29+ if idx == - 1 :
30+ return name
31+ labels ["type" ] = name [:idx - 1 ]
32+ source = name [idx :].removeprefix (f"{ coverage_key } " )
33+ if len (source ) > 0 :
34+ source = source .removeprefix ("_by_" )
35+ if source == "classes" :
36+ labels ["type" ] = "averaged_by_classes"
37+ else :
38+ labels ["source" ] = source
39+ return coverage_key
40+
41+
842def build_metric_struct (name : str , value : any , labels : dict ) -> dict :
43+ name = remove_in_class (name )
44+ name = update_from_counter_name ("classes" , name , labels )
45+ name = update_from_counter_name ("methods" , name , labels )
46+ name = update_from_coverage (name , labels )
47+
48+ name = f"utbot_{ name } "
949 return {
1050 "metric" : name ,
1151 "labels" : labels ,
@@ -22,7 +62,7 @@ def build_metrics_from_data(data: dict, labels: dict) -> List[dict]:
2262 }
2363 metrics = data ["metrics" ]
2464 for metric in metrics :
25- result .append (build_metric_struct (metric , metrics [metric ], new_labels ))
65+ result .append (build_metric_struct (metric , metrics [metric ], new_labels . copy () ))
2666 return result
2767
2868
@@ -86,6 +126,7 @@ def main():
86126 stats = load (args .stats_file )
87127 runner = stats ["metadata" ]["environment" ]["host" ]
88128 metrics = build_metrics_from_targets (stats ["targets" ], runner )
129+ metrics .sort (key = lambda x : x ["metric" ])
89130 with open (args .output_file , "w" ) as f :
90131 json .dump (metrics , f , indent = 4 )
91132
0 commit comments