배희수

Merge branch 'algorithm' into 'developing'

merge 'algorithm' to 'developing'



See merge request !4
...@@ -4,38 +4,45 @@ var db = require('../lib/db'); ...@@ -4,38 +4,45 @@ var db = require('../lib/db');
4 4
5 /* GET home page. */ 5 /* GET home page. */
6 router.get('/', function(req, res, next) { 6 router.get('/', function(req, res, next) {
7 - // 자외선지수, 불쾌지수, 열지수, 체감 온도, 바람속도, 현재기온, 하늘 상태, 강우량, 태풍, 낙뢰, 특보, 현재 시간
8 - var uvr, discomfort, heat, sensibleTem, windSpeed, presentTem, skyState, rainfall, typhoon, lightning, alert, time;
9 7
10 - // 쿼리문 8 + // 렌더링 변수
11 - var sql = 'SELECT * FROM kkonzi_test.weatherInfo WHERE kkonzi_test.time > DATE_FORMAT(DATE_ADD(now(), INTERVAL -1 MINUTE), "%Y-%m-%d %H:%i:%s")''; 9 + var time = new Array(); // 타임스탬프
12 - db.query(sql, function(err, rows, fields){ 10 + var ptArr = new Array(); // 현재 온도
13 - if (err) { 11 + var wsArr = new Array(); // 풍속
14 - console.log(err); 12 + var rainArr = new Array(); // 강우량
15 - } else { 13 + var probArr = new Array(); // 사망 확률
16 - if (rows.length == 0){ 14 + var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
15 + var sql = ""; // 쿼리
16 + var index;
17 17
18 - } 18 + // 이전 10분간 데이터 찾기
19 - else {
20 19
21 - } 20 + sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')";
22 - var tmp = rows.length - 1;
23 - time = rows[temp].time;
24 - uvr = rows[temp].UV;
25 - discomfort = rows[temp].discomfort;
26 - heat = rows[temp].heat;
27 - sensibleTem = rows[temp].SensibleT;
28 - windSpeed = rows[temp].wspd;
29 - presentTem = rows[temp].CurrentT;
30 - skyState = rows[temp].sky;
31 - rainfall = rows[temp].rain;
32 - typhoon = rows[temp].typhoon;
33 - lightning = rows[temp].lightning;
34 - alert = rows[temp].alert;
35 - }
36 - })
37 21
38 - res.render('index', {title: 'Express'}); 22 + db.query(sql, function(err, rows, fields){
23 + if (err) {
24 + console.log(err);
25 + } else {
26 + if (rows.length != 10) {
27 + empty = 1;
28 + } else {
29 + probArr.push(rows[0].prob);
30 + time.push(rows[0].time);
31 + ptArr.push(rows[0].temperature);
32 + wsArr.push(rows[0].wind);
33 + rainArr.push(rows[0].rain);
34 + }
35 +
36 + res.render('index', {
37 + empty,
38 + time,
39 + ptArr,
40 + wsArr,
41 + rainArr,
42 + probArr
43 + });
44 + }
45 + })
39 }); 46 });
40 47
41 module.exports = router; 48 module.exports = router;
......