-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron.go
163 lines (139 loc) · 8.69 KB
/
cron.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package corvallisbus
import (
"appengine"
"appengine/datastore"
"appengine/runtime"
"net/http"
cts "github.com/cvanderschuere/go-connexionz"
)
func init() {
http.HandleFunc("/cron/init", CreateDatabase)
http.HandleFunc("/_ah/start", start)
}
func start(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
c.Infof("Started Instance")
}
// Sets up datastore to fit current structure -- removes all existing
func CreateDatabase(w http.ResponseWriter, r *http.Request) {
context := appengine.NewContext(r)
// Allows for unlimited time limit
runtime.RunInBackground(context, func(c appengine.Context) {
clearDatastore(c) //Delete everything
// Create CTS Client
client := cts.New(c, baseURL)
// Download all route patterns -- create blank stops & routes
addRoutes(client, c)
// Download platforms and update datastore
plats, _ := client.Platforms()
updatePlatforms(plats, c)
// Create map between platform tag and platform number -- GoogleTransit uses tag
// tag -> number (GT -> connexionz)
tagToNumber := make(map[int64]int64)
for _, p := range plats {
tagToNumber[p.Tag] = p.Number
}
// Create map between pattern names in Connexionz and GT (static for now)
// GT -> connexionz
nameMap := map[string]string{
"R1": "1",
"R2": "2",
"R3": "3",
"R4": "4",
"R5": "5",
"R6": "6",
"R7": "7",
"R8": "8",
"BB_N": "NON",
"BB_SE": "NOSE",
"BB_SW": "NOSW",
"C1": "C1",
"C2": "C2",
"C3": "C3",
"CVA": "CVA",
}
// Download/parse/input Google Transit
updateWithGoogleTransit(c, tagToNumber, nameMap)
fixPolylines(c) // FIXME -- this shouldn't be needed
})
}
//
// Internal functions for CRON
//
//Clears all information in datastore
func clearDatastore(c appengine.Context) error {
keys, err := datastore.NewQuery("").KeysOnly().GetAll(c, nil)
if err != nil || len(keys) == 0 {
return err
}
//Delete these keys
return datastore.DeleteMulti(c, keys)
}
//
// Temporary fix for mising polyline issue
//
func fixPolylines(c appengine.Context) {
var routes []*Route
keys, _ := datastore.NewQuery("Route").GetAll(c, &routes)
for i, route := range routes {
if route.Name == "5" {
route.Polyline = string([]byte{117, 96, 95, 111, 71, 122, 124, 105, 111, 86, 86,
99, 66, 116, 64, 90, 118, 65, 108, 64, 98, 69, 100, 66, 91, 110, 66, 87, 126, 65, 67, 80,
119, 64, 106, 69, 71, 102, 64, 105, 64, 100, 68, 103, 64, 126, 67, 79, 120, 64, 123, 65,
115, 64, 97, 66, 115, 64, 105, 69, 103, 66, 89, 110, 66, 65, 64, 89, 102, 66, 111, 64, 108,
69, 109, 64, 122, 68, 111, 64, 118, 68, 111, 64, 126, 68, 109, 64, 122, 68, 111, 64, 122,
68, 111, 64, 98, 69, 63, 63, 105, 65, 63, 105, 67, 66, 115, 70, 66, 107, 64, 64, 117, 64,
68, 95, 64, 63, 81, 63, 105, 65, 65, 121, 69, 72, 117, 66, 63, 111, 65, 64, 103, 67, 64,
123, 64, 64, 113, 66, 64, 117, 64, 63, 117, 64, 64, 111, 66, 66, 103, 69, 66, 125, 65, 64,
103, 64, 64, 113, 64, 64, 97, 64, 66, 89, 70, 83, 72, 85, 80, 109, 64, 106, 64, 99, 64, 86,
89, 78, 87, 68, 89, 64, 93, 63, 85, 63, 93, 65, 99, 68, 63, 121, 69, 63, 117, 64, 64, 125, 64,
64, 97, 68, 66, 115, 68, 63, 125, 64, 63, 103, 64, 63, 97, 74, 63, 105, 64, 63, 119, 71, 68,
123, 66, 63, 95, 64, 63, 121, 71, 68, 119, 64, 63, 87, 65, 123, 68, 63, 81, 64, 119, 64, 72, 117,
64, 76, 95, 64, 68, 67, 64, 79, 66, 83, 68, 63, 121, 65, 77, 125, 65, 81, 95, 66, 85, 113, 65, 91,
105, 65, 111, 64, 117, 66, 95, 64, 109, 65, 89, 97, 65, 75, 95, 64, 73, 87, 91, 103, 65, 83, 99,
65, 100, 66, 105, 64, 110, 64, 77, 112, 64, 69, 96, 65, 70, 110, 64, 78, 124, 64, 94, 122, 64,
108, 64, 112, 65, 106, 65, 98, 64, 90, 66, 63, 102, 64, 88, 94, 92, 88, 96, 64, 98, 64, 111, 64,
82, 91, 82, 88, 90, 76, 78, 66, 66, 64, 118, 65, 63, 122, 66, 65, 112, 65, 67, 92, 69, 74, 71,
76, 73, 118, 64, 95, 65, 88, 106, 64, 124, 64, 126, 65, 78, 90, 120, 64, 98, 66, 94, 112, 64, 86,
116, 64, 82, 118, 64, 80, 102, 65, 68, 96, 65, 63, 122, 64, 67, 102, 66, 116, 69, 63, 116, 68,
63, 100, 66, 63, 102, 64, 63, 106, 67, 63, 96, 68, 67, 110, 65, 67, 98, 64, 63, 120, 69, 63, 112, 64, 63,
110, 67, 64, 84, 63, 92, 63, 88, 65, 86, 69, 88, 79, 98, 64, 87, 108, 64, 107, 64, 84, 81, 82, 73, 88, 71, 96,
64, 67, 112, 64, 65, 100, 67, 67, 108, 67, 67, 120, 64, 63, 110, 66, 67, 106, 66, 65, 112, 66, 65, 122, 64, 65,
102, 67, 65, 100, 69, 65, 104, 65, 67, 110, 67, 69, 104, 65, 64, 112, 64, 63, 116, 64, 69, 106, 64, 65, 114, 70,
67, 102, 65, 65, 103, 65, 64, 89, 63, 88, 63, 78, 65, 79, 64, 124, 64, 65, 108, 64, 63, 102, 66, 65, 94, 123, 66, 78,
103, 65, 110, 64, 123, 68, 108, 64, 123, 68, 110, 64, 95, 69, 110, 64, 119, 68, 108, 64, 123, 68, 84, 121, 65, 88, 115,
66, 88, 103, 66, 90, 113, 66, 116, 64, 115, 69, 118, 64, 115, 69, 80, 101, 65, 92, 97, 67, 64, 69, 66, 77, 78, 123, 64, 106,
64, 73, 84, 67, 72, 99, 64})
} else if route.Name == "C1" {
route.Polyline = string([]byte{111, 97, 95, 111, 71, 98, 125, 105, 111, 86, 64, 63, 84,
67, 88, 103, 66, 119, 64, 91, 69, 88, 93, 118, 66, 71, 94, 71, 90, 67, 76, 65, 68, 111, 64, 102, 69, 101, 64, 114,
67, 81, 126, 64, 117, 64, 114, 69, 75, 114, 64, 79, 124, 64, 89, 102, 66, 111, 64, 108, 69, 73, 108, 64, 99, 64, 108,
67, 111, 64, 118, 68, 75, 116, 64, 99, 64, 104, 67, 109, 64, 122, 68, 67, 84, 107, 64, 100, 68, 85, 126, 65, 89, 98, 66,
121, 64, 63, 121, 67, 66, 89, 63, 117, 64, 63, 99, 68, 66, 107, 64, 64, 117, 64, 68, 99, 64, 63, 77, 63, 105, 65, 65, 95,
66, 66, 121, 66, 68, 125, 64, 63, 103, 67, 64, 121, 64, 63, 109, 65, 64, 123, 64, 64, 121, 64, 63, 119, 64, 64, 107, 66,
64, 81, 63, 125, 65, 66, 117, 66, 64, 113, 65, 64, 101, 67, 66, 71, 63, 105, 64, 64, 97, 64, 66, 89, 70, 83, 72, 85, 80, 109,
64, 106, 64, 99, 64, 86, 89, 78, 71, 64, 79, 66, 89, 64, 93, 63, 85, 63, 95, 67, 65, 97, 65, 63, 117, 66, 63, 99, 66, 63,
111, 65, 64, 99, 64, 64, 97, 68, 66, 121, 64, 63, 121, 66, 63, 101, 66, 63, 85, 63, 121, 70, 63, 123, 66, 63, 101, 67, 64,
113, 67, 66, 111, 65, 63, 107, 64, 63, 113, 68, 64, 103, 67, 66, 119, 64, 63, 103, 65, 65, 107, 67, 63, 81, 64, 119, 64, 72, 117,
64, 76, 99, 64, 70, 79, 66, 83, 68, 65, 110, 64, 67, 100, 65, 81, 114, 66, 63, 68, 79, 124, 64, 111, 64, 106, 67, 93, 100, 65, 83, 98,
65, 77, 124, 64, 73, 96, 65, 63, 116, 64, 65, 94, 63, 118, 64, 63, 112, 71, 65, 104, 67, 65, 100, 66, 65, 118, 64, 75, 96, 71, 71, 108,
66, 73, 122, 66, 73, 116, 66, 69, 100, 66, 63, 96, 67, 63, 104, 64, 66, 104, 64, 66, 106, 65, 72, 118, 65, 70, 96, 65, 66, 106, 64, 70, 116,
66, 64, 112, 65, 63, 100, 66, 63, 112, 69, 63, 104, 74, 65, 116, 64, 63, 126, 72, 63, 114, 64, 65, 112, 74, 65, 108, 64, 67, 96, 65, 71, 122, 64,
67, 90, 73, 114, 64, 101, 64, 120, 67, 79, 122, 64, 97, 64, 112, 67, 69, 80, 81, 124, 65, 67, 110, 64, 65, 124, 64, 64, 104, 65, 96, 65, 73, 110,
64, 79, 66, 63, 96, 64, 95, 64, 94, 99, 64, 84, 97, 64, 78, 87, 116, 64, 101, 66, 90, 109, 64, 114, 64, 121, 65, 76, 83, 84, 77, 86, 71, 88, 64, 104, 64,
76, 66, 64, 110, 65, 110, 64, 94, 82, 84, 84, 94, 90, 72, 74, 90, 94, 94, 98, 64, 84, 88, 108, 64, 124, 64, 110, 64, 114, 64, 86, 82, 90, 80, 90, 76,
92, 70, 104, 64, 70, 72, 66, 98, 65, 65, 122, 64, 69, 63, 63, 118, 64, 83, 116, 64, 99, 64, 98, 64, 95, 64, 76, 75, 108, 65, 109, 65, 114, 64, 115, 64,
124, 68, 123, 68, 72, 73, 92, 93, 104, 67, 107, 67, 64, 65, 124, 65, 95, 66, 108, 65, 109, 65, 100, 64, 101, 64, 104, 67, 109, 67, 118, 65, 113, 65,
112, 65, 123, 65, 116, 64, 103, 65, 64, 65, 96, 66, 99, 67, 106, 64, 125, 64, 106, 67, 109, 69, 70, 77, 122, 66, 113, 68, 92, 107, 64, 122, 68, 107, 71,
78, 83, 74, 93, 68, 87, 63, 89, 65, 101, 64, 64, 105, 67, 64, 101, 65, 64, 121, 68, 63, 79, 63, 125, 65, 64, 113, 66, 64, 99, 69, 64, 105, 68, 64, 95, 64,
63, 99, 68, 64, 115, 66, 64, 113, 64, 64, 111, 70, 66, 113, 68, 63, 103, 69, 64, 115, 69, 63, 105, 69, 64, 109, 66, 64, 103, 67, 63, 99, 64, 66, 107, 68, 64,
109, 66, 67, 115, 64, 69, 89, 75, 93, 108, 64, 107, 64, 84, 81, 82, 73, 88, 71, 96, 64, 67, 112, 64, 65, 104, 65, 65, 122, 64, 65, 102, 69, 67, 110, 66, 67, 116,
65, 65, 84, 63, 112, 66, 65, 122, 64, 65, 102, 67, 65, 104, 68, 65, 90, 63, 120, 69, 73, 104, 65, 64, 112, 64, 63, 116, 64, 69, 82, 65, 86, 63, 120, 69, 67,
88, 63, 104, 66, 65, 106, 65, 65, 92, 63, 102, 64, 95, 68, 70, 99, 64, 110, 64, 123, 68, 108, 64, 123, 68, 110, 64, 95, 69, 110, 64, 119, 68, 108, 64, 123, 68,
110, 64, 109, 69, 88, 103, 66, 90, 113, 66, 116, 64, 115, 69, 118, 64, 115, 69, 110, 64, 103, 69, 64, 69, 66, 77, 78, 123, 64, 106, 64, 73, 84, 67})
}
datastore.Put(c, keys[i], route)
}
}
// Don't forget to call AllocateIDs to prevent overlap with previous keys
// func AllocateIDs(c appengine.Context, kind string, parent *Key, n int) (low, high int64, err error)