Skip to content

Commit d7098cd

Browse files
authored
Option to configure average-speed day by day (#57)
1 parent a5e75eb commit d7098cd

File tree

4 files changed

+80
-53
lines changed

4 files changed

+80
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ public/
44
.cpcache/
55
.lsp/
66
.nrepl-port
7+
.DS_Store

notebooks/rando-planner.clj

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,29 @@
3333
(clerk/col
3434
(clerk/with-viewer diagram/plan-viewer example-plan)))))
3535

36-
;; **rando-planner**:
3736

38-
;; - allows users to break down the route with more control, providing
39-
;; visualization tools that help evaluating and comparing different
40-
;; plans
37+
;; When planning a long-distance bike ride, you face two main
38+
;; challenges: determining the route from point A to B, and organizing
39+
;; your journey—deciding how much distance to cover each day, when to
40+
;; take breaks, and where to refuel. Traditional route planners, such
41+
;; as Komoot, Strava, and Cycle.travel, primarily address the first
42+
;; challenge: designing the route.
4143

42-
;; - assumes the user already has a GPX track defined (provided for
43-
;; example by the organizers of a bike event), and let the user plan
44-
;; the daily effort to a higher granularity.
44+
;; Komoot includes a tool for dividing the route into multiple days,
45+
;; but it simply distributes the distance evenly across
46+
;; them. Cycle.travel, on the other hand, allows users to break the
47+
;; route at specific points and even helps locate accommodations for
48+
;; overnight stays.
4549

46-
;; - is based on Clerk, a notebook library for Clojure
50+
;; Rando-planner takes a different approach. It assumes you already
51+
;; have a GPX file of your route and focuses exclusively on the second
52+
;; challenge: planning your journey in detail.
4753

48-
;; Traditional tools (such as Komoot, Strava, Cycle.travel, etc.)
49-
;; focus on planning the route itself. Komoot offers an extra tool to
50-
;; divide the route into multiple days, but they distribute distance
51-
;; uniformly across the days. Cycle.travel allows to break down the
52-
;; route at arbitrary points (and helps finding accomodation for the
53-
;; night).
54+
;; With rando-planner, users can divide the route into individual
55+
;; activities or daily plans. The tool provides visualization tools to
56+
;; assess daily effort with greater precision and compare various
57+
;; strategies for covering the distance effectively.
5458

55-
;; rando-planner provides different types of visualization that can be
56-
;; used to study different strategies to cover the distance.
5759

5860
;; This page has been composed with Clerk and rando-planner
5961

@@ -63,17 +65,18 @@
6365

6466
;; ## Features
6567

