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 17:07:44 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7ab3a8f55f5c35b50b365dd31e0c11ed51195cab
7ab3a8f5
1 parent
c7416d07
교통사고 api 추가
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
FatalTrafficAccidents_CodeList.xlsx
lib/socketio.js
routes/index.js
FatalTrafficAccidents_CodeList.xlsx
0 → 100644
View file @
7ab3a8f
No preview for this file type
lib/socketio.js
View file @
7ab3a8f
const
db
=
require
(
'./db.js'
);
const
secret_key
=
require
(
'../keys/api_option'
).
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
,
{
...
...
@@ -14,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
=
""
;
...
...
@@ -44,6 +50,29 @@ 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
{
...
...
@@ -53,6 +82,11 @@ module.exports = (server, app) => {
Discomport_index
=
await
req_API
(
"index"
,
"th"
);
//불쾌지수
Ultra_Violet_index
=
await
req_API
(
"index"
,
"uv"
);
//자외선지수
// 사용자의 생일에 따라서 다른 년도의 교통사고정보를 가져옴.
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
,
//체감온도
...
...
@@ -66,9 +100,11 @@ module.exports = (server, app) => {
warning
:
Current_Weather
.
common
.
alertYn
,
//현재 특보 유무
typhoon
:
Current_Weather
.
common
.
stormYn
,
//현재 태풍
time
:
Current_Weather
.
weather
.
minutely
[
0
].
timeObservation
,
// 불러온 시각
traffic
:
Traffic_Accident
.
totalCount
,
// 교통사고 발생횟수
death_prob
:
0
//확률
}
console
.
log
(
"API INFO \n"
,
info
);
console
.
log
(
"Traffic count:"
,
info
.
traffic
);
// ------------------------------ death_prob 정의 ------------------------------
...
...
@@ -84,7 +120,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 @
7ab3a8f
...
...
@@ -66,7 +66,8 @@ router.get('/name/:name/birth/:birth', (req,res) => {
});
}
});
}
)
});
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
res
.
render
(
'main'
);
});
...
...
Please
register
or
login
to post a comment