Showing
4 changed files
with
19 additions
and
31 deletions
... | @@ -148,7 +148,8 @@ | ... | @@ -148,7 +148,8 @@ |
148 | "requestUrl": "/weather/index/th?appKey=c13b1a68-ef31-4131-a1b7-4069c263f82d&version=1&lat=37.239795&lon=127.083240", | 148 | "requestUrl": "/weather/index/th?appKey=c13b1a68-ef31-4131-a1b7-4069c263f82d&version=1&lat=37.239795&lon=127.083240", |
149 | "message": "성공" | 149 | "message": "성공" |
150 | } | 150 | } |
151 | -}{ | 151 | +} |
152 | +{ | ||
152 | "weather": { | 153 | "weather": { |
153 | "wIndex": { | 154 | "wIndex": { |
154 | "heatIndex": [ | 155 | "heatIndex": [ | ... | ... |
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(); | ||
7 | 4 | ||
8 | /* GET home page. */ | 5 | /* GET home page. */ |
9 | router.get('/', function(req, res, next) { | 6 | router.get('/', function(req, res, next) { |
... | @@ -14,39 +11,26 @@ router.get('/', function(req, res, next) { | ... | @@ -14,39 +11,26 @@ router.get('/', function(req, res, next) { |
14 | var wsArr = new Array(); // 풍속 | 11 | var wsArr = new Array(); // 풍속 |
15 | var rainArr = new Array(); // 강우량 | 12 | var rainArr = new Array(); // 강우량 |
16 | var probArr = new Array(); // 사망 확률 | 13 | var probArr = new Array(); // 사망 확률 |
17 | - var dataLen = 0; // 데이터 개수 | ||
18 | var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음 | 14 | var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음 |
19 | var sql = ""; // 쿼리 | 15 | var sql = ""; // 쿼리 |
20 | var index; | 16 | var index; |
21 | 17 | ||
22 | // 이전 10분간 데이터 찾기 | 18 | // 이전 10분간 데이터 찾기 |
19 | + | ||
23 | sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')"; | 20 | sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -10 MINUTE), '%Y-%m-%d %H:%i:%s')"; |
21 | + | ||
24 | db.query(sql, function(err, rows, fields){ | 22 | db.query(sql, function(err, rows, fields){ |
25 | if (err) { | 23 | if (err) { |
26 | console.log(err); | 24 | console.log(err); |
27 | } else { | 25 | } else { |
28 | - if (rows.length == 0) { | 26 | + if (rows.length != 10) { |
29 | empty = 1; | 27 | empty = 1; |
30 | } else { | 28 | } else { |
31 | - dataLen = rows.length; | 29 | + probArr.push(rows[0].prob); |
32 | - for (index = 0; index < rows.length; index++){ | 30 | + time.push(rows[0].time); |
33 | - var temp = rows[index].time.getMinutesBetween(newDate); | 31 | + ptArr.push(rows[0].temperature); |
34 | - | 32 | + wsArr.push(rows[0].wind); |
35 | - if(temp == index){ | 33 | + rainArr.push(rows[0].rain); |
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; | ||
50 | } | 34 | } |
51 | 35 | ||
52 | res.render('index', { | 36 | res.render('index', { |
... | @@ -55,8 +39,7 @@ router.get('/', function(req, res, next) { | ... | @@ -55,8 +39,7 @@ router.get('/', function(req, res, next) { |
55 | ptArr, | 39 | ptArr, |
56 | wsArr, | 40 | wsArr, |
57 | rainArr, | 41 | rainArr, |
58 | - probArr, | 42 | + probArr |
59 | - dataLen | ||
60 | }); | 43 | }); |
61 | } | 44 | } |
62 | }) | 45 | }) | ... | ... |
... | @@ -38,7 +38,14 @@ | ... | @@ -38,7 +38,14 @@ |
38 | ></div> | 38 | ></div> |
39 | </div> | 39 | </div> |
40 | </div> | 40 | </div> |
41 | - | 41 | + <script src="/socket.io/socket.io.js"></script> |
42 | + <script> | ||
43 | + var socket = io.connect('/'); | ||
44 | + socket.emit("connection"); | ||
45 | + socket.on("weatherInfo_minutely_send_to_cliend",(info)=>{ //서버에서 client에게 메세지 전송 | ||
46 | + console.log(info); | ||
47 | + }); | ||
48 | + </script> | ||
42 | <!-- 첫번째 그래프 --> | 49 | <!-- 첫번째 그래프 --> |
43 | <script type="text/javascript"> | 50 | <script type="text/javascript"> |
44 | Highcharts.chart("container1", { | 51 | Highcharts.chart("container1", { | ... | ... |
-
Please register or login to post a comment