-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__server.coffee
122 lines (104 loc) · 3.65 KB
/
__server.coffee
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
`var path`
'use strict'
express = require('express')
request = require 'request'
path = require('path')
http = require('http')
path = require('path')
async = require('async')
serveStatic = require('serve-static')
cartodb = require('cartodb')
app = express()
app.disable 'etag'
app.set 'trust proxy', true
app.use serveStatic('./', 'index': [
'index.html'
'index.htm'
])
app.use serveStatic('./node_modules/web-audio-api/lib')
app.use serveStatic('./lib')
app.use serveStatic('./bower_components/mapbox.js')
app.use serveStatic('./bower_components/semantic/dist')
app.use serveStatic('./bower_components/cartodb.js')
app.use serveStatic('./bower_components/cartodb.js/themes/css')
app.use serveStatic('./bower_components/d3')
app.use serveStatic('./sounds')
user= "arminavn"
api_key= "9150413ca8fb81229459d0a5c2947620e42d0940"
sql= "SELECT * FROM table_4"
lookup_sql= "SELECT * FROM northend_soundcategories_time"
labels_sql = "SELECT * FROM category_lookup"
app.get '/labels', (req, res) =>
labels_res = []
request {
method: 'GET'
url: "https://#{user}.cartodb.com/api/v2/sql?q=#{labels_sql}&api_key=#{api_key}"
json: true
}, (error, label_response, labes_body) =>
for ea in labes_body.rows
console.log ea
labels_res.push
"abbr": ea.description
"name": ea.name
res.send labels_res
app.get '/lookup', (req, res) =>
console.log "https://#{user}.cartodb.com/api/v2/sql?q=#{lookup_sql}&api_key=#{api_key}"
lookup_features = []
request {
method: 'GET'
url: "https://#{user}.cartodb.com/api/v2/sql?q=#{lookup_sql}&api_key=#{api_key}"
json: true
}, (error, lookup_response, lookup_body) =>
console.log lookup_body.rows
if !error and lookup_response.statusCode == 200
# console.log body
# console.log body.rows.length
for each in lookup_body.rows
lookup_features.push
"location_number": +each.number
"time_in_seconds": each.time_in_seconds
"category": each.category
res.send lookup_features
# @emit 'radarResponds', body.results
app.get '/data', (req, res) =>
console.log "https://#{user}.cartodb.com/api/v2/sql?q=#{sql}&api_key=#{api_key}"
geores = {
"type": "FeatureCollection"
"features": []
}
request {
method: 'GET'
url: "https://#{user}.cartodb.com/api/v2/sql?q=#{sql}&api_key=#{api_key}"
json: true
}, (error, response, body) =>
if !error and response.statusCode == 200
# console.log body
# console.log body.rows.length
for each in body.rows
geores.features.push
"type": "Feature"
"geometry":
"type": "Point"
"coordinates": [each.longitude, each.latitude]
"properties":
"sound": each.sound
"file": each.file
"location_number": each.location_number
res.send geores
# @emit 'radarResponds', body.results
app.get '/', (req, res) ->
# res.status(200).send("Hello, world!");
res.render 'index', (err, html) ->
res.send html
return
# res.sendfile('./bower_components/shower-bright/index.html');
return
# [END hello_world]
# [START server]
### Start the server ###
server = app.listen(process.env.PORT or '8080', '0.0.0.0', ->
console.log 'App listening at http://%s:%s', server.address().address, server.address().port
console.log 'Press Ctrl+C to quit.'
console.log 'checking if adjustments work'
return
)