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-03 20:37:26 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
1ee0179318c9c1582bc7a35b4a6347a24b4f526b
1ee01793
2 parents
132605c4
7ab3a8f5
merge
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
6 deletions
FatalTrafficAccidents_CodeList.xlsx
lib/socketio.js
routes/index.js
FatalTrafficAccidents_CodeList.xlsx
0 → 100644
View file @
1ee0179
No preview for this file type
lib/socketio.js
View file @
1ee0179
const
db
=
require
(
'./db.js'
);
const
secret_key
=
require
(
'../keys/api_option'
).
key
;
//const secret_D_key = require('../keys/api_option').D_key;//사망교통사고 키
const
secret_key
=
require
(
'../keys/api_option'
).
weather_
key
;
const
traffic_key
=
require
(
'../keys/api_option'
).
traffic_key
;
const
requesting
=
require
(
'request'
);
const
lat
=
"37.239795"
;
const
lon
=
"127.083240"
;
const
city
=
"1300"
;
const
town
=
"1302"
;
const
year_range
=
6
;
const
year_start
=
2012
;
module
.
exports
=
(
server
,
app
)
=>
{
const
io
=
require
(
'socket.io'
)(
server
,
{
...
...
@@ -15,6 +19,7 @@ module.exports = (server, app) => {
let
Heat_index
=
{};
let
Discomport_index
=
{};
let
Ultra_Violet_index
=
{};
let
Traffic_Accident
=
{};
let
sending_to_client_info
=
{};
let
client_send
=
{};
let
client_name
=
""
;
...
...
@@ -50,9 +55,28 @@ module.exports = (server, app) => {
})
}
// 교통사고정보를 받아오는 함수
const
req_traffic_API
=
(
year
)
=>
{
//async await 사용하기 위하여 promise 사용
return
new
Promise
((
resolve
,
reject
)
=>
{
requesting
.
get
({
// api를 요청할 주소 -- 시크릿키,위도,경도 입력
url
:
`http://taas.koroad.or.kr/data/rest/accident/death?authKey=
${
traffic_key
}
&searchYear=
${
year
}
&siDo=
${
city
}
&guGun=
${
town
}
&type=json`
,
json
:
true
},
//api에게 응답 받았을때 실행되는 callback function
function
(
err
,
api_res
,
api_body
)
{
//err 존재시 promise reject 호출
if
(
err
)
reject
(
err
);
// api의 response이 있을경우 promise resolve 호출
if
(
api_res
)
{
console
.
log
(
"calling traffic api"
);
resolve
(
api_body
);
}
});
})
}
const
API_bundle
=
async
()
=>
{
try
{
...
...
@@ -63,6 +87,12 @@ module.exports = (server, app) => {
Ultra_Violet_index
=
await
req_API
(
"index"
,
"uv"
);
//자외선지수
//let kts = await req_D_API();
Day3_Weather
=
await
req_API
(
"forecast"
,
"3days"
);
//3일예보(단기예보)
// 사용자의 생일에 따라서 다른 년도의 교통사고정보를 가져옴.
const
year
=
year_start
+
(
client_birth
%
(
year_range
+
1
));
Traffic_Accident
=
await
req_traffic_API
(
year
);
//교통사고정보
info
=
{
heat
:
Heat_index
.
weather
.
wIndex
.
heatIndex
[
0
].
current
.
index
,
//열지수
sensible_temperature
:
Sensible_T
.
weather
.
wIndex
.
wctIndex
[
0
].
current
.
index
,
//체감온도
...
...
@@ -78,9 +108,11 @@ module.exports = (server, app) => {
time
:
Current_Weather
.
weather
.
minutely
[
0
].
timeObservation
,
// 불러온 시각
Forecast_3D
:
Day3_Weather
.
weather
.
forecast3days
[
0
].
fcst3hour
.
wind
.
wspd64hour
,
traffic
:
Traffic_Accident
.
totalCount
,
// 교통사고 발생횟수
death_prob
:
0
//확률
}
console
.
log
(
"API INFO \n"
,
info
);
console
.
log
(
"Traffic count:"
,
info
.
traffic
);
...
...
@@ -98,7 +130,7 @@ module.exports = (server, app) => {
//죽을 확률 계산(내맘대로 커스텀)
info
.
death_prob
=
(
(
info
.
heat
/
50
)
+
(
Math
.
abs
(
info
.
sensible_temperature
-
15
)
/
10
)
+
(
info
.
discomport
/
10
)
+
(
info
.
UV
/
10
)
+
info
.
windspd
*
1
+
(
info
.
rain
/
10
)
+
(
Math
.
abs
(
info
.
current_temperature
-
15
)
/
10
)
+
info
.
windspd
*
1
+
(
info
.
rain
/
10
)
+
(
Math
.
abs
(
info
.
current_temperature
-
15
)
/
10
)
+
(
info
.
traffic
/
5
)
);
//이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보
...
...
routes/index.js
View file @
1ee0179
...
...
@@ -132,7 +132,8 @@ router.get('/Cname/:Cname/Cbirth/:Cbirth', (req,res) => {
});
}
});
}
)
});
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
res
.
render
(
'main'
);
});
...
...
Please
register
or
login
to post a comment