Toggle navigation
Toggle navigation
This project
Loading...
Sign in
kkl
/
Probability Death
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이승규
2019-06-05 14:56:06 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
de13cc76a4dc635583b41c9c0fddf6c8ad6907ad
de13cc76
1 parent
880a2fb4
사망요인 추가 (오류 미해결상태)
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
24 deletions
lib/socketio.js
routes/index.js
views/index.ejs
lib/socketio.js
View file @
de13cc7
...
...
@@ -21,7 +21,6 @@ module.exports = (server, app) => {
let
Ultra_Violet_index
=
{};
let
Traffic_Accident
=
{};
let
Death_Factors
=
[];
let
Death_Factor
=
""
;
let
sending_to_client_info
=
{};
let
client_send
=
{};
let
client_name
=
""
;
...
...
@@ -104,6 +103,8 @@ module.exports = (server, app) => {
typhoon
:
Current_Weather
.
common
.
stormYn
,
//현재 태풍
time
:
Current_Weather
.
weather
.
minutely
[
0
].
timeObservation
,
// 불러온 시각
traffic
:
Traffic_Accident
.
totalCount
,
// 교통사고 발생횟수
death_factor
:
""
,
//사망요인
death_countdown
:
0
,
//죽기까지 남은 시간(단위: 초)
death_prob
:
0
//확률
}
console
.
log
(
"API INFO \n"
,
info
);
...
...
@@ -126,29 +127,50 @@ 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
)
;
//
심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음
Math
.
random
()
*
2
>=
1
?
client_send
.
death
+=
getRandom_add_prob
(
0
,
5
)
:
client_send
.
death
-=
getRandom_add_prob
(
0
,
5
)
;
//운명의 장난으로 죽을 확률이 증가하거나 감소함
const
rand
=
Math
.
floor
(
Math
.
random
()
*
6
)
*
10
//생년월일 중 한자리 뽑음
//운명의 장난으로 죽을 확률이 증가하거나 감소함
const
rand
=
Math
.
floor
(
Math
.
random
()
*
6
)
*
10
//생년월일 중 한자리 뽑음
Destiny
=
client_birth
.
charAt
(
rand
)
/
3
;
//명시적 형 변환
if
(
Destiny
==
0
)
Destiny
=
1
;
//사용자 잘못 입력했을때 예외처리
Math
.
random
()
*
2
>=
1
?
client_send
.
death
+=
Destiny
:
client_send
.
death
-=
Destiny
;
Destiny
=
client_birth
.
charAt
(
rand
)
/
3
;
//명시적 형 변환
if
(
Destiny
==
0
)
Destiny
=
1
;
//사용자 잘못 입력했을때 예외처리
Math
.
random
()
*
2
>=
1
?
client_send
.
death
+=
Destiny
:
client_send
.
death
-=
Destiny
;
//만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리
...
...
@@ -162,8 +184,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
...
...
routes/index.js
View file @
de13cc7
...
...
@@ -15,6 +15,7 @@ router.get('/name/:name/birth/:birth', (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
=
""
;
// 쿼리
...
...
@@ -44,6 +45,7 @@ router.get('/name/:name/birth/:birth', (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
){
...
...
@@ -62,7 +64,8 @@ router.get('/name/:name/birth/:birth', (req,res) => {
probArr
,
dataLen
,
name
,
birth
birth
,
factorArr
,
});
}
});
...
...
views/index.ejs
View file @
de13cc7
...
...
@@ -59,7 +59,7 @@
<script
src=
"/socket.io/socket.io.js"
></script>
<script
type=
"text/javascript"
>
let
client_data
=
{
let
client_data
=
{
birth
:
"<%=birth%>"
,
name
:
"<%=name%>"
}
...
...
@@ -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,17 @@ 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
%>
;
//<% probArr.forEach((probArr) => {%>
<%
for
(
var
n
in
probArr
)
{
%>
var
temp
,
temp2
;
temp
=
<%=
probArr
[
n
]
%>
;
temp2
=
<%=
factorArr
[
n
]
%>
;
// for(;j<10;j++)
// {
...
...
@@ -190,11 +193,12 @@ plotOptions: {
deathArr
.
push
({
x
:
time
+
i
*
60000
,
y
:
temp
y
:
temp
,
factor
:
temp2
})
i
++
;
<%
}
)
%>
<%
}
%>
return
deathArr
;
})(),
...
...
@@ -205,7 +209,6 @@ plotOptions: {
});
var
chart2
=
Highcharts
.
chart
(
"container2"
,
{
chart
:
{
type
:
"spline"
,
...
...
@@ -593,16 +596,18 @@ plotOptions: {
});
var
socket
=
io
.
connect
(
'/'
,
{
transports
:
[
'websocket'
],
upgrade
:
false
});
socket
.
emit
(
"connection"
,
client_data
);
socket
.
on
(
"weatherInfo_minutely_send_to_client"
,
(
info
)
=>
{
//서버에서 client에게 메세지 전송
console
.
log
(
info
);
var
date
=
new
Date
().
getTime
();
var
date
=
new
Date
().
getTime
();
chart1
.
series
[
0
].
addPoint
({
x
:
date
,
y
:
info
.
death
,
factor
:
info
.
factor
,
color
:
"#FFE08C"
});
chart2
.
series
[
0
].
addPoint
({
...
...
Please
register
or
login
to post a comment