Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "full-timeseries-journey" option to use the full timeseries for the journey #186

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bin/gopro-dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from gopro_overlay.privacy import PrivacyZone, NoPrivacyZone
from gopro_overlay.progresstrack import ProgressBarProgress
from gopro_overlay.timeunits import timeunits, Timeunit
from gopro_overlay.timeseries import Timeseries
from gopro_overlay.timing import PoorTimer, Timers
from gopro_overlay.units import units
from gopro_overlay.widgets.profile import WidgetProfiler
Expand All @@ -50,7 +51,8 @@ def accepter_from_args(include, exclude):


def create_desired_layout(dimensions, layout, layout_xml: Path, include, exclude, renderer, timeseries, font,
privacy_zone, profiler, converters: Converters):
privacy_zone, profiler, converters: Converters,
fulltimeseries: Timeseries = None):
accepter = accepter_from_args(include, exclude)

if layout_xml:
Expand All @@ -61,7 +63,7 @@ def create_desired_layout(dimensions, layout, layout_xml: Path, include, exclude
try:
return layout_from_xml(
load_xml_layout(resource_name), renderer, timeseries, font, privacy_zone, include=accepter,
decorator=profiler, converters=converters
decorator=profiler, converters=converters, fulltimeseries=fulltimeseries
)
except FileNotFoundError:
raise IOError(f"Unable to locate bundled layout resource: {resource_name}. "
Expand All @@ -72,7 +74,7 @@ def create_desired_layout(dimensions, layout, layout_xml: Path, include, exclude
elif layout == "xml":
return layout_from_xml(
load_xml_layout(layout_xml), renderer, timeseries, font, privacy_zone, include=accepter,
decorator=profiler, converters=converters
decorator=profiler, converters=converters, fulltimeseries=fulltimeseries
)
else:
raise ValueError(f"Unsupported layout {args.layout_creator}")
Expand Down Expand Up @@ -357,7 +359,8 @@ def fmtdt(dt: datetime.datetime):
font=font,
privacy_zone=privacy_zone,
profiler=profiler,
converters=unit_converters
converters=unit_converters,
fulltimeseries=fit_or_gpx_timeseries if args.full_timeseries_journey else None
)

overlay = Overlay(framemeta=frame_meta, create_widgets=layout_creator)
Expand Down
2 changes: 2 additions & 0 deletions gopro_overlay/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def gopro_dashboard_arguments(args=None):

only.add_argument("--use-gpx-only", "--use-fit-only", action="store_true",
help="Use only the GPX/FIT file - no GoPro location data")
only.add_argument("--full-timeseries-journey", action="store_true",
help="Use the full timeseries for the journey")
only.add_argument("--video-time-start", choices=["file-created", "file-modified", "file-accessed"],
help="Use file dates for aligning video and GPS information, only when --use-gpx-only - EXPERIMENTAL! - may be changed/removed")
only.add_argument("--video-time-end", choices=["file-created", "file-modified", "file-accessed"],
Expand Down
9 changes: 8 additions & 1 deletion gopro_overlay/journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,22 @@ def __init__(self):
self.badlat = MinMax("badlat")
self.badlon = MinMax("badlon")

def accept(self, item):
def accept_location(self, item):
if item.gpsfix in GPS_FIXED_VALUES:
self.locations.append(item.point)

def accept_minmax(self, item):
if item.gpsfix in GPS_FIXED_VALUES:
self.lat.update(item.point.lat)
self.lon.update(item.point.lon)
else:
self.badlat.update(item.point.lat)
self.badlon.update(item.point.lon)

def accept(self, item):
self.accept_location(item)
self.accept_minmax(item)

@property
def bounding_box(self) -> BoundingBox:
lat = self.lat if self.lat else self.badlat
Expand Down
9 changes: 7 additions & 2 deletions gopro_overlay/layout_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def converter(self, name: str) -> Callable[[pint.Quantity], Optional[pint.Quanti


def layout_from_xml(xml, renderer, framemeta, font, privacy, include=lambda name: True,
decorator: Optional[WidgetProfiler] = None, converters: Converters = Converters()):
decorator: Optional[WidgetProfiler] = None, converters: Converters = Converters(),
fulltimeseries = None):
root = ET.fromstring(xml)

fonts = {}
Expand All @@ -121,6 +122,7 @@ def font_at(size):
renderer=renderer,
framemeta=framemeta,
converters=converters,
fulltimeseries=fulltimeseries
)

def name_of(element):
Expand Down Expand Up @@ -389,12 +391,13 @@ def __contains__(self, item):

class Widgets:

def __init__(self, font, privacy, renderer, framemeta, converters):
def __init__(self, font, privacy, renderer, framemeta, converters, fulltimeseries = None):
self.framemeta = framemeta
self.renderer = renderer
self.privacy = privacy
self.font = font
self.converters = converters
self.fulltimeseries = fulltimeseries

def _font(self, element, name, d):
return self.font(iattrib(element, name, d=d, r=range(1, 2000)))
Expand Down Expand Up @@ -494,6 +497,7 @@ def create_journey_map(self, element: ET.Element, entry, **kwargs) -> Widget:
privacy_zone=self.privacy,
renderer=self.renderer,
timeseries=self.framemeta,
fulltimeseries=self.fulltimeseries,
size=iattrib(element, "size", d=256),
corner_radius=iattrib(element, "corner_radius", 0),
opacity=fattrib(element, "opacity", 0.7, r=FloatRange(0.0, 1.0))
Expand All @@ -505,6 +509,7 @@ def create_moving_journey_map(self, element: ET.Element, entry, **kwargs) -> Wid
location=lambda: entry().point,
privacy_zone=self.privacy,
renderer=self.renderer,
fulltimeseries=self.fulltimeseries,
timeseries=self.framemeta,
size=iattrib(element, "size", d=256),
zoom=iattrib(element, "zoom", d=16, r=range(1, 20))
Expand Down
17 changes: 13 additions & 4 deletions gopro_overlay/widgets/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def generate_mask(self):

class JourneyMap(Widget):
def __init__(self, timeseries, at, location, renderer, size=256, corner_radius=None, opacity=0.7,
privacy_zone=NoPrivacyZone()):
privacy_zone=NoPrivacyZone(), fulltimeseries=None):
self.timeseries = timeseries
self.fulltimeseries = fulltimeseries
self.privacy_zone = privacy_zone
self.at = at
self.location = location
Expand All @@ -98,7 +99,10 @@ def _init_maybe(self):
if self.map is None:
journey = Journey()

self.timeseries.process(journey.accept)
if self.fulltimeseries is None:
self.timeseries.process(journey.accept)
else:
self.fulltimeseries.process(journey.accept)

bbox = journey.bounding_box
self.map = geotiler.Map(extent=(bbox.min.lon, bbox.min.lat, bbox.max.lon, bbox.max.lat),
Expand Down Expand Up @@ -206,9 +210,10 @@ def f(n):

class MovingJourneyMap(Widget):

def __init__(self, timeseries, privacy_zone, location, size, zoom, renderer):
def __init__(self, timeseries, privacy_zone, location, size, zoom, renderer, fulltimeseries=None):
self.privacy_zone = privacy_zone
self.timeseries = timeseries
self.fulltimeseries = fulltimeseries
self.size = size
self.renderer = renderer
self.zoom = zoom
Expand All @@ -219,7 +224,11 @@ def __init__(self, timeseries, privacy_zone, location, size, zoom, renderer):

def _redraw(self):
journey = Journey()
self.timeseries.process(journey.accept)
if self.fulltimeseries is None:
self.timeseries.process(journey.accept)
else:
self.fulltimeseries.process(journey.accept_location)
self.timeseries.process(journey.accept_minmax)

bbox = journey.bounding_box

Expand Down