Skip to content

Commit

Permalink
Format timeseries values to 2 decimal points for now - need a
Browse files Browse the repository at this point in the history
config field
  • Loading branch information
mikejmets committed Oct 17, 2024
1 parent 422efa4 commit 0b5369d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/senaite/timeseries/importer/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ def parse_headerline(self, line):

return 0

def format_values(self, result):
formatted = []
for value in result:
try:
value = int(value)
value = "%d" % value
formatted.append(value)
continue
except Exception:
pass
try:
value = float(value)
value = "{:0.2f}".format(value)
formatted.append(value)
continue
except Exception:
pass
formatted.append(value)
return formatted

def parse_resultsline(self, line):
"""Parses result lines"""
splitted = [token.strip() for token in line.split(self._delimiter)]
Expand All @@ -78,6 +98,7 @@ def parse_resultsline(self, line):
return 0

result = splitted[1 : len(self._column_headers) + 1] # noqa
result = self.format_values(result)
self._result.append(result)

return 0
Expand Down

0 comments on commit 0b5369d

Please sign in to comment.