Skip to content

Commit

Permalink
implement ecotone
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jun 20, 2024
1 parent 2a2421a commit 4485ce8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion wizard/parsers/gps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from .interrex import PARSERS as INTERREX
from .ornitela import PARSERS as ORNITELA
from .mataki import PARSERS as MATAKI
from .ecotone import PARSERS as ECOTONE

PARSERS = [
GPXParser,
] + IGOUT + CATLOG + BASE + JM + UNKNOWN + PATHTRACK + \
HO11 + AXYTREK + INTERREX + ORNITELA + MATAKI
HO11 + AXYTREK + INTERREX + ORNITELA + MATAKI + ECOTONE
17 changes: 17 additions & 0 deletions wizard/parsers/gps/ecotone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from parsers.parser_base import CSVParser


class EcotoneParser(CSVParser):
DATATYPE = "gps_ecotone"
FIELDS = [x for x in range(0,9)]
SEPARATOR = ";"
HEADER = 0

def _check_headers(self, header):
if len(header) != len(self.FIELDS):
self._raise_not_supported(f"Stream have a header length different than expected, {len(header)} != {len(self.FIELDS)}")


PARSERS = [
EcotoneParser,
]
13 changes: 8 additions & 5 deletions wizard/parsers/parser_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class CSVParser(Parser):
FIELDS = []
SEPARATOR = ','
SKIP_INITIAL_SPACE = True
HEADER = 1

def _check_headers(self, header):
if header != self.FIELDS:
self._raise_not_supported(f"Stream have a header different than expected, {header} != {self.FIELDS}")

def __init__(self, parsable: Parsable):
super().__init__(parsable)
Expand All @@ -120,12 +125,10 @@ def __init__(self, parsable: Parsable):

reader = csv.reader(stream, delimiter=self.SEPARATOR, skipinitialspace=self.SKIP_INITIAL_SPACE)
header = next(reader)
if header != self.FIELDS:
self._raise_not_supported(f"Stream have a header different than expected, {header} != {self.FIELDS}")

stream.seek(0)
self._check_headers(header)
stream.seek(0)

self.data = pd.read_csv(stream, header=1, names=self.FIELDS, sep=self.SEPARATOR, index_col=False)
self.data = pd.read_csv(stream, header=self.HEADER, names=self.FIELDS, sep=self.SEPARATOR, index_col=False)


class ExcelParser(Parser):
Expand Down

0 comments on commit 4485ce8

Please sign in to comment.