66-
;; - Schematic visualization of the plan, that includes:
67-
;; - running count of kilometers
68-
;; - elevation
69-
;; - scheduled pauses
70-
;; - total amount of kilometers accumulated every day
71-
;; - sunrise and sunset indicators (WIP)
72-
73-
;; - Map visualization (based
74-
;; on [Leaflet](https://github.com/Leaflet/Leaflet)) of the route,
75-
;; with markers corresponding to the location reached after each day
76-
;; is completed.
68+
;; - Schematic Visualization of the Plan
69+
;; - Displays a comprehensive overview of your route, including:
70+
;; - Running count of kilometers.
71+
;; - Elevation profile.
72+
;; - Scheduled pauses.
73+
;; - Total distance accumulated daily.
74+
;; - Sunrise and sunset indicators (currently a work in progress).
75+
;; - Daily Elevation Visualization
76+
;; - Provides a focused view of the elevation profile for each day, helping you gauge the effort required for specific segments of the route.
77+
;; - Map Visualization
78+
;; - Interactive mapping powered by Leaflet.
79+
;; - Highlights the route with markers indicating the location reached at the end of each day.
7780

7881
;; ## Usage example
7982

@@ -226,7 +229,7 @@ be morale-crushing."]])
226229
;; end of the first day. Intermediate markers, when clicked, display a
227230
;; popup that shows the label of the day that _ends_ there, and the
228231
;; amount of kilometers planned for that day. With this information,
229-
;; you can use other tools to find accomodation or other services
232+
;; you can use other tools to find accommodation or other services
230233
;; you're going to need on the road.
231234

232235
;; Here the new map, this time displayed taking advantage of all the
@@ -258,18 +261,24 @@ be morale-crushing."]])
258261
;; - `:gpx`: This key refers to the location of a GPX (GPS Exchange
259262
;; Format) file
260263

261-
;; - `:average-speed`: This key represents the average speed
262-
;; maintained during the activities. The value associated with this
263-
;; key is expected to be a numerical value denoting speed, expressed
264-
;; as km/h
264+
;; - `:average-speed` [Optional]: When appears only at this level,
265+
;; this key represents the average speed maintained during all the
266+
;; activities. The value associated with this key is expected to be
267+
;; a numerical value denoting speed, expressed as km/h. If
268+
;; `:average-speed` is used in a daily-plan (see below) then that
269+
;; value overrides this option.
265270

266-
;; - `:daily-plans`: This key holds a vector of daily plans. Each
267-
;; daily plan is represented as a map containing information about
268-
;; activities planned for a single day. Inside each element in the
269-
;; vector:
271+
;; - `:daily-plans` [Optional]: This key holds a vector of daily
272+
;; plans. If no daily-plans is provided, rando-planner will use a
273+
;; default value (one single activity, long enough to cover the
274+
;; entire distance). Each daily plan is represented as a map
275+
;; containing information about activities planned for a single
276+
;; day. Inside each element in the vector:
270277

271278
;; - `:date`: This key denotes the date of the daily plan in the format "YYYY-MM-DD". It is used to compute the sun rise and set times.
272279
;; - `:label`: An arbitrary string, a label or description of the daily plan
280+
;; - `:average-speed' [Optional]: The value associated with this key is expected to be
281+
;; a numerical value denoting speed, expressed as km/h.
273282
;; - `:activities`: This key holds a vector of activities planned for the day. Each activity is represented as a map containing:
274283
;; - `:start`: This key denotes the starting time of an activity, in the format "HH:mm"
275284
;; - `:type`: This key specifies the type of activity. At the moment only the type "ride" is in use. This key is reserved for future uses

src/rando_planner/diagram.clj

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,23 @@
158158
:dominant-baseline "hanging"
159159
:fill (get-from-palette :elevation-legend-stroke)}
160160
(str "" (Math/floor (:elevation d)) " m")]
161+
[:text {:x (+ dx1 2)
162+
:y 39
163+
:font-family "Fira Sans"
164+
:font-size "60%"
165+
:dominant-baseline "hanging"
166+
:fill (get-from-palette :elevation-legend-stroke)}
167+
(str "🚄 " (:average-speed d) " km/h")]
161168
[:rect {:x dx1
162-
:y 0
163-
:width dx2 :height bottom-right-y
164-
:fill (get-alternating-background!)
165-
:fill-opacity 0.4}]
169+
:y 0
170+
:width dx2 :height bottom-right-y
171+
:fill (get-alternating-background!)
172+
:fill-opacity 0.4}]
166173
(when (:pauses d)
167174
(for [p (:pauses d)]
168175
(let [{px :x} (pointspace-to-viewbox-space
169176
{:x (+ (:covered d)
170-
(* average-speed
177+
(* (:average-speed d)
171178
(- (:after p)
172179
(:cumulative-pause p))))
173180
:y 0 ; not important, not used
@@ -286,7 +293,7 @@
286293

287294
(defn day-plan->svg [plan index km center]
288295
(let [day-plan (nth (:daily-plans plan) index)
289-
average-speed (:average-speed plan)
296+
average-speed (plan/average-speed day-plan plan)
290297
elevation (gpx/elevation (:gpx plan))
291298
pauses (plan/pauses day-plan)
292299
main-offset (* (/ km average-speed) box-size)

src/rando_planner/plan.clj

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
(tick/>> (tick/time start)
1414
(tick/new-duration n :hours)))
1515

16+
(def default-average-speed 18)
17+
18+
(defn average-speed
19+
([day-plan] (or (:average-speed day-plan)
20+
default-average-speed))
21+
([day-plan plan] (or (:average-speed day-plan)
22+
(:average-speed plan)
23+
default-average-speed)))
24+
1625
(defn kilometers-in-a-day [day-plan average-speed]
1726
(reduce + (map #(* (:length %) average-speed)
1827
(filter #(= (:type %) :ride)
@@ -54,8 +63,7 @@
5463
"Given a plan, it returns a vector of structures containing how many
5564
kilometers are done in each day, and from what kilometer each day starts"
5665
[plan]
57-
(let [default-average-speed 20
58-
default-daily-plans [{:date (str (tick/today))
66+
(let [default-daily-plans [{:date (str (tick/today))
5967
:label "_day0"
6068
:activities [{:start "05:00"
6169
:type :ride
@@ -71,12 +79,13 @@
7179
acc-km 0
7280
i 0]
7381
(if (< i (count daily-plans))
74-
(let [km (kilometers-in-a-day (nth daily-plans i)
75-
(or (:average-speed plan)
76-
default-average-speed))]
82+
(let [daily-plan (nth daily-plans i)
83+
average-speed (average-speed daily-plan plan)
84+
km (kilometers-in-a-day daily-plan average-speed)]
7785
(recur (conj result
7886
{:day (+ 1 i)
7987
:label (:label (nth daily-plans i))
88+
:average-speed average-speed
8089
:kilometers km
8190
:covered acc-km
8291
:elevation (gpx/elevation-gain elevation
@@ -91,7 +100,7 @@
91100
(gpx/points (:gpx plan)))]
92101
(map (fn [d]
93102
(filter #(and (>= (:cumulative-distance %)
94-
(:covered d))
103+
(:covered d))
95104
(< (:cumulative-distance %)
96105
(+ (:covered d)
97106
(:kilometers d))))
@@ -104,6 +113,7 @@
104113
105114
:day
106115
:cumulative-distance
116+
:average-speed
107117
:elevation
108118
:ele
109119
:label
@@ -118,11 +128,11 @@
118128
gpx/with-cumulative-distance)
119129
daily-distance (daily-distance plan)
120130
points-at-end-of-days (for [dk daily-distance]
121-
(first (filter (fn [p]
122-
(> (:cumulative-distance p)
123-
(+ (:covered dk)
124-
(:kilometers dk))))
125-
points-with-cumulative-distance)))
131+
(first (filter (fn [p]
132+
(> (:cumulative-distance p)
133+
(+ (:covered dk)
134+
(:kilometers dk))))
135+
points-with-cumulative-distance)))
126136
daily-pauses (vec (map
127137
(fn [pauses]
128138
{:pauses pauses})

0 commit comments

Comments
 (0)