1313from osivalidator .osi_trace import OSITrace
1414from osivalidator .osi_rules_checker import OSIRulesChecker
1515
16+
1617def check_positive_int (value ):
1718 ivalue = int (value )
1819 if ivalue < 0 :
1920 raise argparse .ArgumentTypeError ("%s is an invalid positive int value" % value )
2021 return ivalue
2122
23+
2224def command_line_arguments ():
2325 """ Define and handle command line interface """
2426
2527 dir_path = os .path .dirname (os .path .dirname (os .path .realpath (__file__ )))
2628
2729 parser = argparse .ArgumentParser (
28- description = 'Validate data defined at the input' ,
29- prog = 'osivalidator' )
30- parser .add_argument ('data' ,
31- help = 'Path to the file with OSI-serialized data.' ,
32- type = str )
33- parser .add_argument ('--rules' , '-r' ,
34- help = 'Directory with text files containig rules. ' ,
35- default = os .path .join (dir_path , 'requirements-osi-3' ),
36- type = str )
37- parser .add_argument ('--type' , '-t' ,
38- help = 'Name of the type used to serialize data.' ,
39- choices = ['SensorView' , 'GroundTruth' , 'SensorData' ],
40- default = 'SensorView' ,
41- type = str ,
42- required = False )
43- parser .add_argument ('--output' , '-o' ,
44- help = 'Output folder of the log files.' ,
45- default = 'output_logs' ,
46- type = str ,
47- required = False )
48- parser .add_argument ('--timesteps' ,
49- help = 'Number of timesteps to analyze. If -1, all.' ,
50- type = int ,
51- default = - 1 ,
52- required = False )
53- parser .add_argument ('--debug' ,
54- help = 'Set the debug mode to ON.' ,
55- action = "store_true" )
56- parser .add_argument ('--verbose' , '-v' ,
57- help = 'Set the verbose mode to ON.' ,
58- action = "store_true" )
59- parser .add_argument ('--parallel' , '-p' ,
60- help = 'Set parallel mode to ON.' ,
61- default = False ,
62- required = False ,
63- action = "store_true" )
64- parser .add_argument ('--format' , '-f' ,
65- help = 'Set the format type of the trace.' ,
66- choices = ['separated' , None ],
67- default = None ,
68- type = str ,
69- required = False )
70- parser .add_argument ('--blast' , '-bl' ,
71- help = 'Set the in-memory storage count of OSI messages during validation.' ,
72- default = 500 ,
73- type = check_positive_int ,
74- required = False )
75- parser .add_argument ('--buffer' , '-bu' ,
76- help = 'Set the buffer size to retrieve OSI messages from trace file. Set it to 0 if you do not want to use buffering at all.' ,
77- default = 1000000 ,
78- type = check_positive_int ,
79- required = False )
30+ description = "Validate data defined at the input" , prog = "osivalidator"
31+ )
32+ parser .add_argument (
33+ "data" , help = "Path to the file with OSI-serialized data." , type = str
34+ )
35+ parser .add_argument (
36+ "--rules" ,
37+ "-r" ,
38+ help = "Directory with text files containig rules. " ,
39+ default = os .path .join (dir_path , "requirements-osi-3" ),
40+ type = str ,
41+ )
42+ parser .add_argument (
43+ "--type" ,
44+ "-t" ,
45+ help = "Name of the type used to serialize data." ,
46+ choices = ["SensorView" , "GroundTruth" , "SensorData" ],
47+ default = "SensorView" ,
48+ type = str ,
49+ required = False ,
50+ )
51+ parser .add_argument (
52+ "--output" ,
53+ "-o" ,
54+ help = "Output folder of the log files." ,
55+ default = "output_logs" ,
56+ type = str ,
57+ required = False ,
58+ )
59+ parser .add_argument (
60+ "--timesteps" ,
61+ help = "Number of timesteps to analyze. If -1, all." ,
62+ type = int ,
63+ default = - 1 ,
64+ required = False ,
65+ )
66+ parser .add_argument (
67+ "--debug" , help = "Set the debug mode to ON." , action = "store_true"
68+ )
69+ parser .add_argument (
70+ "--verbose" , "-v" , help = "Set the verbose mode to ON." , action = "store_true"
71+ )
72+ parser .add_argument (
73+ "--parallel" ,
74+ "-p" ,
75+ help = "Set parallel mode to ON." ,
76+ default = False ,
77+ required = False ,
78+ action = "store_true" ,
79+ )
80+ parser .add_argument (
81+ "--format" ,
82+ "-f" ,
83+ help = "Set the format type of the trace." ,
84+ choices = ["separated" , None ],
85+ default = None ,
86+ type = str ,
87+ required = False ,
88+ )
89+ parser .add_argument (
90+ "--blast" ,
91+ "-bl" ,
92+ help = "Set the in-memory storage count of OSI messages during validation." ,
93+ default = 500 ,
94+ type = check_positive_int ,
95+ required = False ,
96+ )
97+ parser .add_argument (
98+ "--buffer" ,
99+ "-bu" ,
100+ help = "Set the buffer size to retrieve OSI messages from trace file. Set it to 0 if you do not want to use buffering at all." ,
101+ default = 1000000 ,
102+ type = check_positive_int ,
103+ required = False ,
104+ )
80105
81106 return parser .parse_args ()
82107
@@ -88,10 +113,11 @@ def command_line_arguments():
88113LOGGER = OSIValidatorLogger ()
89114VALIDATION_RULES = OSIRules ()
90115ID_TO_TS = MANAGER .dict ()
91- BAR_SUFFIX = ' %(index)d/%(max)d [%(elapsed_td)s]'
92- BAR = Bar ('' , suffix = BAR_SUFFIX )
116+ BAR_SUFFIX = " %(index)d/%(max)d [%(elapsed_td)s]"
117+ BAR = Bar ("" , suffix = BAR_SUFFIX )
93118MESSAGE_CACHE = MANAGER .dict ()
94119
120+
95121def main ():
96122 """Main method"""
97123
@@ -112,7 +138,12 @@ def main():
112138 # Read data
113139 print ("Reading data ..." )
114140 DATA = OSITrace (buffer_size = args .buffer )
115- DATA .from_file (path = args .data , type_name = args .type , max_index = args .timesteps , format_type = args .format )
141+ DATA .from_file (
142+ path = args .data ,
143+ type_name = args .type ,
144+ max_index = args .timesteps ,
145+ format_type = args .format ,
146+ )
116147
117148 # Collect Validation Rules
118149 print ("Collect validation rules ..." )
@@ -138,7 +169,7 @@ def main():
138169
139170 # Increment the max-timestep to analyze
140171 max_timestep_blast += args .blast
141- first_of_blast = ( max_timestep_blast - args .blast )
172+ first_of_blast = max_timestep_blast - args .blast
142173 last_of_blast = min (max_timestep_blast , max_timestep )
143174
144175 # Cache messages
@@ -148,9 +179,9 @@ def main():
148179 if args .parallel :
149180 # Launch parallel computation
150181 # Recreate the pool
151- try :
182+ try :
152183 pool = Pool ()
153- pool .map (process_timestep , range (first_of_blast , last_of_blast ))
184+ pool .map (process_timestep , range (first_of_blast , last_of_blast ))
154185
155186 except Exception as e :
156187 print (str (e ))
@@ -163,7 +194,7 @@ def main():
163194 try :
164195 for i in range (first_of_blast , last_of_blast ):
165196 process_timestep (i )
166-
197+
167198 except Exception as e :
168199 print (str (e ))
169200
@@ -176,6 +207,7 @@ def main():
176207 # Synthetize
177208 LOGGER .synthetize_results_from_sqlite ()
178209
210+
179211def close_pool (pool ):
180212 """Cleanly close a pool to free the memory"""
181213 pool .close ()
@@ -192,7 +224,7 @@ def process_timestep(timestep):
192224
193225 LOGGER .log_messages [timestep ] = []
194226 LOGGER .debug_messages [timestep ] = []
195- LOGGER .info (None , f' Analyze message of timestamp { timestamp } ' , False )
227+ LOGGER .info (None , f" Analyze message of timestamp { timestamp } " , False )
196228
197229 # Check if timestamp already exists
198230 if timestamp in TIMESTAMP_ANALYZED :
@@ -202,8 +234,9 @@ def process_timestep(timestep):
202234 BAR .goto (len (TIMESTAMP_ANALYZED ))
203235
204236 # Check common rules
205- getattr (rule_checker , 'is_valid' )(
206- message , VALIDATION_RULES .get_rules ().get_type (MESSAGE_TYPE .value ))
237+ getattr (rule_checker , "is_valid" )(
238+ message , VALIDATION_RULES .get_rules ().get_type (MESSAGE_TYPE .value )
239+ )
207240
208241 LOGS .extend (LOGGER .log_messages [timestep ])
209242
0 commit comments