From c10e5ea70ddc1358006723977f5f1928c1f81a99 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 21 Nov 2024 11:46:45 +0000 Subject: [PATCH] set Model start/duration from points --- frontend/src/Main.elm | 12 ++++++++++-- frontend/src/Point.elm | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index 27f4db2..8c487cc 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -158,7 +158,7 @@ init _ url navKey = Just (Timeline (Just s) (Just d)) -> (s, d) _ -> (10,10) in - ((Model (toCoord 51.60 -0.01) (FineZoomLevel (13*8)) None None start duration Empty), + ((Model (toCoord 51.60 -0.01) (FineZoomLevel (13*8)) None None 0 0 Empty), (fetchTrack start duration)) -- SUBSCRIPTIONS @@ -234,7 +234,15 @@ updateModel msg model = } Loaded result -> case result of - Ok trk -> { model | track = Present trk } + Ok trk -> + let start = Maybe.withDefault 0 (Point.startTime trk) + duration = Point.duration trk + in + { model + | track = Present trk + , startTime = floor start + , duration = ceiling duration + } Err (Http.BadBody e) -> { model | track = Debug.log e (Failure "e") } Err e -> { model | track = Debug.log "unknown error" (Failure "e") } NewUrlRequest -> model diff --git a/frontend/src/Point.elm b/frontend/src/Point.elm index f33ab99..6179249 100644 --- a/frontend/src/Point.elm +++ b/frontend/src/Point.elm @@ -1,4 +1,4 @@ -module Point exposing(Pos, Point, decoder, downsample, duration, subseq) +module Point exposing(Pos, Point, decoder, downsample, duration, subseq, startTime) import Json.Decode as D @@ -63,6 +63,11 @@ duration points = (p::ps) -> (last p ps).time - p.time _ -> 0 +startTime points = + case points of + (p::ps) -> Just p.time + _ -> Nothing + subseq points start dur = case points of [] -> []