Added Output class that formats matched data and returns string for printing.
Added beautified output.
This commit is contained in:
parent
d935cc1ea0
commit
c2ed0e1c2a
57
functions.py
57
functions.py
|
@ -74,10 +74,10 @@ class Photo:
|
||||||
# Copy photo to dest_dir and return its (new) filename
|
# Copy photo to dest_dir and return its (new) filename
|
||||||
# if not in dry_run mode or if dest_dir is different from src_dir.
|
# if not in dry_run mode or if dest_dir is different from src_dir.
|
||||||
if dry_run is True:
|
if dry_run is True:
|
||||||
return photo
|
return photo_basename, photo
|
||||||
if dest_dir != '.':
|
if dest_dir != '.':
|
||||||
shutil.copy(photo, dest_photo)
|
shutil.copy(photo, dest_photo)
|
||||||
return dest_photo
|
return photo_basename, dest_photo
|
||||||
|
|
||||||
def _get_creation_date(self, photo, local_timezone):
|
def _get_creation_date(self, photo, local_timezone):
|
||||||
# Load Exif data from photo
|
# Load Exif data from photo
|
||||||
|
@ -114,9 +114,14 @@ class Match:
|
||||||
radiation = round(self.radiation[1], 2)
|
radiation = round(self.radiation[1], 2)
|
||||||
else:
|
else:
|
||||||
radiation = None
|
radiation = None
|
||||||
|
|
||||||
|
if self.position[1][3]:
|
||||||
|
altitude = round(self.position[1][3])
|
||||||
|
else:
|
||||||
|
altitude = None
|
||||||
return 'Radiation: %s µS/h (Δt %s) \nPosition: Lat: %s, Long: %s, Alt: %sm (Δt %s)' % \
|
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(radiation), str(self.radiation[0]), str(self.position[1][1]), \
|
||||||
str(self.position[1][2]), str(self.position[1][3]), str(self.position[0]))
|
str(self.position[1][2]), altitude, str(self.position[0]))
|
||||||
|
|
||||||
def _find_radiation_match(self, photo_time, list):
|
def _find_radiation_match(self, photo_time, list):
|
||||||
valuelist = []
|
valuelist = []
|
||||||
|
@ -153,6 +158,7 @@ class Match:
|
||||||
if valuelist:
|
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 min(valuelist, key=lambda x: x[0])
|
||||||
|
# Return Nones in the same cascaded manner as if it matched.
|
||||||
return [None, [None, None, None, None]]
|
return [None, [None, None, None, None]]
|
||||||
|
|
||||||
class Exif:
|
class Exif:
|
||||||
|
@ -161,7 +167,7 @@ class Exif:
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
photo: file name of photo to modify
|
photo: file name of photo to modify
|
||||||
radiation: radiation levels in µS/h
|
radiation: radiation levels float
|
||||||
latitude: latitude as float
|
latitude: latitude as float
|
||||||
longitude: longitude as float
|
longitude: longitude as float
|
||||||
elevation: elevation as float
|
elevation: elevation as float
|
||||||
|
@ -238,3 +244,46 @@ class Exif:
|
||||||
metadata.write()
|
metadata.write()
|
||||||
|
|
||||||
return latitude_degree, longitude_degree, new_comment
|
return latitude_degree, longitude_degree, new_comment
|
||||||
|
|
||||||
|
class Output:
|
||||||
|
'''
|
||||||
|
Receives values to be printed, formats them and returns a string for printing.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
radiation: radiation as float
|
||||||
|
latitude: latitude as float
|
||||||
|
longitude: longitude as float
|
||||||
|
elevation: elevation as float
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A String that can be printed in output
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, radiation, latitude, longitude, altitude):
|
||||||
|
self.get_string = self._get_string(radiation, latitude, longitude, altitude)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.get_string
|
||||||
|
|
||||||
|
def _get_string(self, radiation, latitude, longitude, altitude):
|
||||||
|
# Convert values to styled strings
|
||||||
|
if radiation:
|
||||||
|
rad = '☢: %sµS/h ' % str(round(radiation, 2))
|
||||||
|
else:
|
||||||
|
rad = '☢: N/A '
|
||||||
|
|
||||||
|
if latitude and longitude:
|
||||||
|
latlon = 'Lat.: %s Long.: %s ' % (str(latitude), str(longitude))
|
||||||
|
else:
|
||||||
|
latlon = 'Lat.: N/A, Long.: N/A '
|
||||||
|
|
||||||
|
if altitude:
|
||||||
|
alt = 'Alt.: %sm' % str(round(altitude, 1))
|
||||||
|
else:
|
||||||
|
alt = 'Alt.: N/A'
|
||||||
|
|
||||||
|
data = rad + latlon + alt
|
||||||
|
|
||||||
|
# Return data string
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
27
rad_tag.py
27
rad_tag.py
|
@ -10,7 +10,7 @@ import csv
|
||||||
import argparse
|
import argparse
|
||||||
import pytz
|
import pytz
|
||||||
import gpxpy
|
import gpxpy
|
||||||
from functions import Radiation, Photo, Match, Exif
|
from functions import Radiation, Photo, Match, Exif, Output
|
||||||
|
|
||||||
# SIFACTOR for GQ Geiger counters
|
# SIFACTOR for GQ Geiger counters
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ with open(args.csv, "r") as f:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Import GPX track(s)print
|
# Import GPX track(s)print
|
||||||
if args.gpx is not None:
|
if args.gpx:
|
||||||
gpx_file = open(args.gpx, 'r')
|
gpx_file = open(args.gpx, 'r')
|
||||||
gpx_reader = gpxpy.parse(gpx_file)
|
gpx_reader = gpxpy.parse(gpx_file)
|
||||||
#for waypoint in gpx_reader.waypoints:
|
#for waypoint in gpx_reader.waypoints:
|
||||||
|
@ -72,13 +72,12 @@ if args.gpx is not None:
|
||||||
for segment in track.segments:
|
for segment in track.segments:
|
||||||
for point in segment.points:
|
for point in segment.points:
|
||||||
point_aware_time = point.time.astimezone(local_timezone)
|
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,
|
position = (point_aware_time, point.latitude, point.longitude,
|
||||||
point.elevation)
|
point.elevation)
|
||||||
position_list.append(position)
|
position_list.append(position)
|
||||||
|
|
||||||
# Inform the user about what is going to happen
|
# Inform the user about what is going to happen
|
||||||
if args.dry is True:
|
if args.dry:
|
||||||
print('Not modifying anything. Just print what would happen without --dry')
|
print('Not modifying anything. Just print what would happen without --dry')
|
||||||
else:
|
else:
|
||||||
if args.outdir == ".":
|
if args.outdir == ".":
|
||||||
|
@ -86,15 +85,23 @@ else:
|
||||||
else:
|
else:
|
||||||
print('Modifying photos in', str(args.outdir), '(copy)')
|
print('Modifying photos in', str(args.outdir), '(copy)')
|
||||||
|
|
||||||
|
# Print table header
|
||||||
|
print('{:<15} {:<25} {:<22}'.format('filename', 'date / time', 'Matched Data'))
|
||||||
|
|
||||||
for src_photo in args.photos:
|
for src_photo in args.photos:
|
||||||
|
# Instantiate photo, copy it to destdir if needed and receive filename to work on
|
||||||
photo = Photo(src_photo, local_timezone, args.outdir, args.dry)
|
photo = Photo(src_photo, local_timezone, args.outdir, args.dry)
|
||||||
print(photo.get_target_photo, photo.get_date)
|
|
||||||
|
|
||||||
# Here the matching magic has to happen
|
|
||||||
|
|
||||||
|
# Here the matching magic takes place
|
||||||
match = Match(photo.get_date, radiation_list, position_list)
|
match = Match(photo.get_date, radiation_list, position_list)
|
||||||
|
|
||||||
|
# Formatted output:
|
||||||
|
#print(Output(photo.get_target_photo[0], photo.get_date, match.radiation[1],
|
||||||
|
# match.position[1][1], match.position[1][2], match.position[1][3]))
|
||||||
|
data = Output(match.radiation[1], match.position[1][1], match.position[1][2], match.position[1][3])
|
||||||
|
|
||||||
|
print('{:<15} {:<25} {:<22}'.format(photo.get_target_photo[0], str(photo.get_date), str(data)))
|
||||||
|
|
||||||
# Write exif data
|
# Write exif data
|
||||||
exif_tags = Exif(photo.get_target_photo, args.dry, match.radiation[1],
|
Exif(photo.get_target_photo[1], args.dry, match.radiation[1],
|
||||||
match.position[1][1], match.position[1][2], match.position[1][3])
|
match.position[1][1], match.position[1][2], match.position[1][3])
|
||||||
print(exif_tags)
|
|
||||||
|
|
Loading…
Reference in New Issue