set Model start/duration from points

This commit is contained in:
Daniel Barlow 2024-11-21 11:46:45 +00:00
parent aa36f74762
commit c10e5ea70d
2 changed files with 16 additions and 3 deletions

View File

@ -158,7 +158,7 @@ init _ url navKey =
Just (Timeline (Just s) (Just d)) -> (s, d) Just (Timeline (Just s) (Just d)) -> (s, d)
_ -> (10,10) _ -> (10,10)
in 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)) (fetchTrack start duration))
-- SUBSCRIPTIONS -- SUBSCRIPTIONS
@ -234,7 +234,15 @@ updateModel msg model =
} }
Loaded result -> Loaded result ->
case result of 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 (Http.BadBody e) -> { model | track = Debug.log e (Failure "e") }
Err e -> { model | track = Debug.log "unknown error" (Failure "e") } Err e -> { model | track = Debug.log "unknown error" (Failure "e") }
NewUrlRequest -> model NewUrlRequest -> model

View File

@ -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 import Json.Decode as D
@ -63,6 +63,11 @@ duration points =
(p::ps) -> (last p ps).time - p.time (p::ps) -> (last p ps).time - p.time
_ -> 0 _ -> 0
startTime points =
case points of
(p::ps) -> Just p.time
_ -> Nothing
subseq points start dur = subseq points start dur =
case points of case points of
[] -> [] [] -> []