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.
This commit is contained in:
parent
4a7de7b518
commit
cf4007c909
48
functions.py
48
functions.py
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
''' Classes used by main program. '''
|
''' Classes used by main program. '''
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
|
@ -90,6 +90,48 @@ class Photo:
|
||||||
pic_aware_time = pic_naive_time.astimezone(local_timezone)
|
pic_aware_time = pic_naive_time.astimezone(local_timezone)
|
||||||
return pic_aware_time
|
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:
|
class Exif:
|
||||||
'''
|
'''
|
||||||
Converts, compiles and writes Exif-Tags from given arguemnts.
|
Converts, compiles and writes Exif-Tags from given arguemnts.
|
||||||
|
@ -103,8 +145,8 @@ class Exif:
|
||||||
dry_run: whether to acutally write (True / False)
|
dry_run: whether to acutally write (True / False)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Latitude / Longitude in degrees
|
Latitude / Longitude: in degrees
|
||||||
Exif-Comment that has been written (incl. radiation)
|
Exif-Comment: that has been written (incl. radiation)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, photo, dry_run, radiation, latitude, longitude, elevation):
|
def __init__(self, photo, dry_run, radiation, latitude, longitude, elevation):
|
||||||
|
|
|
@ -10,7 +10,7 @@ import csv
|
||||||
import argparse
|
import argparse
|
||||||
import pytz
|
import pytz
|
||||||
import gpxpy
|
import gpxpy
|
||||||
from functions import Radiation, Photo, Exif
|
from functions import Radiation, Photo, Exif, Match
|
||||||
|
|
||||||
# SIFACTOR for GQ Geiger counters
|
# SIFACTOR for GQ Geiger counters
|
||||||
|
|
||||||
|
@ -91,6 +91,8 @@ for src_photo in args.photos:
|
||||||
|
|
||||||
# Here the matching magic has to happen
|
# Here the matching magic has to happen
|
||||||
|
|
||||||
|
match = Match(photo.get_date, radiation_list, position_list)
|
||||||
|
|
||||||
latitude = 51.0234024
|
latitude = 51.0234024
|
||||||
longitude = 7.248347
|
longitude = 7.248347
|
||||||
radiation = 9001.15
|
radiation = 9001.15
|
||||||
|
|
Loading…
Reference in New Issue