souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c10e5ea70ddc1358006723977f5f1928c1f81a99
parent aa36f74762c77a7bd988f8a92a46135a0f97baf6
Author: Daniel Barlow <dan@telent.net>
Date:   Thu, 21 Nov 2024 11:46:45 +0000

set Model start/duration from points

Diffstat:
Mfrontend/src/Main.elm | 12++++++++++--
Mfrontend/src/Point.elm | 7++++++-
2 files changed, 16 insertions(+), 3 deletions(-)

diff --git 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 @@ -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 [] -> []