Skip to content

Commit 3e7d5a4

Browse files
Add function to automatically detect type from file name (#73)
Signed-off-by: ClemensLinnhoff <[email protected]>
1 parent 03af25e commit 3e7d5a4

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

osivalidator/osi_general_validator.py

+24-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ def command_line_arguments():
5353
parser.add_argument(
5454
"--type",
5555
"-t",
56-
help="Name of the type used to serialize data.",
56+
help="Name of the type used to serialize data. Default is SensorView.",
5757
choices=["SensorView", "GroundTruth", "SensorData"],
58-
default="SensorView",
5958
type=str,
6059
required=False,
6160
)
@@ -122,12 +121,35 @@ def command_line_arguments():
122121
VALIDATION_RULES = osi_rules.OSIRules()
123122

124123

124+
def detect_message_type(path: str):
125+
"""Automatically detect the message type from the file name.
126+
If it cannot be detected, the function return SensorView as default.
127+
128+
Args:
129+
path (str): Path incl. filename of the trace file
130+
131+
Returns:
132+
Str: Message type as string, e.g. SensorData, SensorView etc.
133+
"""
134+
filename = os.path.basename(path)
135+
if filename.find("_sd_") != -1:
136+
return "SensorData"
137+
if filename.find("_sv_") != -1:
138+
return "SensorView"
139+
if filename.find("_gt_") != -1:
140+
return "GroundTruth"
141+
return "SensorView"
142+
143+
125144
def main():
126145
"""Main method"""
127146

128147
# Handling of command line arguments
129148
args = command_line_arguments()
130149

150+
if not args.type:
151+
args.type = detect_message_type(args.data)
152+
131153
# Instantiate Logger
132154
print("Instantiate logger ...")
133155
directory = args.output

0 commit comments

Comments
 (0)