@@ -106,26 +106,35 @@ def parse_jobs_from_data(data):
106106
107107def print_job_summary (parsed_jobs ):
108108 success_jobs = [job for job in parsed_jobs if job ['conclusion' ] == 'success' ]
109- print (f"A total of { len (parsed_jobs )} tasks were parsed, among which { len (success_jobs )} tasks were successful (success)\n " )
109+ # Sort by total elapsed time (seconds) in descending order,
110+ # handling potential None values (treat None as 0 and place them at the end).
111+ success_jobs_sorted = sorted (
112+ success_jobs ,
113+ key = lambda x : x ['total_duration_seconds' ] or 0 ,
114+ reverse = True
115+ )
116+
117+ print (
118+ f"A total of { len (parsed_jobs )} tasks were parsed, among which { len (success_jobs_sorted )} tasks were successful (success)\n " )
110119
111120 job_table_data = []
112121 headers = ["Sequence Number" , "Job Name" , "Job ID" , "CONCLUSION" , "STARTED_AT" ,
113122 "Total Duration (Seconds)" , "Total Duration (Minutes)" , "Expected" ]
114123
115- for i , job in enumerate (success_jobs , 1 ):
116- remainder = job ['total_duration_minutes' ] % 20
117- cost = (math .ceil (job ['total_duration_minutes' ] / 20 ) + 1 ) * 20 if remainder >= 10 else \
118- (math .ceil (job ['total_duration_minutes' ] / 20 )) * 20
124+ for i , job in enumerate (success_jobs_sorted , 1 ):
125+ remainder = job ['total_duration_minutes' ] % 20 if job [ 'total_duration_minutes' ] is not None else 0
126+ expectedCost = (math .ceil (job ['total_duration_minutes' ] / 20 ) + 1 ) * 20 if remainder >= 10 else \
127+ (math .ceil (job ['total_duration_minutes' ] / 20 )) * 20 if job [ 'total_duration_minutes' ] is not None else None
119128 job_table_data .append ([
120- i , job ['name' ], job ['job_id' ], job ['conclusion' ],job ['started_at' ],
121- job ['total_duration_seconds' ], job ['total_duration_minutes' ], cost
129+ i , job ['name' ], job ['job_id' ], job ['conclusion' ], job ['started_at' ],
130+ job ['total_duration_seconds' ], job ['total_duration_minutes' ], expectedCost
122131 ])
123132
124133 print ("Overview of the Task:" )
125134 print (tabulate (job_table_data , headers = headers , tablefmt = "pipe" ))
126135 print ()
127136
128- for i , job in enumerate (success_jobs , 1 ):
137+ for i , job in enumerate (success_jobs_sorted , 1 ):
129138 print (f"\n Task { i } : The 3 steps with the longest duration for { job ['name' ]} :" )
130139 if job ['steps' ]:
131140 sorted_steps = sorted (job ['steps' ], key = lambda x : x ['duration_seconds' ], reverse = True )
@@ -134,7 +143,9 @@ def print_job_summary(parsed_jobs):
134143 [s ['name' ], s ['number' ], s ['status' ], s ['conclusion' ], s ['duration_seconds' ]]
135144 for s in top_steps
136145 ]
137- print (tabulate (step_table_data , headers = ["Step name" , "No" , "Status" , "Conclusion" , "Total Duration (seconds)" ], tablefmt = "pipe" ))
146+ print (tabulate (step_table_data ,
147+ headers = ["Step name" , "No" , "Status" , "Conclusion" , "Total Duration (seconds)" ],
148+ tablefmt = "pipe" ))
138149 else :
139150 print ("There is no step information for this task." )
140151 print ("\n " + "-" * 80 )
0 commit comments