radiation-tagger/functions.py
Commander1024 fcc466eb41 Started conversion to OOP.
Created class Radiation with functions time_conversion and radiation
2020-03-09 22:42:08 +01:00

32 lines
1.0 KiB
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
class Position:
def __init__(self, timestamp, latitude, longitude):
self.timestamp = timestamp
self.latitude = latitude
self.longitude = longitude