Added a working match class that returns best match for radiation and position.
Still ugly and a lot of debug output. Also not finished.
This commit is contained in:
38
functions.py
38
functions.py
@@ -11,7 +11,7 @@ import pyexiv2
|
||||
|
||||
class Radiation:
|
||||
'''
|
||||
Reiceives Values vom CSV file and creates a list of the relevant data
|
||||
Reiceives values vom CSV file and creates a list of the relevant data
|
||||
|
||||
Arguments:
|
||||
timestamp: Date/time string from CSV as string
|
||||
@@ -101,27 +101,24 @@ class Match:
|
||||
position_list: list of timestamp / position / elevation values
|
||||
|
||||
Returns:
|
||||
timestamp: as datetime object
|
||||
radiation: in µS/h as string
|
||||
latitude: in decimal format as float
|
||||
longitude: in decimal format as float
|
||||
elevation: in meters as float
|
||||
minimal timedelta: as timedelta object
|
||||
best matching valuerow
|
||||
'''
|
||||
|
||||
def __init__(self, photo_time, radiation_list, position_list):
|
||||
# self.radiation = self._find_match(photo_time, radiation_list)
|
||||
self.position = self._find_match(photo_time, position_list)
|
||||
self.radiation = self._find_radiation_match(photo_time, radiation_list)
|
||||
self.position = self._find_position_match(photo_time, position_list)
|
||||
|
||||
def __repr__(self):
|
||||
pass
|
||||
|
||||
def _find_match(self, photo_time, list):
|
||||
def _find_radiation_match(self, photo_time, list):
|
||||
valuelist = []
|
||||
for row in list:
|
||||
# Define timedelta and define timedelta datetime object.
|
||||
delta = timedelta(seconds=60)
|
||||
time_delta = abs(row.timestamp - photo_time)
|
||||
# time_delta = abs(row[0] - photo_time)
|
||||
if row.timestamp:
|
||||
time_delta = abs(row.timestamp - photo_time)
|
||||
# datetime objects should match with 1 minute precision.
|
||||
if time_delta < delta:
|
||||
element = (time_delta, row)
|
||||
@@ -129,6 +126,25 @@ class Match:
|
||||
# Return the list item with the lowest timedelta in column 0.
|
||||
# Column 2 contains the source objects untouched.
|
||||
if valuelist:
|
||||
print(min(valuelist, key=lambda x: x[0]))
|
||||
return min(valuelist, key=lambda x: x[0])
|
||||
return None
|
||||
|
||||
def _find_position_match(self, photo_time, list):
|
||||
valuelist = []
|
||||
for row in list:
|
||||
# Define timedelta and define timedelta datetime object.
|
||||
delta = timedelta(seconds=60)
|
||||
if row[0]:
|
||||
time_delta = abs(row[0] - photo_time)
|
||||
# datetime objects should match with 1 minute precision.
|
||||
if time_delta < delta:
|
||||
element = (time_delta, row)
|
||||
valuelist.append(element)
|
||||
# Return the list item with the lowest timedelta in column 0.
|
||||
# Column 2 contains the source objects untouched.
|
||||
if valuelist:
|
||||
print(min(valuelist, key=lambda x: x[0]))
|
||||
return min(valuelist, key=lambda x: x[0])
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user