-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (38 loc) · 1.21 KB
/
index.js
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
const weather = require('./weather');
const geocoding = require('./graphhopper_geocoding');
const routing = require('./graphhopper_routing');
const express = require('express');
const points = require('./points');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 8000;
app.use(cors());
function simulateTraffic() {
var sec = (new Date().getTime() / 1000) % 40;
return Math.sin((sec * Math.PI) / 40);
}
app.post('/points', bodyParser.json(), async (req, res) => {
const location = req.body.location;
const name = req.body.name;
switch (name) {
case "Walk":
break;
case "Bike":
break;
case "Bus":
break;
case "Electric Car":
default:
break;
}
// const traffic; // TODO: invent random traffic
// const timeLastTime; // TODO: get time from database
let info = await weather.getWeatherInfo(location);
const p = parseFloat(info.precipitation);
const t = parseFloat(info.temperature);
res.send({
points: points.calculatePoints(p, t)
});
});
app.listen(port, () => { console.log(`Back&Forth listening on port ${port}`); });