Showing
1 changed file
with
16 additions
and
13 deletions
... | @@ -12,6 +12,7 @@ require('dotenv').config(); | ... | @@ -12,6 +12,7 @@ require('dotenv').config(); |
12 | 12 | ||
13 | var routeID = ['200000112', '200000115', '234000016', '200000103']; | 13 | var routeID = ['200000112', '200000115', '234000016', '200000103']; |
14 | var Bus = []; | 14 | var Bus = []; |
15 | +var busNum = []; | ||
15 | // request(BusArrivalUrl, (err, res, body) => { | 16 | // request(BusArrivalUrl, (err, res, body) => { |
16 | // var $ = cheerio.load(body, {decodeEntities: false}); | 17 | // var $ = cheerio.load(body, {decodeEntities: false}); |
17 | 18 | ||
... | @@ -53,6 +54,7 @@ function getBusNum(){ | ... | @@ -53,6 +54,7 @@ function getBusNum(){ |
53 | 54 | ||
54 | console.log(newBus); | 55 | console.log(newBus); |
55 | Bus.push(newBus); | 56 | Bus.push(newBus); |
57 | + busNum.push(num); | ||
56 | }) | 58 | }) |
57 | }) | 59 | }) |
58 | } | 60 | } |
... | @@ -74,13 +76,14 @@ function predict(){ | ... | @@ -74,13 +76,14 @@ function predict(){ |
74 | let route = $(this).find('routeId').text(); | 76 | let route = $(this).find('routeId').text(); |
75 | 77 | ||
76 | var index = Bus.findIndex(function(e, idx){ return e.routeId == route;}); | 78 | var index = Bus.findIndex(function(e, idx){ return e.routeId == route;}); |
79 | + console.log(index); | ||
77 | if(index > -1){ | 80 | if(index > -1){ |
78 | //var num = $(this).find('plateNo1').text(); // 버스 차량번호 ex) 70사 1290 | 81 | //var num = $(this).find('plateNo1').text(); // 버스 차량번호 ex) 70사 1290 |
79 | var time = $(this).find('predictTime1').text(); // 버스 예상 도착시간 | 82 | var time = $(this).find('predictTime1').text(); // 버스 예상 도착시간 |
80 | var predictHour1 = date.getHours(); | 83 | var predictHour1 = date.getHours(); |
81 | - var predictMinute1 = date.getMinutes() + Bus[index].mintime - (3 - (time*1)); // 사색의 광장 -> 경희대학교 3분정도 소요 | 84 | + var predictMinute1 = date.getMinutes() + parseInt(Bus[index].MinTime) - (3 - parseInt(time)); // 사색의 광장 -> 경희대학교 3분정도 소요 |
82 | var predictHour2 = date.getHours(); | 85 | var predictHour2 = date.getHours(); |
83 | - var predictMinute2 = date.getMinutes() + Bus[index].maxtime - (3 - (time*1)); // time*1 : string to integer 형변환 | 86 | + var predictMinute2 = date.getMinutes() + parseInt(Bus[index].MaxTime)- (3 - parseInt(time)); // time*1 : string to integer 형변환 |
84 | 87 | ||
85 | if(predictMinute1 >= 60){ | 88 | if(predictMinute1 >= 60){ |
86 | predictHour1 += 1; | 89 | predictHour1 += 1; |
... | @@ -102,18 +105,16 @@ function predict(){ | ... | @@ -102,18 +105,16 @@ function predict(){ |
102 | var gapHour = Math.floor(gapSec / 60 / 60); | 105 | var gapHour = Math.floor(gapSec / 60 / 60); |
103 | var gapMin = Math.floor((gapSec - gapHour * 3600) / 60); | 106 | var gapMin = Math.floor((gapSec - gapHour * 3600) / 60); |
104 | 107 | ||
105 | - // var ans = gapHour + "시간" + gapMin + "분 이상"; | 108 | + module.exports.data = {}; |
106 | 109 | ||
107 | - // var ETD_min_H = predictTime[0]; | 110 | + module.exports.data.remainTime = gapHour + "시간" + gapMin + "분 이상"; |
108 | - // var ETD_min_M = predictTime[1]; | 111 | + module.exports.data.ETD_min_H = predictTime[0]; |
109 | - // var ETD_max_H = predictTime[2]; | 112 | + module.exports.data.ETD_min_M = predictTime[1]; |
110 | - // var ETD_max_M = predictTime[3]; | 113 | + module.exports.data.ETD_max_H = predictTime[2]; |
114 | + module.exports.data.ETD_max_M = predictTime[3]; | ||
115 | + module.exports.data.busNum = Bus[index]["BusNum"]; | ||
111 | 116 | ||
112 | - module.exports.remainTime = gapHour + "시간" + gapMin + "분 이상"; | 117 | + console.log(predictTime); |
113 | - module.exports.ETD_min_H = predictTime[0]; | ||
114 | - module.exports.ETD_min_M = predictTime[1]; | ||
115 | - module.exports.ETD_max_H = predictTime[2]; | ||
116 | - module.exports.ETD_max_M = predictTime[3]; | ||
117 | } | 118 | } |
118 | }) | 119 | }) |
119 | }) | 120 | }) |
... | @@ -121,6 +122,8 @@ function predict(){ | ... | @@ -121,6 +122,8 @@ function predict(){ |
121 | 122 | ||
122 | function start(){ | 123 | function start(){ |
123 | setInterval(predict, 60000); | 124 | setInterval(predict, 60000); |
125 | + console.log(Bus); | ||
126 | + console.log(busNum); | ||
124 | } | 127 | } |
125 | 128 | ||
126 | -setTimeout(start, 20000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
129 | +setTimeout(start, 10000); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment