-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathservices_handler.go
73 lines (62 loc) · 1.95 KB
/
services_handler.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
package main
import (
"net/http"
"net/url"
)
var ServiceNames = map[string]string{"4fd3b167e750846744000005": "Graffiti Removal",
"4fd6e4ece750840569000019": "Restaurant Complaint",
"4fd3b9bce750846c5300004a": "Rodent Baiting / Rat Complaint",
"4fd3bbf8e750846c53000069": "Tree Debris",
"4ffa4c69601827691b000018": "Abandoned Vehicle",
"4ffa9f2d6018277d400000c8": "Street Light 1 / Out",
"4ffa971e6018277d4000000b": "Pavement Cave-In Survey",
"4ffa9cad6018277d4000007b": "Alley Light Out",
"4fd3bd72e750846c530000cd": "Building Violation",
"4ffa9db16018277d400000a2": "Traffic Signal Out",
"4ffa995a6018277d4000003c": "Street Cut Complaints",
"4fd3b750e750846c5300001d": "Sanitation Code Violation",
"4fd3b656e750846c53000004": "Pothole in Street",
"4fd3bd3de750846c530000b9": "Street Lights All / Out"}
func ServicesHandler(params url.Values, request *http.Request) ([]byte, *ApiError) {
// return counts of requests, grouped by service name
//
// Sample output:
//
// [
// {
// "Count": 1139,
// "Service_code": "4fd3b167e750846744000005",
// "Service_name": "Graffiti Removal"
// },
// {
// "Count": 25,
// "Service_code": "4fd6e4ece750840569000019",
// "Service_name": "Restaurant Complaint"
// },
//
// ... snip ...
//
// ]
type ServicesCount struct {
Count int `json:"count"`
Service_code string `json:"service_code"`
Service_name string `json:"service_name"`
}
var services []ServicesCount
rows, err := api.Db.Query(`SELECT SUM(total), service_code
FROM daily_counts
GROUP BY service_code;`)
if err != nil {
return backend_error(err)
}
for rows.Next() {
var count int
var service_code string
if err := rows.Scan(&count, &service_code); err != nil {
return backend_error(err)
}
row := ServicesCount{Count: count, Service_code: service_code, Service_name: ServiceNames[service_code]}
services = append(services, row)
}
return dumpJson(services), nil
}