From 0b5369d6c1e0e6ab10b7ded70c77f714a4f3d5be Mon Sep 17 00:00:00 2001 From: Mike Metcalfe Date: Thu, 17 Oct 2024 20:39:15 +0200 Subject: [PATCH] Format timeseries values to 2 decimal points for now - need a config field --- src/senaite/timeseries/importer/timeseries.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/senaite/timeseries/importer/timeseries.py b/src/senaite/timeseries/importer/timeseries.py index 8c3eb2c..9efed54 100644 --- a/src/senaite/timeseries/importer/timeseries.py +++ b/src/senaite/timeseries/importer/timeseries.py @@ -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)] @@ -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