배희수

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(); // 타임스탬프
10 + var ptArr = new Array(); // 현재 온도
11 + var wsArr = new Array(); // 풍속
12 + var rainArr = new Array(); // 강우량
13 + var probArr = new Array(); // 사망 확률
14 + var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
15 + var sql = ""; // 쿼리
16 + var index;
17 +
18 + // 이전 10분간 데이터 찾기
19 +
20 + sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')";
21 +
12 db.query(sql, function(err, rows, fields){ 22 db.query(sql, function(err, rows, fields){
13 if (err) { 23 if (err) {
14 console.log(err); 24 console.log(err);
15 } else { 25 } else {
16 - if (rows.length == 0){ 26 + if (rows.length != 10) {
17 - 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);
18 } 34 }
19 - else {
20 35
21 - } 36 + res.render('index', {
22 - var tmp = rows.length - 1; 37 + empty,
23 - time = rows[temp].time; 38 + time,
24 - uvr = rows[temp].UV; 39 + ptArr,
25 - discomfort = rows[temp].discomfort; 40 + wsArr,
26 - heat = rows[temp].heat; 41 + rainArr,
27 - sensibleTem = rows[temp].SensibleT; 42 + probArr
28 - windSpeed = rows[temp].wspd; 43 + });
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 } 44 }
36 }) 45 })
37 -
38 - res.render('index', {title: 'Express'});
39 }); 46 });
40 47
41 module.exports = router; 48 module.exports = router;
......