55import subprocess
66import sys
77import warnings
8- from datetime import timezone
8+ from datetime import datetime , timezone
99from enum import Enum
1010from typing import (
1111 Callable ,
@@ -817,42 +817,43 @@ def _record_driver_timing(
817817 stdout_style = self .stdout_style , _scratch = self .scratch
818818 )
819819
820- def _try_asutc (dt_or_none ) :
820+ def _try_asutc (dt_or_none : Optional [ datetime ]) -> Optional [ datetime ] :
821821 if dt_or_none :
822822 return dt_or_none .astimezone (tz = timezone .utc )
823823 return None
824824
825+ # column names
826+ D_CLASS = "Driver Class"
827+ D_NAME = "Driver Name"
828+ START_TIME = "Start Time (UTC)"
829+ END_TIME = "Stop Time (UTC)"
830+ DURATION = "Duration(seconds)"
831+
825832 # input for tablelog
826833 table = [
827834 {
828- "Driver Class" : driver .__class__ .__name__ ,
829- "Driver Name" : driver .name ,
830- "Start Time (UTC)" : _try_asutc (
835+ D_CLASS : driver .__class__ .__name__ ,
836+ D_NAME : driver .name ,
837+ START_TIME : _try_asutc (
831838 driver .timer .last (setup_or_teardown ).start
832839 ),
833- "Stop Time (UTC)" : _try_asutc (
834- driver .timer .last (setup_or_teardown ).end
835- ),
836- "Duration(seconds)" : driver .timer .last (
837- setup_or_teardown
838- ).elapsed ,
840+ END_TIME : _try_asutc (driver .timer .last (setup_or_teardown ).end ),
841+ DURATION : driver .timer .last (setup_or_teardown ).elapsed ,
839842 }
840843 for driver in self .resources
841844 if setup_or_teardown in driver .timer .keys ()
842845 ]
843- table .sort (key = lambda entry : entry ["Start Time (UTC)" ])
846+ table .sort (key = lambda entry : entry [START_TIME ])
844847
845848 def _format_start_stop_time (d ):
846849 # format tablelog entries to be human readable
847- if d ["Start Time (UTC)" ]:
848- d ["Start Time (UTC)" ] = d ["Start Time (UTC)" ].strftime (
849- "%H:%M:%S.%f"
850- )
851- if d ["Stop Time (UTC)" ]:
852- d ["Stop Time (UTC)" ] = d ["Stop Time (UTC)" ].strftime (
853- "%H:%M:%S.%f"
854- )
855- return d
850+ st = (
851+ d [START_TIME ].strftime ("%H:%M:%S.%f" )
852+ if d [START_TIME ]
853+ else None
854+ )
855+ et = d [END_TIME ].strftime ("%H:%M:%S.%f" ) if d [END_TIME ] else None
856+ return {** d , START_TIME : st , END_TIME : et }
856857
857858 case_result .table .log (
858859 [_format_start_stop_time (d ) for d in table ],
@@ -870,32 +871,28 @@ def _format_start_stop_time(d):
870871 else :
871872 # input for plotly
872873 px_input = {
873- "Start Time (UTC)" : [],
874- "Stop Time (UTC)" : [],
875- "Driver Name" : [],
874+ D_NAME : [],
875+ START_TIME : [],
876+ END_TIME : [],
876877 }
877878 for driver in table :
878- if driver ["Stop Time (UTC)" ]:
879- px_input ["Driver Name" ].append (driver ["Driver Name" ])
880- px_input ["Start Time (UTC)" ].append (
881- driver ["Start Time (UTC)" ]
882- )
883- px_input ["Stop Time (UTC)" ].append (
884- driver ["Stop Time (UTC)" ]
885- )
879+ if driver [END_TIME ]:
880+ px_input [D_NAME ].append (driver [D_NAME ])
881+ px_input [START_TIME ].append (driver [START_TIME ])
882+ px_input [END_TIME ].append (driver [END_TIME ])
886883
887884 # empirical values
888885 padding = 150
889886 row_size = 25
890- height = padding + row_size * len (px_input ["Driver Name" ])
887+ height = padding + row_size * len (px_input [D_NAME ])
891888 if height == padding :
892889 # min height
893890 height = padding + row_size
894891 fig = px .timeline (
895892 px_input ,
896- x_start = "Start Time (UTC)" ,
897- x_end = "Stop Time (UTC)" ,
898- y = "Driver Name" ,
893+ x_start = START_TIME ,
894+ x_end = END_TIME ,
895+ y = D_NAME ,
899896 height = height ,
900897 )
901898 fig .update_yaxes (autorange = "reversed" , automargin = True )
0 commit comments