Skip to content

Commit

Permalink
Initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyS83 authored and time4tea committed Feb 10, 2024
1 parent e64957a commit d589303
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/gopro-dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def fmtdt(dt: datetime.datetime):
frame_meta.process_deltas(timeseries_process.calculate_speeds(), skip=packets_per_second * 3,
filter_fn=locked_2d)
frame_meta.process(timeseries_process.calculate_odo(), filter_fn=locked_2d)
frame_meta.process_accel(timeseries_process.calculate_accel(), skip=18 * 3)
frame_meta.process_deltas(timeseries_process.calculate_gradient(), skip=packets_per_second * 3,
filter_fn=locked_3d) # hack
frame_meta.process(timeseries_process.process_kalman("speed", lambda e: e.speed))
Expand Down
1 change: 1 addition & 0 deletions bin/gopro-layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def load_frame(ffmpeg_gopro: FFMPEGGoPro, filepath: pathlib.Path, size: Dimensio

timeseries.process_deltas(timeseries_process.calculate_speeds(), skip=18 * 3)
timeseries.process(timeseries_process.calculate_odo())
timeseries.process_accel(timeseries_process.calculate_accel(), skip=18 * 3)
timeseries.process_deltas(timeseries_process.calculate_gradient(), skip=18 * 3)

video_frame = load_frame(ffmpeg_gopro, inputpath, gopro.recording.video.dimension, timeseries.mid)
Expand Down
10 changes: 8 additions & 2 deletions bin/gopro-to-csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
# ts.process(timeseries_process.process_ses("point", lambda i: i.point, alpha=0.45), filter_fn=locked_2d)
ts.process_deltas(timeseries_process.calculate_speeds(), skip=packets_per_second * 3, filter_fn=locked_2d)
ts.process(timeseries_process.calculate_odo(), filter_fn=locked_2d)
ts.process_accel(timeseries_process.calculate_accel(), skip=packets_per_second * 3, filter_fn=locked_2d)
ts.process_deltas(timeseries_process.calculate_gradient(), skip=packets_per_second * 3, filter_fn=locked_3d) # hack
ts.process(timeseries_process.filter_locked())

Expand All @@ -88,20 +89,24 @@
def printable_unit(v):
if v is None:
return ""
return v.magnitude
try:
return v.magnitude
except:
return None


dest: Optional[Path] = args.output

with smart_open(dest) as f:
writer = csv.DictWriter(f=f,
fieldnames=["packet", "packet_index", "gps_fix", "date", "lat", "lon", "dop", "alt",
"speed",
"speed", "accel",
"dist", "time", "azi", "odo",
"grad",
"accl_x", "accl_y", "accl_z"])
writer.writeheader()
for entry in filter(filter_fn, ts.items(step=datetime.timedelta(seconds=args.every))):

writer.writerow({
"packet": printable_unit(entry.packet),
"packet_index": printable_unit(entry.packet_index),
Expand All @@ -113,6 +118,7 @@ def printable_unit(v):
"alt": printable_unit(entry.alt),
"grad": printable_unit(entry.grad if entry.grad is not None else entry.cgrad),
"speed": printable_unit(entry.speed if entry.speed is not None else entry.cspeed),
"accel": printable_unit(entry.accel),
"dist": printable_unit(entry.dist),
"time": printable_unit(entry.time),
"azi": printable_unit(entry.azi),
Expand Down
2 changes: 2 additions & 0 deletions gopro_overlay/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def fake_framemeta(length: datetime.timedelta = datetime.timedelta(seconds=20),

points = Random2D(Point(51.4972, -0.1499), point_step, rng=rng)
speed = Random1D(10, rng=rng)
accel = Random1D(5, -10, rng=rng)
cad = Random1D(50, rng=rng)
grad = Random1D(23, rng=rng)
hr = Random1D(100, rng=rng)
Expand Down Expand Up @@ -87,6 +88,7 @@ def fake_framemeta(length: datetime.timedelta = datetime.timedelta(seconds=20),
packet_index=units.Quantity(counter % 18, units.number),

speed=units.Quantity(speed.step(), units.mps),
accel=units.Quantity(accel.step()),
cad=units.Quantity(cad.step(), units.rpm),
hr=units.Quantity(hr.step(), units.bpm),
alt=units.Quantity(alt.step(), units.m),
Expand Down
12 changes: 12 additions & 0 deletions gopro_overlay/framemeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ def process_deltas(self, processor, skip=1, filter_fn: Callable[[Entry], bool] =
if updates:
entry_a.update(**updates)

def process_accel(self, processor, skip=1, filter_fn: Callable[[Entry], bool] = lambda e: True):
self.check_modified()
diffs = list(zip(self.framelist, self.framelist[skip:]))

for a, b in diffs:
entry_a = self.frames[a]
entry_b = self.frames[b]
if filter_fn(entry_a) and filter_fn(entry_b):
updates = processor(entry_a, entry_b, skip)
if updates:
entry_b.update(**updates)

def process(self, processor, filter_fn: Callable[[Entry], bool] = lambda e: True):
self.check_modified()
for pts in self.framelist:
Expand Down
1 change: 1 addition & 0 deletions gopro_overlay/layout_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def metric_accessor_from(name: str) -> Callable[[Entry], Optional[pint.Quantity]
"power": lambda e: e.power,
"speed": lambda e: e.speed if e.speed is not None else e.cspeed,
"cspeed": lambda e: e.cspeed,
"accel": lambda e: e.accel,
"temp": lambda e: e.atemp,
"gradient": lambda e: e.grad if e.grad is not None else e.cgrad,
"cgrad": lambda e: e.cgrad,
Expand Down
9 changes: 9 additions & 0 deletions gopro_overlay/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def process_deltas(self, processor, skip=1):
if updates:
self.entries[a].update(**updates)

def process_accel(self, processor, skip=1):
self.check_modified()
diffs = list(zip(self.dates, self.dates[skip:]))

for a, b in diffs:
updates = processor(self.entries[a], self.entries[b], skip)
if updates:
self.entries[b].update(**updates)

def process(self, processor):
self.check_modified()
for e in self.dates:
Expand Down
15 changes: 14 additions & 1 deletion gopro_overlay/timeseries_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ def accept(a, b, c):
return accept


def calculate_accel():
def accept(a, b, c):
time = units.Quantity((b.dt - a.dt).total_seconds(), units.seconds)

if a.speed and b.speed and time:
accel = (b.speed - a.speed) / time
else:
accel = units.Quantity(0, units.mps)
return { "accel": accel }

return accept


def calculate_odo():
total = [units.Quantity(0.0, units.m)]

Expand All @@ -91,7 +104,7 @@ def accept(e):


def filter_locked():
fields = ["speed", "cspeed", "azi", "cog", "time", "dist", "grad", "cgrad", "alt"]
fields = ["speed", "cspeed", "accel", "azi", "cog", "time", "dist", "grad", "cgrad", "alt"]

def accept(e):
if e.gpsfix not in GPS_FIXED_VALUES:
Expand Down

0 comments on commit d589303

Please sign in to comment.