From 91bde61a93d1e016ae683ba9255fc7f945c8b2dd Mon Sep 17 00:00:00 2001 From: ClemensLinnhoff Date: Mon, 27 May 2024 18:11:33 +0200 Subject: [PATCH] Add function to automatically detect type from file name Signed-off-by: ClemensLinnhoff --- osivalidator/osi_general_validator.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/osivalidator/osi_general_validator.py b/osivalidator/osi_general_validator.py index d808830..e6a9f25 100755 --- a/osivalidator/osi_general_validator.py +++ b/osivalidator/osi_general_validator.py @@ -53,9 +53,8 @@ def command_line_arguments(): parser.add_argument( "--type", "-t", - help="Name of the type used to serialize data.", + help="Name of the type used to serialize data. Default is SensorView.", choices=["SensorView", "GroundTruth", "SensorData"], - default="SensorView", type=str, required=False, ) @@ -122,12 +121,35 @@ def command_line_arguments(): VALIDATION_RULES = osi_rules.OSIRules() +def detect_message_type(path: str): + """Automatically detect the message type from the file name. + If it cannot be detected, the function return SensorView as default. + + Args: + path (str): Path incl. filename of the trace file + + Returns: + Str: Message type as string, e.g. SensorData, SensorView etc. + """ + filename = os.path.basename(path) + if filename.find("_sd_") != -1: + return "SensorData" + if filename.find("_sv_") != -1: + return "SensorView" + if filename.find("_gt_") != -1: + return "GroundTruth" + return "SensorView" + + def main(): """Main method""" # Handling of command line arguments args = command_line_arguments() + if not args.type: + args.type = detect_message_type(args.data) + # Instantiate Logger print("Instantiate logger ...") directory = args.output