Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍용민
/
BusTime
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
홍용민
2021-05-31 21:17:38 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e473526bcf732d8690d0b4e6e7b7e9e6d83957b9
e473526b
1 parent
715215a9
다음 버스 시간 예측
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
31 deletions
BusInfo.js
BusInfo.js
View file @
e473526
...
...
@@ -10,8 +10,7 @@ const BusArrivalUrl = bus_url + '?servicekey=' + bus_key + '&stationId=' + stati
//console.log(BusArrivalUrl);
var
routeID
=
[];
var
Bus
=
[];
// 버스 차 번호( ex) 경기 70바 3713 ) / 도착 여부 확인용
var
BusNum
=
[];
// 버스 번호 ( ex) 9)
var
Bus
=
[];
request
(
BusArrivalUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
...
...
@@ -65,32 +64,48 @@ function useFor(){
}
setTimeout
(
useFor
,
500
);
// const GateBusUrl = bus_url + '?servicekey=' + bus_key + '&stationId=' + gateStationID;
// request(GateBusUrl, (err, res, body) => {
// var $ = cheerio.load(body, {decodeEntities: false});
// $('busArrivalList').each(function(idx){
// let route = $(this).find('routeId').text();
// let num = $(this).find('plateNo1').text();
// var index = routeID.indexOf(route);
// if(index > -1){
// for(var i=0; i<Bus.length; i++){
// if(Bus[i]['route'] == route){
// if(Bus[i]['num'] != num){
// Bus[i]['pass'] = true;
// Bus[i]['num'] == num;
// }
// }
// }
// var info = new Object();
// info.route = route;
// info.num = num;
// info.pass = false; // json 형태로 저장
// Bus.push(info);
// }
// })
// //console.log(routeID);
// //console.log(Bus);
// })
\ No newline at end of file
const
GateBusUrl
=
bus_url
+
'?servicekey='
+
bus_key
+
'&stationId='
+
gateStationID
;
//국제캠 정문 정류장
let
date
=
new
Date
();
let
curHour
=
date
.
getHours
();
// 현재 시간
let
curMinute
=
date
.
getMinutes
();
//현재 분
function
predict
(){
request
(
GateBusUrl
,
(
err
,
res
,
body
)
=>
{
var
$
=
cheerio
.
load
(
body
,
{
decodeEntities
:
false
});
$
(
'busArrivalList'
).
each
(
function
(
idx
){
let
route
=
$
(
this
).
find
(
'routeId'
).
text
();
var
index
=
Bus
.
findIndex
(
function
(
e
,
idx
){
return
e
.
routeId
==
route
;});
if
(
index
>
-
1
){
//var num = $(this).find('plateNo1').text(); // 버스 차량번호 ex) 70사 1290
var
time
=
$
(
this
).
find
(
'predictTime1'
).
text
();
// 버스 예상 도착시간
var
predictHour1
=
date
.
getHours
();
var
predictMinute1
=
date
.
getMinutes
()
+
Bus
[
index
].
mintime
-
(
3
-
(
time
*
1
));
// 사색의 광장 -> 경희대학교 3분정도 소요
var
predictHour2
=
date
.
getHours
();
var
predictMinute2
=
date
.
getMinutes
()
+
Bus
[
index
].
maxtime
-
(
3
-
(
time
*
1
));
// time*1 : string to integer 형변환
if
(
predictMinute1
>=
60
){
predictHour1
+=
1
;
predictMinute1
-=
60
;
}
if
(
predictMinute2
>=
60
){
predictHour2
+=
1
;
predictMinute2
-=
60
;
}
Bus
[
index
][
"MinPredictTime"
]
=
predictHour1
+
":"
+
predictMinute1
;
Bus
[
index
][
"MaxPredictTime"
]
=
predictHour2
+
":"
+
predictMinute2
;
}
})
console
.
log
(
Bus
);
})
}
function
useWhile
(){
while
(
true
){
setTimeout
(
predict
,
6000
);
}
}
setTimeout
(
useWhile
,
1000
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment