Created a match representation, figured how to access specific data from Match class.

This commit is contained in:
Marcus Scholz 2020-03-21 13:29:53 +01:00
parent 952f2726ba
commit d935cc1ea0
2 changed files with 21 additions and 22 deletions

View File

@ -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

View File

@ -74,7 +74,7 @@ if args.gpx is not None:
point_aware_time = point.time.astimezone(local_timezone)
#point_aware_time = point_naive_time.astimezone(local_timezone)
position = (point_aware_time, point.latitude, point.longitude,
point.elevation, local_timezone)
point.elevation)
position_list.append(position)
# Inform the user about what is going to happen
@ -93,16 +93,8 @@ for src_photo in args.photos:
# Here the matching magic has to happen
match = Match(photo.get_date, radiation_list, position_list)
#print(match)
latitude = 51.0234024
longitude = 7.248347
radiation = 9001.15
elevation = 56.079345703125
# Write exif data
exif_tags = Exif(photo.get_target_photo, args.dry, radiation, latitude, longitude, elevation)
#print(exif_tags)
# Print table header
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Exif UserComment'))
exif_tags = Exif(photo.get_target_photo, args.dry, match.radiation[1],
match.position[1][1], match.position[1][2], match.position[1][3])
print(exif_tags)