radiation-tagger/functions.py

26 lines
888 B
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Classes used by main program. Handles CSV and GPX processing."""
from datetime import datetime
class Radiation:
def __init__(self, timestamp, radiation, local_timezone, si_factor):
self.timestamp = self._time_conversion(timestamp, local_timezone)
self.radiation = self._radiation(radiation, si_factor)
def __repr__(self):
return '%s %f µS/h' % (str(self.timestamp), self.radiation)
def _time_conversion(self, timestamp, local_timezone):
csv_naive_time = datetime.fromisoformat(timestamp)
# Set timezone
csv_aware_time = csv_naive_time.astimezone(local_timezone)
return csv_aware_time
def _radiation(self, radiation, si_factor):
# Convert CP/M to µS/h using si_factor
radiation = round(float(radiation) * si_factor, 2)
return radiation