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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package main
import (
"database/sql"
"flag"
"log/slog"
"os"
"runtime/pprof"
"time"
mountainpass "github.com/martinlehoux/biking_home/mountain_pass"
"github.com/martinlehoux/biking_home/ride"
"github.com/martinlehoux/kagamigo/kcore"
_ "github.com/mattn/go-sqlite3"
)
var (
download = flag.Bool("download", false, "download mountain passes into the database")
resume = flag.Bool("resume", false, "skip departments already cached on disk")
demo = flag.Bool("demo", false, "run the climb similarity demo")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
parser = ride.GPXRideParser{}
)
func main() {
flag.Parse()
if *download {
runDownload()
return
}
if *demo {
runDemo()
}
}
func runDownload() {
db, err := sql.Open("sqlite3", "biking_home.db")
kcore.Expect(err, "failed to open database")
defer db.Close()
err = mountainpass.DownloadMountainPasses(db, 5*time.Second, *resume)
kcore.Expect(err, "failed to download mountain passes")
}
func runDemo() {
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
kcore.Expect(err, "failed to create CPU profile")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
ride19Jan, _ := ride.ParseFile(parser, "examples/activity_18043356988.gpx")
ride30Mar, _ := ride.ParseFile(parser, "examples/activity_18679866717.gpx")
ride20Apr, _ := ride.ParseFile(parser, "examples/activity_18880605641.gpx")
for _, r := range []*ride.Ride{&ride19Jan, &ride30Mar, &ride20Apr} {
slog.Info("Ride", "difficulty", r.DifficultyScore())
}
index := ride.NewFlatRideClimbsIndex(30)
index.Insert(ride19Jan)
index.Insert(ride30Mar)
for _, climb := range ride20Apr.AllClimbs() {
slog.Info("Climb", "climb", climb, "duration", climb.Duration(), "speed", climb.Speed()*3.6)
if len(index.Similar(ride20Apr, climb)) > 0 {
for _, similar := range index.Similar(ride20Apr, climb) {
slog.Info("Similar", "climb", similar, "duration", similar.Duration(), "speed", similar.Speed()*3.6)
}
}
}
for _, climb := range ride30Mar.AllClimbs() {
slog.Info("Climb", "climb", climb, "duration", climb.Duration(), "speed", climb.Speed()*3.6)
}
ride.PlotScore(&ride30Mar, 61.2, 66.7, "Ride 30 Mar.png")
}
|