Merge branch 'algorithm' into 'developing'
merge 'algorithm' to 'developing' See merge request !7
Showing
1 changed file
with
26 additions
and
9 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | var db = require('../lib/db'); | 3 | var db = require('../lib/db'); |
4 | +require('date-utils'); | ||
5 | + | ||
6 | +var newDate = new Date(); | ||
4 | 7 | ||
5 | /* GET home page. */ | 8 | /* GET home page. */ |
6 | router.get('/', function(req, res, next) { | 9 | router.get('/', function(req, res, next) { |
... | @@ -11,26 +14,39 @@ router.get('/', function(req, res, next) { | ... | @@ -11,26 +14,39 @@ router.get('/', function(req, res, next) { |
11 | var wsArr = new Array(); // 풍속 | 14 | var wsArr = new Array(); // 풍속 |
12 | var rainArr = new Array(); // 강우량 | 15 | var rainArr = new Array(); // 강우량 |
13 | var probArr = new Array(); // 사망 확률 | 16 | var probArr = new Array(); // 사망 확률 |
17 | + var dataLen = 0; // 데이터 개수 | ||
14 | var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음 | 18 | var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음 |
15 | var sql = ""; // 쿼리 | 19 | var sql = ""; // 쿼리 |
16 | var index; | 20 | var index; |
17 | 21 | ||
18 | // 이전 10분간 데이터 찾기 | 22 | // 이전 10분간 데이터 찾기 |
19 | - | ||
20 | sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')"; | 23 | sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')"; |
21 | - | ||
22 | db.query(sql, function(err, rows, fields){ | 24 | db.query(sql, function(err, rows, fields){ |
23 | if (err) { | 25 | if (err) { |
24 | console.log(err); | 26 | console.log(err); |
25 | } else { | 27 | } else { |
26 | - if (rows.length != 10) { | 28 | + if (rows.length == 0) { |
27 | empty = 1; | 29 | empty = 1; |
28 | } else { | 30 | } else { |
29 | - probArr.push(rows[0].prob); | 31 | + dataLen = rows.length; |
30 | - time.push(rows[0].time); | 32 | + for (index = 0; index < rows.length; index++){ |
31 | - ptArr.push(rows[0].temperature); | 33 | + var temp = rows[index].time.getMinutesBetween(newDate); |
32 | - wsArr.push(rows[0].wind); | 34 | + |
33 | - rainArr.push(rows[0].rain); | 35 | + if(temp == index){ |
36 | + probArr.push(rows[index].prob); | ||
37 | + time.push(rows[index].time); | ||
38 | + ptArr.push(rows[index].temperature); | ||
39 | + wsArr.push(rows[index].wind); | ||
40 | + rainArr.push(rows[index].rain); | ||
41 | + } | ||
42 | + else { | ||
43 | + empty = 1; | ||
44 | + break; | ||
45 | + } | ||
46 | + } | ||
47 | + | ||
48 | + if (empty == 1 && probArr.length != 0) | ||
49 | + empty = 0; | ||
34 | } | 50 | } |
35 | 51 | ||
36 | res.render('index', { | 52 | res.render('index', { |
... | @@ -39,7 +55,8 @@ router.get('/', function(req, res, next) { | ... | @@ -39,7 +55,8 @@ router.get('/', function(req, res, next) { |
39 | ptArr, | 55 | ptArr, |
40 | wsArr, | 56 | wsArr, |
41 | rainArr, | 57 | rainArr, |
42 | - probArr | 58 | + probArr, |
59 | + dataLen | ||
43 | }); | 60 | }); |
44 | } | 61 | } |
45 | }) | 62 | }) | ... | ... |
-
Please register or login to post a comment