Skip to content

Commit

Permalink
Add function to automatically detect type from file name (#73)
Browse files Browse the repository at this point in the history
Signed-off-by: ClemensLinnhoff <clemens.linnhoff@partner.bmw.de>
  • Loading branch information
ClemensLinnhoff authored May 28, 2024
1 parent 03af25e commit 3e7d5a4
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions osivalidator/osi_general_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e7d5a4

Please sign in to comment.