index.js
2.81 KB
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
var express = require('express');
var router = express.Router();
var db = require('../lib/db_total');
/* GET home page. */
router.post('/starting', (req, res) => {
res.redirect(`/name/${req.body.name}/birth/${req.body.birth}`);
})
router.get('/name/:name/birth/:birth', (req, res) => {
// 렌더링 변수
var time = new Array(); // 타임스탬프
var ptArr = new Array(); // 현재 온도
var wsArr = new Array(); // 풍속
var rainArr = new Array(); // 강우량
var probArr = new Array(); // 사망 확률
var dataLen = 0; // 데이터 개수
var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
var sql = ""; // 쿼리
var count = 0;
const name = req.params.name;
const birth = req.params.birth;
//const address = req.params.address;
////////////////////////////////////////
var tdeathArr = new Array(); //사망자수
var mhurtArr = new Array(); //중상자수
var lhurtArr = new Array(); //경상자수
var occurArr = new Array(); //총 발생수
////////////////////////////////////////
var airArr = new Array(); //대기오염 지수
// 이전 10분간 데이터 찾기
sql = "SELECT * FROM apisInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -20 MINUTE), '%Y-%m-%d %H:%i:%s')";
db.query(sql, function (err, rows, fields) {
if (err) {
console.log(err);
}
else {
if (rows.length == 0) {
empty = 1;
}
else {
for (var i = rows.length - 1; i >= 0; i--) {
probArr.unshift(rows[i].prob);
time.unshift(rows[i].time);
ptArr.unshift(rows[i].temperature);
wsArr.unshift(rows[i].wind);
rainArr.unshift(rows[i].rain);
////
tdeathArr.unshift(rows[i].tdeath);
mhurtArr.unshift(rows[i].mhurt);
lhurtArr.unshift(rows[i].lhurt);
occurArr.unshift(rows[i].occurence);
////
airArr.unshift(rows[i].pollution);
count = count + 1;
if (count == 10) {
break;
}
}
}
dataLen = probArr.length;
res.render('index', {
empty,
time,
ptArr,
wsArr,
rainArr,
probArr,
dataLen,
name,
birth,
tdeathArr,
mhurtArr,
lhurtArr,
occurArr,
airArr
});
}
});
})
router.get('/', function (req, res, next) {
res.render('main');
});
module.exports = router;