From cf4007c9092911b6f8e952d7931f581886468616 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sun, 15 Mar 2020 01:57:02 +0100 Subject: [PATCH] Added Match class. Works on Radiation so far, but fails on Position, because there is not attribute timestamp. Going to write a wrapper class to be able to use same Match class on both of them. --- functions.py | 48 +++++++++++++++++++++++++++++++++++++++++++++--- rad_tag.py | 4 +++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/functions.py b/functions.py index 2c5b3ef..49b2909 100644 --- a/functions.py +++ b/functions.py @@ -3,7 +3,7 @@ ''' Classes used by main program. ''' -from datetime import datetime +from datetime import datetime, timedelta import os import shutil from fractions import Fraction @@ -90,6 +90,48 @@ class Photo: pic_aware_time = pic_naive_time.astimezone(local_timezone) return pic_aware_time +class Match: + ''' + Receives lists of time / radiation and GPS data and compares it to timestamp. + Then returns relevant values matching to time - or None + + Arguments: + photo_time: timestamp of photo + radiation_list: list of timestamp / radiation values + 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 + ''' + + 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) + + def __repr__(self): + pass + + def _find_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) + # 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: + return min(valuelist, key=lambda x: x[0]) + return None + class Exif: ''' Converts, compiles and writes Exif-Tags from given arguemnts. @@ -103,8 +145,8 @@ class Exif: dry_run: whether to acutally write (True / False) Returns: - Latitude / Longitude in degrees - Exif-Comment that has been written (incl. radiation) + Latitude / Longitude: in degrees + Exif-Comment: that has been written (incl. radiation) ''' def __init__(self, photo, dry_run, radiation, latitude, longitude, elevation): diff --git a/rad_tag.py b/rad_tag.py index 8432c02..24e5bb6 100755 --- a/rad_tag.py +++ b/rad_tag.py @@ -10,7 +10,7 @@ import csv import argparse import pytz import gpxpy -from functions import Radiation, Photo, Exif +from functions import Radiation, Photo, Exif, Match # SIFACTOR for GQ Geiger counters @@ -91,6 +91,8 @@ for src_photo in args.photos: # Here the matching magic has to happen + match = Match(photo.get_date, radiation_list, position_list) + latitude = 51.0234024 longitude = 7.248347 radiation = 9001.15