-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers_test.go
149 lines (132 loc) · 3.96 KB
/
handlers_test.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package catTrackslib
import (
"encoding/json"
"os"
"testing"
"time"
"github.com/paulmach/orb/geojson"
"github.com/rotblauer/tileTester2/note"
)
func TestValidVisitGrabbing(t *testing.T) {
exampleNotesValidVisit := `{"floorsAscended":0,"customNote":"","currentTripStart":"2018-11-08T12:50:08.458Z","floorsDescended":0,"averageActivePace":3.100616996616512,"numberOfSteps":25,"visit":"{\"place\":\"25 Yeadon Ave, 25 Yeadon Ave, Charleston, SC 29407, United States @ <+32.78044829,-79.98285770> +\\\/- 100.00m, region CLCircularRegion (identifier:'<+32.78044828,-79.98285770> radius 141.76', center:<+32.78044828,-79.98285770>, radius:141.76m)\",\"arrivalDate\":\"2018-11-08T13:20:50.999Z\",\"validVisit\":true,\"departureDate\":\"4001-01-01T00:00:00.000Z\"}","relativeAltitude":-11.805885314941406,"currentCadence":0,"activity":"Stationary","currentPace":0,"pressure":101.96843719482422,"distance":19.160000000032596}`
// Mon Jan 2 15:04:05 -0700 MST 2006
// tt, err := time.Parse("2006-01-02T15:04:05", "2018-11-08T13:20:50.999Z")
tt, err := time.Parse(time.RFC3339Nano, "2018-11-08T13:20:50.999Z")
if err != nil {
t.Fatal("err", err)
}
t.Log(tt)
// Rye8 38.633697509765625 -90.26709747314453 0 0 -1 0 -1 0 2018-11-08 13:30:52.85 +0000 UTC {"floorsAs
tp := TrackPoint{
Uuid: "9B4843BB-0EF7-4B54-832A-B6940304C531",
ID: 1541683852850000000,
Name: "tester",
Lat: 38.633697509765625,
Lng: -90.26709747314453,
Accuracy: 0,
Elevation: 0,
Speed: -1,
Tilt: 0,
Heading: -1,
HeartRate: 0,
Time: time.Now(),
Notes: exampleNotesValidVisit,
}
sn, err := note.NotesField(tp.Notes).AsNoteStructured()
if err != nil {
t.Error("err", err)
}
if !sn.HasValidVisit() {
t.Error("invalid visit")
}
visit, err := sn.Visit.AsVisit()
if err != nil {
t.Error("err", err)
}
pl, err := visit.Place.AsPlace()
if err != nil {
t.Error(err)
}
t.Log("visit", visit)
t.Log("place", pl)
}
func TestTimeZeroing(t *testing.T) {
tim := time.Unix(0, 0)
t.Log(tim.IsZero())
var tim2 time.Time
t.Log(tim2.IsZero())
}
func TestDecodeAnythingToGeoJSON(t *testing.T) {
validate := func(got []*geojson.Feature, err error) error {
if err != nil {
return err
}
for _, f := range got {
if err := validatePoint(f); err != nil {
return err
}
}
return nil
}
for _, f := range []string{
"testdata/ia.json",
"testdata/rye.json",
"testdata/trackpoints.json",
"testdata/trackpoints.geojson",
"testdata/trackpoints.featurecollection.geojson",
"testdata/trackpoints.nd.geojson",
"testdata/trackpoints.nd.json",
} {
t.Run(f, func(t *testing.T) {
data, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
got, err := DecodeAnythingToGeoJSON(data)
if err := validate(got, err); err != nil {
t.Error(err)
}
if t.Failed() {
j, _ := json.MarshalIndent(got, "", " ")
t.Log(string(j))
}
})
}
// t.Log("ND GeoJSON")
// ndGeoJSONFile := "testdata/trackpoints.nd.geojson"
// ndData, err := os.ReadFile(ndGeoJSONFile)
// if err != nil {
// t.Fatal(err)
// }
// got, err := DecodeAnythingToGeoJSON(ndData)
// validate(got, err)
//
// t.Log("GeoJSON FeatureCollection")
// geoJSONFCFile := "testdata/trackpoints.featurecollection.geojson"
// geoJSONFCData, err := os.ReadFile(geoJSONFCFile)
// if err != nil {
// t.Fatal(err)
// }
// got, err = DecodeAnythingToGeoJSON(geoJSONFCData)
// validate(got, err)
//
// t.Log("GeoJSON array")
// geoJSONFile := "testdata/trackpoints.geojson"
// geoJSONData, err := os.ReadFile(geoJSONFile)
// if err != nil {
// t.Fatal(err)
// }
// got, err = DecodeAnythingToGeoJSON(geoJSONData)
// validate(got, err)
//
// t.Log("Trackpoint array")
// trackpointsFile := "testdata/trackpoints.json"
// trackpointData, err := os.ReadFile(trackpointsFile)
// if err != nil {
// t.Fatal(err)
// }
// got, err = DecodeAnythingToGeoJSON(trackpointData)
// validate(got, err)
//
// // geoJSONFCFile := "testdata/trackpoints.geojson"
}