index.js
2.1 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
var express = require('express');
var router = express.Router();
var db = require('../lib/db');
/* GET home page. */
router.post('/starting' , (req,res) => {
res.redirect(`/name/${req.body.name}/birth/${req.body.birth}/city/${req.body.city}/county/${req.body.county}/village/${req.body.village}`);
})
sql1 = "TRUNCATE weatherInfo";
db.query(sql1, function(err, rows, fields){
if(err)
{
console.log(err);
}
});
router.get('/name/:name/birth/:birth/city/:city/county/:county/village/:village', (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 city = req.params.city;
const county = req.params.county;
const village = req.params.village;
// 이전 20분간 데이터 찾기
sql = "SELECT * FROM weatherInfo 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);
count = count + 1;
if (count == 10){
break;
}
}
}
dataLen = probArr.length;
res.render('index', {
empty,
time,
ptArr,
wsArr,
rainArr,
probArr,
dataLen,
name,
birth,
city,
county,
village
});
}
});
} )
router.get('/', function(req, res, next) {
res.render( 'main' );
});
module.exports = router;