From a1d65817f1c6daf87860c0ff3b38e886c4e3a83b Mon Sep 17 00:00:00 2001 From: Martin Kobetic Date: Mon, 20 Jan 2025 09:11:17 -0500 Subject: [PATCH] wip --- main.go | 6 +- map.go | 46 +- samples/out/160525-2h21-16.1nm.gpx | 290 + samples/out/160525-2h21-16.1nm.svg | 6003 +++++-------------- samples/out/160525-2h21-16.1nm.vtt | 4362 +++++++------- samples/out/160601-1h11-06.8nm.gpx | 104 + samples/out/160601-1h11-06.8nm.svg | 2285 ++----- samples/out/160601-1h11-06.8nm.vtt | 1120 ++-- samples/out/160604-1h23-04.9nm.gpx | 74 + samples/out/160604-1h23-04.9nm.svg | 2085 ++----- samples/out/160604-1h23-04.9nm.vtt | 1096 ++-- samples/out/160605-3h01-23.1nm.gpx | 212 + samples/out/160605-3h01-23.1nm.svg | 8821 +++++++--------------------- samples/out/160605-3h01-23.1nm.vtt | 6746 ++++++++++----------- samples/out/160622-2h29-18.6nm.gpx | 220 + samples/out/160622-2h29-18.6nm.svg | 6494 +++++--------------- samples/out/160622-2h29-18.6nm.vtt | 4966 ++++++++-------- samples/out/160726-0h42-04.0nm.gpx | 22 + samples/out/160726-0h42-04.0nm.svg | 920 +-- samples/out/160726-0h42-04.0nm.vtt | 70 +- samples/out/160808-0h13-01.6nm.gpx | 20 + samples/out/160808-0h13-01.6nm.svg | 379 +- samples/out/160808-0h13-01.6nm.vtt | 16 +- samples/out/160817-0h59-04.4nm.gpx | 58 + samples/out/160817-0h59-04.4nm.svg | 1588 +---- samples/out/160817-0h59-04.4nm.vtt | 924 +-- samples/out/160820-1h12-10.1nm.gpx | 100 + samples/out/160820-1h12-10.1nm.svg | 2082 +------ samples/out/160820-1h12-10.1nm.vtt | 486 +- samples/out/160824-2h04-14.8nm.gpx | 198 + samples/out/160824-2h04-14.8nm.svg | 5418 +++++------------ samples/out/160824-2h04-14.8nm.vtt | 3996 ++++++------- segment.go | 26 +- segment_test.go | 10 +- test_utils.go | 4 +- 35 files changed, 21056 insertions(+), 40191 deletions(-) diff --git a/main.go b/main.go index 5362b93..0673742 100644 --- a/main.go +++ b/main.go @@ -67,13 +67,13 @@ func main() { fmt.Printf("Error opening %s: %s\n", fn, err) return } - segments = append(segments, GetSegments(g, filepath.Base(fn))...) + segments = append(segments, gpxGetSegments(g, filepath.Base(fn))...) } sort.Sort(segments) sn := len(segments) - segments = segments.Dedupe(20).Split(time.Hour).Dedupe(20) + segments = segments.gpxDedupe(20).gpxSplit(time.Hour).gpxDedupe(20) fmt.Printf("Dropped %d duplicate and bogus segments\n", sn-len(segments)) - for _, t := range segments.Tracks(time.Hour) { + for _, t := range segments.gpxTracks(time.Hour) { t.Analyze(Sailing) // if windDirection != nil { // t.Analyze(*windDirection) diff --git a/map.go b/map.go index a20af6b..a2ad039 100644 --- a/map.go +++ b/map.go @@ -127,31 +127,29 @@ func (m *Map) renderSubtitles(w io.Writer, t *Track, videoOffset time.Duration) currentOffset := videoOffset totalDistance := float64(0) cueCounter := 0 - for _, s := range t.Segments { - s.gpxEachPair(func(prev, next *gpx.GPXPoint) { - duration := next.Timestamp.Sub(prev.Timestamp) - newOffset := currentOffset + duration - if newOffset < 0 { - currentOffset = newOffset - return - } - cueCounter++ - totalDistance += m.Distance(prev, next, nm) - heading := m.Heading(prev, next) - direction := Direction(heading) - fmt.Fprintf(w, "%d\n", cueCounter) - fmt.Fprintf(w, "%s --> %s\n", vttTimestamp(currentOffset), vttTimestamp(newOffset)) - fmt.Fprintf(w, "%s: %0.1f m @ %0.1f kts \u2191 %d\u00b0 %s = %0.2f nm\n", - next.Timestamp.In(t.Timezone()).Format(time.TimeOnly), - m.Distance(prev, next, meter), - m.Speed(prev, next, nm), - heading, - direction.String(), - totalDistance) - fmt.Fprintln(w) + t.Segments.EachPair(func(prev, next *Point) { + duration := next.gpx.Timestamp.Sub(prev.gpx.Timestamp) + newOffset := currentOffset + duration + if newOffset < 0 { currentOffset = newOffset - }) - } + return + } + cueCounter++ + totalDistance += next.Distance + heading := next.Heading + direction := Direction(heading) + fmt.Fprintf(w, "%d\n", cueCounter) + fmt.Fprintf(w, "%s --> %s\n", vttTimestamp(currentOffset), vttTimestamp(newOffset)) + fmt.Fprintf(w, "%s: %0.1f m @ %0.1f kts \u2191 %d\u00b0 %s = %0.2f nm\n", + next.gpx.Timestamp.In(t.Timezone()).Format(time.TimeOnly), + next.Distance, + next.Speed, + heading, + direction.String(), + totalDistance/1852) + fmt.Fprintln(w) + currentOffset = newOffset + }) } func vttTimestamp(ts time.Duration) string { diff --git a/samples/out/160525-2h21-16.1nm.gpx b/samples/out/160525-2h21-16.1nm.gpx index 8140e71..b27078f 100644 --- a/samples/out/160525-2h21-16.1nm.gpx +++ b/samples/out/160525-2h21-16.1nm.gpx @@ -205,6 +205,8 @@ 58.77771 + + 59.258423 @@ -213,6 +215,8 @@ 59.258423 + + 60.219727 @@ -241,6 +245,8 @@ 61.18103 + + 61.18103 @@ -277,6 +283,8 @@ 62.142334 + + 61.661743 @@ -361,6 +369,8 @@ 62.622925 + + 62.622925 @@ -389,6 +399,8 @@ 62.622925 + + 62.622925 @@ -401,6 +413,8 @@ 62.142334 + + 62.142334 @@ -437,6 +451,8 @@ 63.584351 + + 63.584351 @@ -473,6 +489,8 @@ 61.661743 + + 61.661743 @@ -493,6 +511,8 @@ 62.142334 + + 62.622925 @@ -521,6 +541,8 @@ 62.622925 + + 62.622925 @@ -541,6 +563,8 @@ 61.661743 + + 61.18103 @@ -573,6 +597,8 @@ 61.18103 + + 61.18103 @@ -743,6 +769,8 @@ 63.103638 + + 63.103638 @@ -775,6 +803,8 @@ 62.622925 + + 63.103638 @@ -783,6 +813,8 @@ 63.103638 + + 63.103638 @@ -819,6 +851,8 @@ 62.622925 + + 62.622925 @@ -835,6 +869,8 @@ 62.622925 + + 62.622925 @@ -937,6 +973,8 @@ 62.142334 + + 62.622925 @@ -961,6 +999,8 @@ 62.622925 + + 62.622925 @@ -1057,6 +1097,8 @@ 62.142334 + + 61.18103 @@ -1085,6 +1127,8 @@ 60.219727 + + 60.219727 @@ -1117,6 +1161,8 @@ 62.142334 + + 62.622925 @@ -1133,6 +1179,8 @@ 63.584351 + + 63.584351 @@ -1189,6 +1237,8 @@ 63.103638 + + 63.103638 @@ -1213,6 +1263,8 @@ 61.18103 + + 60.700317 @@ -1285,6 +1337,8 @@ 60.700317 + + 60.700317 @@ -1305,6 +1359,8 @@ 58.77771 + + 58.297119 @@ -1313,6 +1369,8 @@ 58.297119 + + 58.297119 @@ -1341,6 +1399,8 @@ 60.219727 + + 59.739136 @@ -1373,6 +1433,8 @@ 58.77771 + + 58.77771 @@ -1409,6 +1471,8 @@ 61.18103 + + 61.661743 @@ -1477,6 +1541,8 @@ 63.103638 + + 63.584351 @@ -1505,6 +1571,8 @@ 61.661743 + + 61.18103 @@ -1549,6 +1617,8 @@ 60.700317 + + 59.739136 @@ -1581,6 +1651,8 @@ 60.700317 + + 61.18103 @@ -1597,6 +1669,8 @@ 60.700317 + + 60.700317 @@ -1605,6 +1679,8 @@ 60.700317 + + 60.700317 @@ -1665,6 +1741,8 @@ 56.374512 + + 55.893799 @@ -1685,6 +1763,8 @@ 57.335815 + + 57.816528 @@ -1777,6 +1857,8 @@ 61.18103 + + 62.142334 @@ -1793,6 +1875,8 @@ 61.18103 + + 60.700317 @@ -1825,6 +1909,8 @@ 58.77771 + + 59.739136 @@ -1849,6 +1935,8 @@ 61.661743 + + 61.661743 @@ -1865,6 +1953,8 @@ 61.18103 + + 61.18103 @@ -1987,6 +2077,8 @@ 60.219727 + + 60.219727 @@ -2023,6 +2115,8 @@ 59.739136 + + 59.739136 @@ -2055,6 +2149,8 @@ 58.77771 + + 58.297119 @@ -2067,6 +2163,8 @@ 57.816528 + + 59.258423 @@ -2075,6 +2173,8 @@ 60.219727 + + 60.219727 @@ -2087,6 +2187,8 @@ 60.219727 + + 60.219727 @@ -2107,6 +2209,8 @@ 58.77771 + + 58.77771 @@ -2147,6 +2251,8 @@ 60.219727 + + 60.219727 @@ -2183,6 +2289,8 @@ 59.739136 + + 59.739136 @@ -2249,6 +2357,8 @@ 62.142334 + + 63.103638 @@ -2261,6 +2371,8 @@ 64.545654 + + 65.026367 @@ -2285,6 +2397,8 @@ 62.142334 + + 61.18103 @@ -2309,6 +2423,8 @@ 55.413086 + + 53.971191 @@ -2333,6 +2449,8 @@ 56.855103 + + 56.374512 @@ -2369,6 +2487,8 @@ 60.700317 + + 60.700317 @@ -2401,6 +2521,8 @@ 61.18103 + + 61.18103 @@ -2437,6 +2559,8 @@ 64.065063 + + 64.065063 @@ -2449,6 +2573,8 @@ 64.545654 + + 65.026367 @@ -2465,6 +2591,8 @@ 65.026367 + + 64.545654 @@ -2489,6 +2617,8 @@ 66.948975 + + 66.948975 @@ -2513,6 +2643,8 @@ 65.026367 + + 64.545654 @@ -2541,6 +2673,8 @@ 62.142334 + + 61.661743 @@ -2605,6 +2739,8 @@ 61.18103 + + 60.700317 @@ -2641,6 +2777,8 @@ 62.622925 + + 62.142334 @@ -2673,6 +2811,8 @@ 65.50708 + + 65.50708 @@ -2701,6 +2841,8 @@ 64.545654 + + 65.026367 @@ -2729,6 +2871,8 @@ 61.661743 + + 61.661743 @@ -2777,6 +2921,8 @@ 59.739136 + + 59.739136 @@ -2805,6 +2951,8 @@ 62.142334 + + 63.103638 @@ -2813,6 +2961,8 @@ 63.584351 + + 64.545654 @@ -2825,6 +2975,8 @@ 63.584351 + + 63.584351 @@ -2833,6 +2985,8 @@ 63.584351 + + 63.103638 @@ -2853,6 +3007,8 @@ 61.661743 + + 61.661743 @@ -2873,6 +3029,8 @@ 59.258423 + + 58.77771 @@ -2925,6 +3083,8 @@ 59.258423 + + 59.739136 @@ -2937,6 +3097,8 @@ 61.18103 + + 62.142334 @@ -2961,6 +3123,8 @@ 59.258423 + + 58.77771 @@ -3033,6 +3197,8 @@ 59.258423 + + 59.258423 @@ -3061,6 +3227,8 @@ 61.661743 + + 62.622925 @@ -3093,6 +3261,8 @@ 62.142334 + + 62.622925 @@ -3105,6 +3275,8 @@ 63.103638 + + 63.103638 @@ -3125,6 +3297,8 @@ 61.18103 + + 61.18103 @@ -3137,6 +3311,8 @@ 61.661743 + + 61.18103 @@ -3173,6 +3349,8 @@ 59.739136 + + 59.739136 @@ -3205,6 +3383,8 @@ 57.335815 + + 57.335815 @@ -3221,6 +3401,8 @@ 58.297119 + + 58.77771 @@ -3277,6 +3459,8 @@ 58.297119 + + 57.816528 @@ -3297,6 +3481,8 @@ 58.77771 + + 58.77771 @@ -3309,6 +3495,8 @@ 58.297119 + + 58.297119 @@ -3337,6 +3525,8 @@ 58.297119 + + 58.297119 @@ -3409,6 +3599,8 @@ 60.219727 + + 59.739136 @@ -3433,6 +3625,8 @@ 62.142334 + + 63.103638 @@ -3489,6 +3683,8 @@ 61.661743 + + 61.661743 @@ -3537,6 +3733,8 @@ 58.297119 + + 57.816528 @@ -3585,6 +3783,8 @@ 56.855103 + + 56.855103 @@ -3605,6 +3805,8 @@ 58.297119 + + 58.77771 @@ -3653,6 +3855,8 @@ 59.258423 + + 59.258423 @@ -3681,6 +3885,8 @@ 59.258423 + + 58.77771 @@ -3721,6 +3927,8 @@ 58.297119 + + 58.297119 @@ -3765,6 +3973,8 @@ 61.661743 + + 63.103638 @@ -3837,6 +4047,8 @@ 64.545654 + + 64.545654 @@ -3869,6 +4081,8 @@ 60.700317 + + 59.739136 @@ -3893,6 +4107,8 @@ 56.855103 + + 56.855103 @@ -3901,6 +4117,8 @@ 56.855103 + + 57.335815 @@ -3991,6 +4209,8 @@ 60.219727 + + 60.700317 @@ -3999,6 +4219,8 @@ 60.700317 + + 60.700317 @@ -4023,6 +4245,8 @@ 59.739136 + + 59.739136 @@ -4031,6 +4255,8 @@ 59.739136 + + 58.77771 @@ -4071,6 +4297,8 @@ 59.739136 + + 59.739136 @@ -4083,6 +4311,8 @@ 60.219727 + + 59.739136 @@ -4091,6 +4321,8 @@ 59.258423 + + 59.258423 @@ -4131,6 +4363,8 @@ 59.258423 + + 59.258423 @@ -4159,6 +4393,8 @@ 58.297119 + + 58.77771 @@ -4231,6 +4467,8 @@ 60.219727 + + 59.739136 @@ -4259,6 +4497,8 @@ 60.219727 + + 60.219727 @@ -4275,6 +4515,8 @@ 60.700317 + + 57.816528 @@ -4287,6 +4529,8 @@ 57.816528 + + 58.297119 @@ -4323,6 +4567,8 @@ 59.258423 + + 59.739136 @@ -4359,6 +4605,8 @@ 58.297119 + + 58.297119 @@ -4391,6 +4639,8 @@ 59.739136 + + 60.219727 @@ -4411,6 +4661,8 @@ 60.219727 + + 59.739136 @@ -4443,6 +4695,8 @@ 60.219727 + + 60.219727 @@ -4463,6 +4717,8 @@ 59.739136 + + 60.219727 @@ -4483,6 +4739,8 @@ 61.661743 + + 61.661743 @@ -4507,6 +4765,8 @@ 60.700317 + + 60.219727 @@ -4531,6 +4791,8 @@ 58.77771 + + 58.77771 @@ -4539,6 +4801,8 @@ 59.258423 + + 58.77771 @@ -4555,6 +4819,8 @@ 58.297119 + + 58.297119 @@ -4571,6 +4837,8 @@ 60.700317 + + 60.700317 @@ -4583,6 +4851,8 @@ 60.700317 + + 60.219727 @@ -4623,6 +4893,8 @@ 61.661743 + + 61.661743 @@ -4727,6 +4999,8 @@ 62.142334 + + 62.142334 @@ -4751,6 +5025,8 @@ 61.18103 + + 60.219727 @@ -4831,6 +5107,8 @@ 57.816528 + + 57.335815 @@ -4855,6 +5133,8 @@ 59.739136 + + 59.739136 @@ -4879,6 +5159,8 @@ 58.77771 + + 59.258423 @@ -4903,6 +5185,8 @@ 58.77771 + + 58.77771 @@ -4927,6 +5211,8 @@ 57.816528 + + 57.816528 @@ -4955,6 +5241,8 @@ 60.700317 + + 61.661743 @@ -4979,6 +5267,8 @@ 61.661743 + + 61.18103 diff --git a/samples/out/160525-2h21-16.1nm.svg b/samples/out/160525-2h21-16.1nm.svg index 2b28d65..8d5ab39 100644 --- a/samples/out/160525-2h21-16.1nm.svg +++ b/samples/out/160525-2h21-16.1nm.svg @@ -1,5 +1,6 @@ - +