배희수

Merge branch 'algorithm' into 'developing'

merge 'algorithm' to 'developing'



See merge request !7
var express = require('express');
var router = express.Router();
var db = require('../lib/db');
require('date-utils');
var newDate = new Date();
/* GET home page. */
router.get('/', function(req, res, next) {
......@@ -11,38 +14,52 @@ router.get('/', function(req, res, next) {
var wsArr = new Array(); // 풍속
var rainArr = new Array(); // 강우량
var probArr = new Array(); // 사망 확률
var dataLen = 0; // 데이터 개수
var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
var sql = ""; // 쿼리
var index;
// 이전 10분간 데이터 찾기
sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 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 {
dataLen = rows.length;
for (index = 0; index < rows.length; index++){
var temp = rows[index].time.getMinutesBetween(newDate);
sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')";
db.query(sql, function(err, rows, fields){
if (err) {
console.log(err);
} else {
if (rows.length != 10) {
if(temp == index){
probArr.push(rows[index].prob);
time.push(rows[index].time);
ptArr.push(rows[index].temperature);
wsArr.push(rows[index].wind);
rainArr.push(rows[index].rain);
}
else {
empty = 1;
} else {
probArr.push(rows[0].prob);
time.push(rows[0].time);
ptArr.push(rows[0].temperature);
wsArr.push(rows[0].wind);
rainArr.push(rows[0].rain);
break;
}
}
res.render('index', {
empty,
time,
ptArr,
wsArr,
rainArr,
probArr
});
if (empty == 1 && probArr.length != 0)
empty = 0;
}
})
res.render('index', {
empty,
time,
ptArr,
wsArr,
rainArr,
probArr,
dataLen
});
}
})
});
module.exports = router;
......