summaryrefslogtreecommitdiff
path: root/web/views.go
blob: 29f3c4f7043131ab7b45732cb704cce6b42b0827 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package web

import (
	"fmt"
	"time"

	"github.com/martinlehoux/biking_home/rides"
)

type RideView struct {
	rides.Ride
	Cotacol         string
	CotacolPer100Km string
}

type SyncPageData struct {
	From    string
	To      string
	Error   string
	Notice  string
	HasAuth bool
}

func formatRideDate(value time.Time) string {
	return value.Local().Format("02 Jan 2006, 15:04")
}

func formatDistance(meters float64) string {
	return fmt.Sprintf("%.1f km", meters/1000)
}

func formatDuration(seconds int64) string {
	hours := seconds / 3600
	minutes := (seconds % 3600) / 60
	return fmt.Sprintf("%dh %02dm", hours, minutes)
}

func formatElevation(meters float64) string {
	return fmt.Sprintf("%.0f m", meters)
}

func formatCotacol(score float64) string {
	return fmt.Sprintf("%.1f", score)
}

func formatCotacolPer100Km(score, distanceM float64) string {
	distanceKm := distanceM / 1000
	if distanceKm <= 0 {
		return "-"
	}
	return fmt.Sprintf("%.1f", score*100/distanceKm)
}