Skip to content

Commit

Permalink
add cat log without header structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Feb 22, 2024
1 parent 1129ab6 commit 3a51eac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
39 changes: 36 additions & 3 deletions wizard/parsers/parser_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class GPSCatTrackParser(CSVParser):
'''
DATATYPE = "gps_cattrack"
DIVIDER = "--------\n"
START_WITH = "Name:CatLog"
FIELDS = [
"Date", "Time", "Latitude", "Longitude", "Altitude", "Satellites", "HDOP", "PDOP", "Temperature [C]", "Speed [km/h]", "TTFF", "SNR", "tbd"]

Expand Down Expand Up @@ -213,11 +214,14 @@ def __init__(self, stream):
if not self.stream.seekable():
self._raise_not_supported('Stream not seekable')

if not stream_starts_with(self.stream, "Name:CatLog"):
if self.START_WITH and not stream_starts_with(self.stream, self.START_WITH):
self._raise_not_supported(f"Stream must start with Name:CatLog")

_intro, data = self.stream.read().split(self.DIVIDER)
content = io.StringIO(data)
if self.DIVIDER:
_intro, data = self.stream.read().split(self.DIVIDER)
content = io.StringIO(data)
else:
content = self.stream

reader = csv.reader(content, delimiter=self.SEPARATOR, skipinitialspace=self.SKIP_INITIAL_SPACE)
header = next(reader)
Expand All @@ -227,6 +231,34 @@ def __init__(self, stream):
self.data = pd.read_csv(content, header=0, names=self.FIELDS, sep=self.SEPARATOR, index_col=False)


class GPSCatTrackNoDivider(GPSCatTrackParser):
DIVIDER = None
START_WITH = None
FIELDS = [
"Date", "Time", "Latitude", "Longitude", "Altitude", "Satellites", "HDOP", "PDOP"]

MAPPINGS = {
"id": "",
"date": "Date",
"time": "Time",
"latitude": "Latitude",
"longitude": "Longitude",
"altitude": "Altitude",
"speed_km_h": None,
"type": None,
"distance": None,
"course": None,
"hdop": "HDOP",
"pdop": "PDOP",
"satellites_count": "Satellites",
"temperature": None,
"solar_I_mA": None,
"bat_soc_pct": None,
"ring_nr": None,
"trip_nr": None,
}


class GPS2JMParser(CSVParser):
'''
Parser for 2Jm format
Expand Down Expand Up @@ -300,4 +332,5 @@ def __init__(self, stream):
IGotU_GT_Parser,
IGotU_GT_TabSeparatedParser,
GPS2JMParser,
GPSCatTrackNoDivider,
]
8 changes: 7 additions & 1 deletion wizard/parsers/tests/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
IGNORED_FILES = [
'.gitkeep',
]
IGNORED_DIRS = [
# 'gps_gpx',
# 'accelerometer',
# 'gps_pathtrack',
# 'tdr',
]

testdata_success = []
for dir in (TESTS_DATA_PATH / 'success').iterdir():
if dir.is_dir() and not dir.name.endswith('__ignore'):
if dir.is_dir() and dir.name not in IGNORED_DIRS:
for f in dir.iterdir():
if not f.is_dir() and f.name not in IGNORED_FILES:
testdata_success.append((f.name, f, dir.name))
Expand Down

0 comments on commit 3a51eac

Please sign in to comment.