조민지

Merge branch 'developing' of http://khuhub.khu.ac.kr/2017104029/2018_2_project into chart

......@@ -39,10 +39,8 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
kakao_option.js
db_option.js
session.js
kakao_option.js
keys/api_option.js
keys/db_option.js
# TypeScript v1 declaration files
typings/
......
......@@ -6,7 +6,9 @@ var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
var app = express(),
server= require('http').createServer(app),
SOCKETIO=require('./lib/socketio.js');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
......@@ -37,4 +39,7 @@ app.use(function(err, req, res, next) {
res.render('error');
});
server.listen(80);
SOCKETIO(server,app);
module.exports = app;
......
const mysql = require('mysql');
const DB_option = require('../keys/db_option');
module.exports = mysql.createConnection(DB_option);
{
"weather": {
"minutely": [
{
"station": {
"longitude": "127.1164",
"latitude": "37.2772",
"name": "기흥구",
"id": "371",
"type": "KMA"
},
"wind": {
"wdir": "189.50",
"wspd": "2.20"
},
"precipitation": {
"sinceOntime": "0.00",
"type": "0"
},
"sky": {
"code": "SKY_A07",
"name": "흐림"
},
"rain": {
"sinceOntime": "0.00",
"sinceMidnight": "",
"last10min": "0.00",
"last15min": "0.00",
"last30min": "0.00",
"last1hour": "0.00",
"last6hour": "0.50",
"last12hour": "0.50",
"last24hour": "0.50"
},
"temperature": {
"tc": "5.90",
"tmax": "7.00",
"tmin": "-1.00"
},
"humidity": "",
"pressure": {
"surface": "",
"seaLevel": ""
},
"lightning": "0",
"timeObservation": "2018-12-06 14:14:00"
}
]
},
"common": {
"alertYn": "Y",
"stormYn": "N"
},
"result": {
"code": 9200,
"requestUrl": "/weather/current/minutely?appKey=key&lat=37.239795&lon=127.083240",
"message": "성공"
}
},
{
"weather": {
"wIndex": {
"uvindex": [
{
"grid": {
"city": "경기도",
"county": "수원시",
"village": ""
},
"day00": {
"imageUrl": "http://files.weatherplanet.co.kr/weather/01_FCT/INDEX1/20181209/FCT_IDX_A07_1_2018120906_00D.gif",
"index": "20.00",
"comment": "자외선 걱정 없어요"
},
"day01": {
"imageUrl": "http://files.weatherplanet.co.kr/weather/01_FCT/INDEX1/20181209/FCT_IDX_A07_1_2018120906_01D.gif",
"index": "20.00",
"comment": "자외선 걱정 없어요"
},
"day02": {
"imageUrl": "http://files.weatherplanet.co.kr/weather/01_FCT/INDEX1/20181209/FCT_IDX_A07_1_2018120906_02D.gif",
"index": "10.00",
"comment": "자외선 없는 날입니다"
}
}
],
"timeRelease": "2018-12-09 06:00:00"
}
},
"common": {
"alertYn": "Y",
"stormYn": "N"
},
"result": {
"code": 9200,
"requestUrl": "/weather/index/uv?appKey=c13b1a68-ef31-4131-a1b7-4069c263f82d&version=1&lat=37.239795&lon=127.083240",
"message": "성공"
}
}{
"weather": {
"wIndex": {
"thIndex": [
{
"grid": {
"city": "경기",
"county": "용인시 기흥구",
"village": "상갈동"
},
"forecast": {
"timeRelease": "2018-12-09 14:00:00",
"index43hour": "37.85",
"index4hour": "38.40",
"index7hour": "34.36",
"index10hour": "31.08",
"index13hour": "31.08",
"index16hour": "27.60",
"index19hour": "35.76",
"index22hour": "44.84",
"index25hour": "47.47",
"index28hour": "42.45",
"index31hour": "39.37",
"index34hour": "37.85",
"index37hour": "36.54",
"index40hour": "35.73",
"index46hour": "42.99",
"index49hour": "39.12",
"index52hour": "37.79",
"index55hour": "37.13",
"index58hour": "36.29",
"index61hour": "",
"index64hour": "",
"index67hour": ""
},
"current": {
"timeRelease": "2018-12-09 14:00:00",
"index": "40.49"
}
}
]
}
},
"common": {
"alertYn": "Y",
"stormYn": "N"
},
"result": {
"code": 9200,
"requestUrl": "/weather/index/th?appKey=c13b1a68-ef31-4131-a1b7-4069c263f82d&version=1&lat=37.239795&lon=127.083240",
"message": "성공"
}
}{
"weather": {
"wIndex": {
"heatIndex": [
{
"grid": {
"city": "경기",
"county": "용인시 기흥구",
"village": "상갈동"
},
"forecast": {
"timeRelease": "2018-12-09 14:00:00",
"index4hour": "37.28",
"index7hour": "70.81",
"index10hour": "91.57",
"index13hour": "91.57",
"index16hour": "110.30",
"index19hour": "71.89",
"index22hour": "36.40",
"index25hour": "27.82",
"index28hour": "50.39",
"index31hour": "61.62",
"index34hour": "71.05",
"index37hour": "75.20",
"index40hour": "79.01",
"index43hour": "71.05",
"index46hour": "52.61",
"index49hour": "67.96",
"index52hour": "69.50",
"index55hour": "69.08",
"index58hour": "74.43",
"index61hour": "",
"index64hour": "",
"index67hour": ""
},
"current": {
"timeRelease": "2018-12-09 14:00:00",
"index": "32.79"
}
}
]
}
},
"common": {
"alertYn": "Y",
"stormYn": "N"
},
"result": {
"code": 9200,
"requestUrl": "/weather/index/heat?appKey=c13b1a68-ef31-4131-a1b7-4069c263f82d&version=1&lat=37.239795&lon=127.083240",
"message": "성공"
}
}
{
"weather": {
"wIndex": {
"wctIndex": [
{
"grid": {
"city": "경기",
"county": "용인시 기흥구",
"village": "상갈동"
},
"forecast": {
"timeRelease": "2018-12-09 14:00:00",
"index43hour": "-2.17",
"index4hour": "-8.15",
"index7hour": "-6.55",
"index10hour": "-7.00",
"index13hour": "-7.63",
"index16hour": "-9.08",
"index19hour": "-4.71",
"index22hour": "1.18",
"index25hour": "1.53",
"index28hour": "-0.47",
"index31hour": "-3.76",
"index34hour": "-2.37",
"index37hour": "-4.67",
"index40hour": "-4.38",
"index46hour": "-0.67",
"index49hour": "-1.18",
"index52hour": "-2.14",
"index55hour": "-1.65",
"index58hour": "-4.23",
"index61hour": "",
"index64hour": "",
"index67hour": ""
},
"current": {
"timeRelease": "2018-12-09 14:00:00",
"index": "-6.22"
}
}
]
}
},
"common": {
"alertYn": "Y",
"stormYn": "N"
},
"result": {
"code": 9200,
"requestUrl": "/weather/index/wct?appKey=c13b1a68-ef31-4131-a1b7-4069c263f82d&version=1&lat=37.239795&lon=127.083240",
"message": "성공"
}
}
\ No newline at end of file
const db = require('./db.js');
const secret_key = require('../keys/api_option').key;
const requesting = require('request');
const lat = "37.239795";
const lon = "127.083240";
module.exports = (server, app) => {
const io = require('socket.io', )(server, {
transports: ['websocket']
});
let info = {}
const CALL = (when, what) => {
requesting.get({
// api를 요청할 주소 -- 시크릿키,위도,경도 입력
url: `https://api2.sktelecom.com/weather/${when}/${what}?appKey=${secret_key}&lat=${lat}&lon=${lon}`,
json: true
},
//api에게 응답 받았을때 실행되는 callback function
function (err, api_res, api_body) {
if (err) throw err;
// api의 대답이 있을경우 실행
if (api_res) {
return api_body;
// api_body.weather.minutely[0]
}
});
}
io.on('connection', (socket) => { //웹 페이지 연결시 루프 동작
let API_CALL;
let Current_Weather;
let Sensible_T;
let Heat_index;
let Discomport_index;
let Ultra_Violet_index;
socket.on("connection", () => {
API_CALL = setInterval(() => {
Current_Weather = CALL("current","minutely"); //현재날씨 (분별)
Sensible_T = CALL("index","wct"); //체감온도
Heat_index = CALL("index","heat"); //열지수
Discomport_index = CALL("index","th"); //불쾌지수
Ultra_Violet_index = CALL("index","uv"); //자외선지수
socket.emit("weatherInfo_minutely_send_to_cliend",info);
}, 60 * 1000); //1분마다 호출
});
socket.on('disconnecting', (reason) => {
clearInterval(API_CALL); //연결 종료시 해제
})
})
}
This diff is collapsed. Click to expand it.
......@@ -9,12 +9,15 @@
"body-parser": "^1.18.3",
"compression": "^1.7.3",
"cookie-parser": "~1.4.3",
"date-utils": "^1.2.21",
"debug": "~2.6.9",
"ejs": "~2.5.7",
"express": "~4.16.0",
"helmet": "^3.13.0",
"http-errors": "~1.6.2",
"morgan": "~1.9.0",
"helmet": "^3.13.0",
"mysql": "^2.16.0",
"request": "^2.88.0",
"socket.io": "^2.1.1"
}
}
......
var express = require('express');
var router = express.Router();
var db = require('../lib/db');
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
// 자외선지수, 불쾌지수, 열지수, 체감 온도, 바람속도, 현재기온, 하늘 상태, 강우량, 태풍, 낙뢰, 특보, 현재 시간
var uvr, discomfort, heat, sensibleTem, windSpeed, presentTem, skyState, rainfall, typhoon, lightning, alert, time;
// 쿼리문
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")'';
db.query(sql, function(err, rows, fields){
if (err) {
console.log(err);
} else {
if (rows.length == 0){
}
else {
}
var tmp = rows.length - 1;
time = rows[temp].time;
uvr = rows[temp].UV;
discomfort = rows[temp].discomfort;
heat = rows[temp].heat;
sensibleTem = rows[temp].SensibleT;
windSpeed = rows[temp].wspd;
presentTem = rows[temp].CurrentT;
skyState = rows[temp].sky;
rainfall = rows[temp].rain;
typhoon = rows[temp].typhoon;
lightning = rows[temp].lightning;
alert = rows[temp].alert;
}
})
res.render('index', {title: 'Express'});
});
module.exports = router;
......
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Highcharts Example</title>
<style type="text/css"></style>
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
<script src="../code/highcharts.js"></script>
<script src="../code/modules/exporting.js"></script>
<script src="../code/modules/export-data.js"></script>
<div
id="container1"
style="width:1260px; height: 400px; margin: 0 auto"
></div>
<div style="width:1275px; margin:0 auto;">
<div style="display: inline-block;">
<div
id="container2"
style="width:400px; height: 300px; padding:0; margin-left:0px;margin-right: 30px;"
></div>
</div>
<div style="display: inline-block;">
<div
id="container3"
style="width:400px; height: 300px; padding:0; margin-left:0px;margin-right: 30px;"
></div>
</div>
<div style="display: inline-block;">
<div
id="container4"
style="width:400px; height: 300px; padding:0; margin-left:0px;"
></div>
</div>
</div>
<script type="text/javascript">
Highcharts.chart("container1", {
chart: {
type: "areaspline",
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = new Date().getTime(), // 현재 시간
y = 0.7 //여기에 새로 넣을 값
series.addPoint([x, y], true, true);
}, 1000); //1000=1초 -> 1분=60000
}
}
},
time: {
useUTC: false
},
title: {
text: "실시간 사망률"
},
xAxis: {
type: "datetime",
tickPixelInterval: 150
},
yAxis: {
title: {
text: "Value"
},
plotLines: [
{
value: 0,
width: 1,
color: "#808080"
}
]
},
tooltip: {
headerFormat: "<b>{series.name}</b><br/>",
pointFormat: "{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}"
},
legend: {
//enabled: false
layout: "vertical",
align: "left",
verticalAlign: "top",
x: 120,
y: 70,
floating: true,
borderWidth: 1,
backgroundColor:
(Highcharts.theme && Highcharts.theme.legendBackgroundColor) ||
"#FFFFFF"
},
exporting: {
enabled: false
},
series: [
{
name: "사망률(%)",
data: (function() {
// generate an array of random data
var data = [],
time = new Date().getTime(),
i;
for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: 0
});
}
return data;
})()
}
]
});
Highcharts.chart("container2", {
chart: {
type: "spline",
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = new Date().getTime(), // 현재 시간
y = Math.random(); //
series.addPoint([x, y], true, true);
}, 3000); //1000=1초
}
}
},
time: {
useUTC: false
},
title: {
text: "실시간 사망률"
},
xAxis: {
type: "datetime",
tickPixelInterval: 150
},
yAxis: {
title: {
text: "Value"
},
plotLines: [
{
value: 0,
width: 1,
color: "#808080"
}
]
},
tooltip: {
headerFormat: "<b>{series.name}</b><br/>",
pointFormat: "{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}"
},
legend: {
//enabled: false
layout: "vertical",
align: "left",
verticalAlign: "top",
x: 120,
y: 70,
floating: true,
borderWidth: 1,
backgroundColor:
(Highcharts.theme && Highcharts.theme.legendBackgroundColor) ||
"#FFFFFF"
},
exporting: {
enabled: false
},
series: [
{
name: "사망률(%)",
data: (function() {
// generate an array of random data
var data = [],
time = new Date().getTime(),
i;
for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 3000,
y: 0
});
}
return data;
})()
}
]
});
Highcharts.chart("container3", {
chart: {
type: "spline",
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = new Date().getTime(), // 현재 시간
y = Math.random(); //
series.addPoint([x, y], true, true);
}, 3000); //1000=1초
}
}
},
time: {
useUTC: false
},
title: {
text: "실시간 사망률"
},
xAxis: {
type: "datetime",
tickPixelInterval: 150
},
yAxis: {
title: {
text: "Value"
},
plotLines: [
{
value: 0,
width: 1,
color: "#808080"
}
]
},
tooltip: {
headerFormat: "<b>{series.name}</b><br/>",
pointFormat: "{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}"
},
legend: {
//enabled: false
layout: "vertical",
align: "left",
verticalAlign: "top",
x: 120,
y: 70,
floating: true,
borderWidth: 1,
backgroundColor:
(Highcharts.theme && Highcharts.theme.legendBackgroundColor) ||
"#FFFFFF"
},
exporting: {
enabled: false
},
series: [
{
name: "사망률(%)",
data: (function() {
// generate an array of random data
var data = [],
time = new Date().getTime(),
i;
for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 3000,
y: 0
});
}
return data;
})()
}
]
});
Highcharts.chart("container4", {
chart: {
type: "spline",
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = new Date().getTime(), // 현재 시간
y = Math.random(); //
series.addPoint([x, y], true, true);
}, 3000); //1000=1초
}
}
},
time: {
useUTC: false
},
title: {
text: "실시간 사망률"
},
xAxis: {
type: "datetime",
tickPixelInterval: 150
},
yAxis: {
title: {
text: "Value"
},
plotLines: [
{
value: 0,
width: 1,
color: "#808080"
}
]
},
tooltip: {
headerFormat: "<b>{series.name}</b><br/>",
pointFormat: "{point.x:%Y-%m-%d %H:%M:%S}<br/>{point.y:.2f}"
},
legend: {
//enabled: false
layout: "vertical",
align: "left",
verticalAlign: "top",
x: 120,
y: 70,
floating: true,
borderWidth: 1,
backgroundColor:
(Highcharts.theme && Highcharts.theme.legendBackgroundColor) ||
"#FFFFFF"
},
exporting: {
enabled: false
},
series: [
{
name: "사망률(%)",
data: (function() {
// generate an array of random data
var data = [],
time = new Date().getTime(),
i;
for (i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 3000,
y: 0
});
}
return data;
})()
}
]
});
</script>
</body>
</html>
......