Skip to content

Commit

Permalink
Show uphill / downhill for tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
jlelse committed Jul 7, 2024
1 parent 83606c0 commit 04063ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
25 changes: 22 additions & 3 deletions geoTrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type trackResult struct {
PointsJSON string
Kilometers string
Hours string
Uphill string
Downhill string
Name string
MapAttribution string
MinZoom, MaxZoom int
Expand Down Expand Up @@ -92,6 +94,11 @@ func (a *goBlog) getTrack(p *post, withMapFeatures bool) (result *trackResult, e
)
}

if parseResult.ud != nil {
result.Uphill = lp.Sprintf("%.0f", parseResult.ud.Uphill)
result.Downhill = lp.Sprintf("%.0f", parseResult.ud.Downhill)
}

return result, nil
}

Expand All @@ -104,14 +111,16 @@ type trackParseResult struct {
points []*trackPoint
gpxData *gpx.GPX
md *gpx.MovingData
ud *gpx.UphillDownhill
}

func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
result = &trackParseResult{}

type trackPath struct {
gpxMovingData *gpx.MovingData
points []*trackPoint
gpxMovingData *gpx.MovingData
gpxUphillDownhill *gpx.UphillDownhill
points []*trackPoint
}

result.gpxData, err = gpx.ParseString(gpxString)
Expand All @@ -123,8 +132,10 @@ func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
for _, track := range result.gpxData.Tracks {
for _, segment := range track.Segments {
md := segment.MovingData()
ud := segment.UphillDownhill()
path := &trackPath{
gpxMovingData: &md,
gpxMovingData: &md,
gpxUphillDownhill: &ud,
}
for _, point := range segment.Points {
path.points = append(path.points, &trackPoint{
Expand Down Expand Up @@ -158,6 +169,14 @@ func trackParseGPX(gpxString string) (result *trackParseResult, err error) {
result.md.StoppedDistance = result.md.StoppedDistance + path.gpxMovingData.StoppedDistance
result.md.StoppedTime = result.md.StoppedTime + path.gpxMovingData.StoppedTime
}
// Combine uphill/downhill
if path.gpxUphillDownhill != nil {
if result.ud == nil {
result.ud = &gpx.UphillDownhill{}
}
result.ud.Uphill = result.ud.Uphill + path.gpxUphillDownhill.Uphill
result.ud.Downhill = result.ud.Downhill + path.gpxUphillDownhill.Downhill
}
}

result.points = []*trackPoint{}
Expand Down
1 change: 1 addition & 0 deletions strings/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ locationnotsupported: "Die Standort-API wird von diesem Browser nicht unterstüt
mediafiles: "Medien-Dateien"
message: "Nachricht"
messagesent: "Nachricht gesendet"
meters: "Meter"
next: "Weiter"
nofiles: "Keine Dateien"
nolocations: "Keine Posts mit Standorten"
Expand Down
1 change: 1 addition & 0 deletions strings/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ logout: "Logout"
mediafiles: "Media files"
message: "Message"
messagesent: "Message sent"
meters: "meters"
nameopt: "Name (optional)"
next: "Next"
nofiles: "No files"
Expand Down
18 changes: 14 additions & 4 deletions uiComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,29 @@ func (a *goBlog) renderPostGPX(hb *htmlbuilder.HtmlBuilder, p *post, b *configBl
hb.WriteElementOpen("strong")
hb.WriteEscaped(track.Name)
hb.WriteElementClose("strong")
hb.WriteUnescaped(" ")
}
if track.Kilometers != "" {
hb.WriteUnescaped("🏁 ")
hb.WriteUnescaped(" 🏁 ")
hb.WriteEscaped(track.Kilometers)
hb.WriteUnescaped(" ")
hb.WriteEscaped(a.ts.GetTemplateStringVariant(b.Lang, "kilometers"))
hb.WriteUnescaped(" ")
}
if track.Hours != "" {
hb.WriteUnescaped("⏱ ")
hb.WriteUnescaped(" ⏱ ")
hb.WriteEscaped(track.Hours)
}
if track.Uphill != "" {
hb.WriteUnescaped(" ⬆️ ")
hb.WriteEscaped(track.Uphill)
hb.WriteUnescaped(" ")
hb.WriteEscaped(a.ts.GetTemplateStringVariant(b.Lang, "meters"))
}
if track.Downhill != "" {
hb.WriteUnescaped(" ⬇️ ")
hb.WriteEscaped(track.Downhill)
hb.WriteUnescaped(" ")
hb.WriteEscaped(a.ts.GetTemplateStringVariant(b.Lang, "meters"))
}
hb.WriteElementClose("p")
// Map (only show if it has features)
if track.hasMapFeatures() {
Expand Down

0 comments on commit 04063ae

Please sign in to comment.