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-05-31 16:24:04 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a08a4c56ab8f31f36963870b15e5fc84a3000afb
a08a4c56
1 parent
34d1e3a0
일부 수정,테스트중
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
2 deletions
lib/socketio.js
lib/socketio.js
View file @
a08a4c5
const
db
=
require
(
'./db.js'
);
const
secret_key
=
require
(
'../keys/api_option'
).
key
;
const
secret_D_key
=
require
(
'../keys/api_option'
).
D_key
;
//사망교통사고 키
const
requesting
=
require
(
'request'
);
const
lat
=
"37.239795"
;
const
lon
=
"127.083240"
;
...
...
@@ -23,6 +24,9 @@ module.exports = (server, app) => {
let
info
=
{}
const
req_API
=
(
when
,
what
)
=>
{
//async await 사용하기 위하여 promise 사용
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -44,6 +48,30 @@ module.exports = (server, app) => {
});
})
}
const
req_D_API
=
()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
requesting
.
get
({
// api를 요청할 주소 -- 시크릿키 입력, 경기도 수원시 설정
url
:
`http://taas.koroad.or.kr/data/rest/accident/death?authKey=
${
secret_D_key
}
searchYear=2018&sido=1300&guGun=1302&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 api"
);
resolve
(
api_body
);
}
});
})
}
const
API_bundle
=
async
()
=>
{
try
{
...
...
@@ -52,7 +80,8 @@ module.exports = (server, app) => {
Heat_index
=
await
req_API
(
"index"
,
"heat"
);
//열지수
Discomport_index
=
await
req_API
(
"index"
,
"th"
);
//불쾌지수
Ultra_Violet_index
=
await
req_API
(
"index"
,
"uv"
);
//자외선지수
let
kts
=
await
req_D_API
();
info
=
{
heat
:
Heat_index
.
weather
.
wIndex
.
heatIndex
[
0
].
current
.
index
,
//열지수
sensible_temperature
:
Sensible_T
.
weather
.
wIndex
.
wctIndex
[
0
].
current
.
index
,
//체감온도
...
...
@@ -66,10 +95,13 @@ module.exports = (server, app) => {
warning
:
Current_Weather
.
common
.
alertYn
,
//현재 특보 유무
typhoon
:
Current_Weather
.
common
.
stormYn
,
//현재 태풍
time
:
Current_Weather
.
weather
.
minutely
[
0
].
timeObservation
,
// 불러온 시각
death_prob
:
0
//확률
death_prob
:
0
,
//확률
}
console
.
log
(
"API INFO \n"
,
info
);
// ------------------------------ death_prob 정의 ------------------------------
info
.
death_prob
+=
info
.
sky
.
substr
(
5
)
*
1
//하늘 상태에 따라 확률 증가
...
...
Please
register
or
login
to post a comment