Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect type from file name #73

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a logger warning here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no logger warning before when no type is set. Of course we could still add one here, but I am actually not sure, if the logger even works correctly, see #53.

Since this is blocking my development in openMSL/sl-2-0-traffic-participant-model-repository-template#12 I propose to merge without the logger entry and fix this later in #53.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree



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