이의준
...@@ -8,6 +8,7 @@ require('dotenv').config(); ...@@ -8,6 +8,7 @@ require('dotenv').config();
8 //console.log(BusArrivalUrl); 8 //console.log(BusArrivalUrl);
9 var routeID = ['200000112', '200000115', '234000016', '200000103']; 9 var routeID = ['200000112', '200000115', '234000016', '200000103'];
10 var Bus = []; 10 var Bus = [];
11 +var BusNum = [];
11 // request(BusArrivalUrl, (err, res, body) => { 12 // request(BusArrivalUrl, (err, res, body) => {
12 // var $ = cheerio.load(body, {decodeEntities: false}); 13 // var $ = cheerio.load(body, {decodeEntities: false});
13 // $('busArrivalList').each(function(idx){ 14 // $('busArrivalList').each(function(idx){
...@@ -41,6 +42,7 @@ function getBusNum(){ ...@@ -41,6 +42,7 @@ function getBusNum(){
41 newBus.MaxTime = maxtime; 42 newBus.MaxTime = maxtime;
42 //console.log(newBus); 43 //console.log(newBus);
43 Bus.push(newBus); 44 Bus.push(newBus);
45 + BusNum.push(num);
44 //console.log(Bus); 46 //console.log(Bus);
45 }) 47 })
46 }) 48 })
...@@ -51,9 +53,19 @@ for(var i=0; i<routeID.length; i++){ ...@@ -51,9 +53,19 @@ for(var i=0; i<routeID.length; i++){
51 const GateBusUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + gateStationID; //국제캠 정문 정류장 53 const GateBusUrl = bus_url + '?servicekey=' + process.env.key + '&stationId=' + gateStationID; //국제캠 정문 정류장
52 let date = new Date(); 54 let date = new Date();
53 let predictTime = ['-1', '-1', '-1', '-1']; 55 let predictTime = ['-1', '-1', '-1', '-1'];
54 -let body = new Object(); 56 +
57 +module.exports.data = [];
58 +
55 function predict(){ 59 function predict(){
56 - console.log(GateBusUrl); 60 + //console.log(GateBusUrl);
61 + if(module.exports.data.length == 0){
62 + for(var i=0; i<BusNum.length; i++){
63 + var info = new Object();
64 + info.BusNum = BusNum[i];
65 +
66 + module.exports.data.push(info);
67 + }
68 + }
57 request(GateBusUrl, (err, res, body) => { 69 request(GateBusUrl, (err, res, body) => {
58 var $ = cheerio.load(body, {decodeEntities: false}); 70 var $ = cheerio.load(body, {decodeEntities: false});
59 $('busArrivalList').each(function(idx){ 71 $('busArrivalList').each(function(idx){
...@@ -61,6 +73,7 @@ function predict(){ ...@@ -61,6 +73,7 @@ function predict(){
61 var index = Bus.findIndex(function(e, idx){ return e.routeId == route;}); 73 var index = Bus.findIndex(function(e, idx){ return e.routeId == route;});
62 if(index > -1){ 74 if(index > -1){
63 //var num = $(this).find('plateNo1').text(); // 버스 차량번호 ex) 70사 1290 75 //var num = $(this).find('plateNo1').text(); // 버스 차량번호 ex) 70사 1290
76 + console.log(Bus[index].BusNum);
64 var time = $(this).find('predictTime1').text(); // 버스 예상 도착시간 77 var time = $(this).find('predictTime1').text(); // 버스 예상 도착시간
65 var predictHour1 = date.getHours(); 78 var predictHour1 = date.getHours();
66 var predictMinute1 = date.getMinutes() + parseInt(Bus[index].MinTime) - (3 - parseInt(time)); // 사색의 광장 -> 경희대학교 3분정도 소요 79 var predictMinute1 = date.getMinutes() + parseInt(Bus[index].MinTime) - (3 - parseInt(time)); // 사색의 광장 -> 경희대학교 3분정도 소요
...@@ -89,14 +102,15 @@ function predict(){ ...@@ -89,14 +102,15 @@ function predict(){
89 102
90 103
91 //controller에 데이터 전송 104 //controller에 데이터 전송
92 - module.exports.data = {};
93 - module.exports.data.remainTime = gapHour + "시간" + gapMin + "분 이상";
94 - module.exports.data.ETD_min_H = predictTime[0];
95 - module.exports.data.ETD_min_M = predictTime[1];
96 - module.exports.data.ETD_max_H = predictTime[2];
97 - module.exports.data.ETD_max_M = predictTime[3];
98 105
106 + var busIndex = module.exports.data.findIndex(function(e, idx){ return e.BusNum == Bus[index].BusNum;});
107 + console.log(busIndex);
99 108
109 + module.exports.data[busIndex]["remainTime"] = gapHour + "시간" + gapMin + "분 이상";
110 + module.exports.data[busIndex]["ETD_min_H"] = predictTime[0];
111 + module.exports.data[busIndex]["ETD_min_M"] = predictTime[1];
112 + module.exports.data[busIndex]["ETD_max_H"] = predictTime[2];
113 + module.exports.data[busIndex]["ETD_max_M"] = predictTime[3];
100 } 114 }
101 }) 115 })
102 }) 116 })
...@@ -107,4 +121,4 @@ function predict(){ ...@@ -107,4 +121,4 @@ function predict(){
107 function start(){ 121 function start(){
108 setInterval(predict, 60000); 122 setInterval(predict, 60000);
109 } 123 }
110 -setTimeout(start, 20000); 124 +setTimeout(start, 10000);
......
...@@ -13,8 +13,9 @@ exports.mainView = function(req, res) { ...@@ -13,8 +13,9 @@ exports.mainView = function(req, res) {
13 }//main 화면 13 }//main 화면
14 14
15 exports.timeTable = function(req, res) { 15 exports.timeTable = function(req, res) {
16 - res.render("ejstest.ejs",{busNum:req.query.busNum, remainTime: Businfo.data.remainTime, ETD_min_H: Businfo.data.ETD_min_H, 16 + var index = Businfo.data.findIndex(function(e, idx){ return e.BusNum == req.query.busNum;});
17 - ETD_min_m: Businfo.data.ETD_max_m, ETD_max_H: Businfo.data.ETD_max_H, ETD_max_m: Businfo.data.ETD_max_m }); 17 + res.render("timetable.ejs",{busNum:req.query.busNum, remainTime: Businfo.data[index].remainTime, ETD_min_H: Businfo.data[index].ETD_min_H,
18 + ETD_min_m: Businfo.data[index].ETD_min_M, ETD_max_H: Businfo.data[index].ETD_max_H, ETD_max_m: Businfo.data[index].ETD_max_M });
18 } //timeTable 화면 ejs 변수 렌더링 19 } //timeTable 화면 ejs 변수 렌더링
19 20
20 21
......