Created a match representation, figured how to access specific data from Match class.
This commit is contained in:
27
functions.py
27
functions.py
@@ -39,7 +39,7 @@ class Radiation:
|
||||
|
||||
def _radiation_conversion(self, radiation, si_factor):
|
||||
# Convert CP/M to µS/h using si_factor
|
||||
radiation = round(float(radiation) * si_factor, 2)
|
||||
radiation = float(radiation) * si_factor
|
||||
return radiation
|
||||
|
||||
class Photo:
|
||||
@@ -110,7 +110,13 @@ class Match:
|
||||
self.position = self._find_position_match(photo_time, position_list)
|
||||
|
||||
def __repr__(self):
|
||||
pass
|
||||
if self.radiation[1]:
|
||||
radiation = round(self.radiation[1], 2)
|
||||
else:
|
||||
radiation = None
|
||||
return 'Radiation: %s µS/h (Δt %s) \nPosition: Lat: %s, Long: %s, Alt: %sm (Δt %s)' % \
|
||||
(str(radiation), str(self.radiation[0]), str(self.position[1][1]), \
|
||||
str(self.position[1][2]), str(self.position[1][3]), str(self.position[0]))
|
||||
|
||||
def _find_radiation_match(self, photo_time, list):
|
||||
valuelist = []
|
||||
@@ -126,27 +132,28 @@ 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
|
||||
result = min(valuelist, key=lambda x: x[0])
|
||||
return result[0], result[1].radiation
|
||||
# Return a tuple of 2x None, if there was no match.
|
||||
return None, 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)
|
||||
delta = timedelta(seconds=300)
|
||||
if row[0]:
|
||||
time_delta = abs(row[0] - photo_time)
|
||||
# datetime objects should match with 1 minute precision.
|
||||
# datetime objects should match with 5 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]))
|
||||
#print(min(valuelist, key=lambda x: x[0]))
|
||||
return min(valuelist, key=lambda x: x[0])
|
||||
return None
|
||||
return [None, [None, None, None, None]]
|
||||
|
||||
class Exif:
|
||||
'''
|
||||
@@ -221,7 +228,7 @@ class Exif:
|
||||
|
||||
if radiation:
|
||||
# Set new UserComment
|
||||
new_comment = 'Radiation ☢ : ' + str(radiation) + ' µS/h'
|
||||
new_comment = 'Radiation ☢ : %s µS/h' % str(round(radiation, 2))
|
||||
metadata['Exif.Photo.UserComment'] = new_comment
|
||||
else:
|
||||
new_comment = None
|
||||
|
Reference in New Issue
Block a user