곽태식

Merge branch 'joke' into forecast

......@@ -9,8 +9,8 @@ var usersRouter = require('./routes/users');
var app = express(),
server= require('http').createServer(app),
SOCKETIO=require('./lib/socketio.js');
server = require('http').createServer(app),
SOCKETIO = require('./lib/socketio.js');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
......
......@@ -20,6 +20,7 @@ module.exports = (server, app) => {
let Discomport_index = {};
let Ultra_Violet_index = {};
let Traffic_Accident = {};
let Death_Factors = [];
let sending_to_client_info = {};
let client_send = {};
let client_name = "";
......@@ -27,6 +28,7 @@ module.exports = (server, app) => {
let Destiny;
let sql;
let Day3_Weather ={};
let info = {}
......@@ -137,6 +139,8 @@ module.exports = (server, app) => {
traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수
death_factor: "", //사망요인
death_countdown: 0, //죽기까지 남은 시간(단위: 초)
death_prob: 0 //확률
}
console.log("API INFO \n", info);
......@@ -161,20 +165,41 @@ module.exports = (server, app) => {
+ info.windspd*1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) //+ (info.traffic / 5)
);
// ------------------------------ death_factor 정의 ------------------------------
if (info.typhoon == "Y")
Death_Factors.push("태풍에 휩쓸려 사망");
if (info.lightning == 1)
Death_Factors.push("번개에 맞아 사망");
if (info.warning == "Y")
Death_Factors.push("우박에 머리를 맞아 사망");
if (info.windspd*1 >= 2)
Death_Factors.push("애인에게 바람맞아 그 충격으로 인해 사망");
if (info.heat*1 >= 100)
Death_Factors.push("학점이 너무 낮아 화병으로 사망");
if (info.discomport*1 >= 40)
Death_Factors.push("날씨가 너무 찝찝해서 사망");
Death_Factors.push("심장마비로 사망"); //반드시 하나의 요인은 추가되어야 함
info.death_factor = Death_Factors[Math.round(Math.random()*Death_Factors.length)]; //사망요인 하나를 렌덤으로 고른다.
//이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보
client_send = {
time: info.time,
wind: info.windspd,
temperature: info.current_temperature,
rain: info.rain,
death: info.death_prob
death: info.death_prob,
factor: info.death_factor,
};
function getRandom_add_prob(min, max) {
return Math.random() * (max - min) + min;
}
// 심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음
//심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음
Math.random() * 2 >= 1 ? client_send.death += getRandom_add_prob(0,5) : client_send.death -= getRandom_add_prob(0,5) ;
......@@ -197,8 +222,8 @@ module.exports = (server, app) => {
console.log("emit");
//db에 저장
sql = "INSERT INTO weather_info (time,wind,temperature,rain,prob) VALUES (?,?,?,?,?)";
db.query(sql, [client_send.time, client_send.wind, client_send.temperature, client_send.rain, client_send.death], (err, result) => {
sql = "INSERT INTO weather_info (time,wind,temperature,rain,prob,factor) VALUES (?,?,?,?,?,?)";
db.query(sql, [client_send.time, client_send.wind, client_send.temperature, client_send.rain, client_send.death, client_send.factor], (err, result) => {
if (err) console.log(err);
})
} catch (err) { //promise err or try err catch
......
......@@ -81,6 +81,7 @@ router.get('/Cname/:Cname/Cbirth/:Cbirth', (req,res) => {
var wsArr = new Array(); // 풍속
var rainArr = new Array(); // 강우량
var probArr = new Array(); // 사망 확률
var factorArr = new Array(); // 사망요인
var dataLen = 0; // 데이터 개수
var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
var sql = ""; // 쿼리
......@@ -110,6 +111,7 @@ router.get('/Cname/:Cname/Cbirth/:Cbirth', (req,res) => {
ptArr.unshift(rows[i].temperature);
wsArr.unshift(rows[i].wind);
rainArr.unshift(rows[i].rain);
factorArr.unshift(rows[i].factor);
count = count + 1;
if (count == 10){
......@@ -128,7 +130,8 @@ router.get('/Cname/:Cname/Cbirth/:Cbirth', (req,res) => {
probArr,
dataLen,
name,
birth
birth,
factorArr,
});
}
});
......
......@@ -131,7 +131,7 @@
},
tooltip: {
headerFormat: "<b>{series.name}</b><br/>",
pointFormat: "{point.x:%Y년%m월%d일 %H시%M분}<br/>의 사망률 : {point.y:.2f}%"
pointFormat: "{point.x:%Y년%m월%d일 %H시%M분}<br/>의 사망률 : {point.y:.2f}%<br/>사망요인 : {point.factor}"
},
legend: {
//enabled: false
......@@ -150,7 +150,7 @@
enabled: false
},
plotOptions: {
plotOptions: {
series: {
marker: {
radius: 6
......@@ -170,14 +170,16 @@ plotOptions: {
for (; j < 10 - length; j++) {
deathArr.push({
x: time + i * 60000,
y: 0
y: 0,
factor: "없음"
})
i++;
}
<% probArr.forEach((probArr) => {%>
var temp;
temp = <%=probArr %>;
<% for(var n; n < probArr.length; n++) {%>
var temp, temp2;
temp = <%=probArr[n] %>;
temp2 = <%=factorArr[n] %>;
// for(;j<10;j++)
// {
......@@ -190,11 +192,12 @@ plotOptions: {
deathArr.push({
x: time + i * 60000,
y: temp
y: temp,
factor: temp2
})
i++;
<%}) %>
<%} %>
return deathArr;
})(),
......@@ -205,7 +208,6 @@ plotOptions: {
});
var chart2 = Highcharts.chart("container2", {
chart: {
type: "spline",
......@@ -593,6 +595,7 @@ plotOptions: {
});
var socket = io.connect('/', { transports: ['websocket'], upgrade: false });
socket.emit("connection", client_data);
socket.on("weatherInfo_minutely_send_to_client", (info) => { //서버에서 client에게 메세지 전송
......@@ -603,6 +606,7 @@ plotOptions: {
chart1.series[0].addPoint({
x: date,
y: info.death,
factor: info.factor,
color:"#FFE08C"
});
chart2.series[0].addPoint({
......