최현영

Expressway travel time fo IC to IC is making...

...@@ -21,7 +21,7 @@ const datafeejson = feebuffer.toString(); ...@@ -21,7 +21,7 @@ const datafeejson = feebuffer.toString();
21 const feedata = JSON.parse(datafeejson); 21 const feedata = JSON.parse(datafeejson);
22 console.log("Expressfee.json 파일 읽기"); 22 console.log("Expressfee.json 파일 읽기");
23 23
24 -const namebuffer = fs.roadFileSync('./whereur/ExpressIC.json'); 24 +const namebuffer = fs.readFileSync('./whereur/ExpressIC.json');
25 const datanamejson = namebuffer.toString(); 25 const datanamejson = namebuffer.toString();
26 const namedata = JSON.parse(datanamejson); 26 const namedata = JSON.parse(datanamejson);
27 console.log("Expressname.json 파일 열기"); 27 console.log("Expressname.json 파일 열기");
...@@ -56,18 +56,6 @@ router.route('/process/maprealtime').get(function(req, res){ ...@@ -56,18 +56,6 @@ router.route('/process/maprealtime').get(function(req, res){
56 }); 56 });
57 57
58 58
59 -router.route('/process/construction').get(function(req, res){
60 - console.log('process/maprealconstruction 호출됨');
61 - res.end();
62 -});
63 -
64 -router.route('/process/mapcctv').get(function(req, res){
65 - console.log('process/mapcctv 호출됨');
66 - res.end();
67 -});
68 -
69 -
70 -
71 function jsonforecast(callback){ //교통예보 59 function jsonforecast(callback){ //교통예보
72 var url2 = 'http://data.ex.co.kr/openapi/safeDriving/forecast'; 60 var url2 = 'http://data.ex.co.kr/openapi/safeDriving/forecast';
73 var queryParams2 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/ 61 var queryParams2 = '?' + encodeURIComponent('key') + '=4365330273'; /* Service Key*/
...@@ -106,17 +94,26 @@ function jsoncongest(callback){ //교통정체 ...@@ -106,17 +94,26 @@ function jsoncongest(callback){ //교통정체
106 }); 94 });
107 } 95 }
108 96
97 +function jsonICtoICtime(startICcode, endICcode, callback){
98 + var url3 = 'http://data.ex.co.kr/openapi/trtm/realUnitTrtm';
99 + var queryParams3 = '?' + encodeURIComponent('key') + '=4365330273';
100 + queryParams3 += '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json');
101 + queryParams3 += '&' + encodeURIComponent('iStartUnitCode') + '=' + startICcode + '&' + encodeURIComponent('iEndUnitCode') + '=' + endICcode + '&' + encodeURIComponent('numOfRows') + '=10'+ '&' + encodeURIComponent('pageNo') + '=1'
109 102
110 - 103 + request({
111 -function nexttext(typetext){ 104 + url: url3 + queryParams3,
112 - if(typetext == '다음'){ 105 + method: 'GET'
113 - return true; 106 + }, function (error, response, body) {
114 - } 107 + console.log('Status', response.statusCode);
108 + console.log('Headers', JSON.stringify(response.headers));
109 + console.log('Reponse received', body);
110 + var obj = JSON.parse(body);
111 + console.log(obj);
112 + callback(obj);
113 + });
115 } 114 }
116 115
117 116
118 -
119 -
120 app.use('/', router); 117 app.use('/', router);
121 118
122 119
...@@ -142,6 +139,9 @@ function firstforecast(isforecast){ ...@@ -142,6 +139,9 @@ function firstforecast(isforecast){
142 else if(isforecast == '4'){ 139 else if(isforecast == '4'){
143 return true; 140 return true;
144 } 141 }
142 + else if (isforecast == '5'){
143 + return true;
144 + }
145 else { 145 else {
146 return false; 146 return false;
147 } 147 }
...@@ -184,7 +184,7 @@ function isroadnumber(typetext){ ...@@ -184,7 +184,7 @@ function isroadnumber(typetext){
184 } 184 }
185 } 185 }
186 186
187 -function isroadname(typetext){ 187 +function findroadname(typetext){
188 if(typetext == '나들목정보'){ 188 if(typetext == '나들목정보'){
189 return true; 189 return true;
190 } 190 }
...@@ -193,6 +193,12 @@ function isroadname(typetext){ ...@@ -193,6 +193,12 @@ function isroadname(typetext){
193 } 193 }
194 } 194 }
195 195
196 +function nexttext(typetext){
197 + if(typetext == '다음'){
198 + return true;
199 + }
200 +}
201 +
196 202
197 function inputroadnumber(typetext){ 203 function inputroadnumber(typetext){
198 if(typetext.indexOf("번") >= 0){ 204 if(typetext.indexOf("번") >= 0){
...@@ -263,7 +269,13 @@ function wanttoknowfee(typetext){ ...@@ -263,7 +269,13 @@ function wanttoknowfee(typetext){
263 } 269 }
264 } 270 }
265 271
266 - 272 +function wanttoknowtime(typetext){
273 + if(typetext.indexOf(",") >= 0){
274 + return true;
275 + }else{
276 + return false;
277 + }
278 +}
267 279
268 280
269 281
...@@ -285,12 +297,11 @@ app.post('/hook', function (req, res) { ...@@ -285,12 +297,11 @@ app.post('/hook', function (req, res) {
285 var isfee; 297 var isfee;
286 var istime; 298 var istime;
287 299
288 -
289 -
290 // request log 300 // request log
291 console.log('======================', new Date() ,'======================'); 301 console.log('======================', new Date() ,'======================');
292 console.log('[request]', req.body); 302 console.log('[request]', req.body);
293 console.log('[request source] ', source); 303 console.log('[request source] ', source);
304 + console.log('[request UserId]', source.userId);
294 console.log('[request message]', message); 305 console.log('[request message]', message);
295 306
296 console.log(userroadcongest[source.userId]); 307 console.log(userroadcongest[source.userId]);
...@@ -309,7 +320,7 @@ app.post('/hook', function (req, res) { ...@@ -309,7 +320,7 @@ app.post('/hook', function (req, res) {
309 roadnumber(eventObj); 320 roadnumber(eventObj);
310 } 321 }
311 322
312 - isroadname = isroadname(message.text); 323 + isroadname = findroadname(message.text);
313 if(isroadname == true){ 324 if(isroadname == true){
314 console.log("나들목 이름을 궁금해 합니다."); 325 console.log("나들목 이름을 궁금해 합니다.");
315 roadname(eventObj); 326 roadname(eventObj);
...@@ -334,6 +345,10 @@ app.post('/hook', function (req, res) { ...@@ -334,6 +345,10 @@ app.post('/hook', function (req, res) {
334 console.log("[request Order] ", message); 345 console.log("[request Order] ", message);
335 leadfee(eventObj); 346 leadfee(eventObj);
336 } 347 }
348 + else if (message.text == '5') {
349 + console.log("[request Order] ", message);
350 + leadtime(eventObj);
351 + }
337 } 352 }
338 353
339 isselecttypeforecast = selecttypeforecast(message.text); 354 isselecttypeforecast = selecttypeforecast(message.text);
...@@ -390,12 +405,14 @@ app.post('/hook', function (req, res) { ...@@ -390,12 +405,14 @@ app.post('/hook', function (req, res) {
390 timelead(eventObj, message.text); 405 timelead(eventObj, message.text);
391 } 406 }
392 407
408 +
393 isinputroadname = israodnameExist(message.text); 409 isinputroadname = israodnameExist(message.text);
394 if(isinputroadname == true ){ 410 if(isinputroadname == true ){
395 - isinputroadname(eventObj, message.text); 411 + inputroadname(eventObj, message.text);
396 -
397 } 412 }
398 413
414 +
415 +
399 res.sendStatus(200); 416 res.sendStatus(200);
400 }); 417 });
401 418
...@@ -419,7 +436,7 @@ function helloworld(eventObj){ ...@@ -419,7 +436,7 @@ function helloworld(eventObj){
419 }, 436 },
420 { 437 {
421 "type":"text", 438 "type":"text",
422 - "text":"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을, 교통요금이 궁금하시다면 4번을, 나들목간 평균시간" 439 + "text":"현재 교통 예보가 궁금하시다면 1번을, 실시간 교통혼잡 상황을 보실려면 2번을, 실시간 정체상황을 알고 싶다면 3번을, 교통요금이 궁금하시다면 4번을, 나들목간 통행평균시간이 궁금하시다면 5번을 눌러주세요. "
423 }, 440 },
424 { 441 {
425 "type":"text", 442 "type":"text",
...@@ -490,6 +507,44 @@ function leadfee(eventObj){ ...@@ -490,6 +507,44 @@ function leadfee(eventObj){
490 }); 507 });
491 } 508 }
492 509
510 +function leadtime(eventObj){
511 + request.post(
512 + {
513 + url: TARGET_URL,
514 + headers: {
515 + 'Authorization': `Bearer ${TOKEN}`
516 + },
517 + json: {
518 + "replyToken":eventObj.replyToken,
519 + "messages":[
520 + {
521 + "type":"text",
522 + "text":"나들목(영업소)간 평균 통행시간 안내를 시작합니다."
523 + },
524 + {
525 + "type":"text",
526 + "text":"불완전한 서비스입니다. 정보 제공처에서 제공을 안할 수 있습니다. 이점 유의해 주세요."
527 + },
528 + {
529 + "type":"text",
530 + "text":"출발하실 나들목(IC)의 이름과 도착하실 나들목(IC)의 이름을 순서대로 적어주세요."
531 + },
532 + {
533 + "type":"text",
534 + "text":"예)남안동,서안동"
535 + },
536 + {
537 + "type":"text",
538 + "text":"예) 예천,서안동"
539 + }
540 + ]
541 + }
542 + },(error, response, body) => {
543 + console.log(body)
544 + });
545 +}
546 +
547 +
493 548
494 function findroad(eventObj){ 549 function findroad(eventObj){
495 jsonforecast(function(object){ 550 jsonforecast(function(object){
...@@ -837,7 +892,7 @@ function roadname(eventObj){ ...@@ -837,7 +892,7 @@ function roadname(eventObj){
837 }, 892 },
838 { 893 {
839 "type":"text", 894 "type":"text",
840 - "test":"예) 검색:안동" 895 + "text":"예) 검색:안동"
841 } 896 }
842 ] 897 ]
843 } 898 }
...@@ -881,17 +936,20 @@ function tieupselect(eventObj){ ...@@ -881,17 +936,20 @@ function tieupselect(eventObj){
881 }); 936 });
882 } 937 }
883 938
884 -function isinputroadname(eventObj, msg){ 939 +function inputroadname(eventObj, msg){
885 var icnamelist = new Array(); 940 var icnamelist = new Array();
886 var iclist = ""; 941 var iclist = "";
887 - var ExpressICnameLength = namedata.length; 942 + var ExpressICnameLength = namedata.unitLists.length;
888 var icnamelist = msg.split(':'); 943 var icnamelist = msg.split(':');
889 var isthat = false; 944 var isthat = false;
890 - var iscout = 0; 945 + var iscount = 0;
946 + console.log(ExpressICnameLength);
947 + console.log(icnamelist[1]);
891 for(var i = 0; i < ExpressICnameLength; i++){ 948 for(var i = 0; i < ExpressICnameLength; i++){
892 if(namedata.unitLists[i].unitName.indexOf(icnamelist[1]) >= 0 ){ 949 if(namedata.unitLists[i].unitName.indexOf(icnamelist[1]) >= 0 ){
893 isthat = true; 950 isthat = true;
894 - iclist = "#" + str(iscount) + " " + namedata.unitLists[i].unitName + " "; 951 + iscount += 1;
952 + iclist += "#" + String(iscount) + " " + namedata.unitLists[i].unitName + " ";
895 } 953 }
896 } 954 }
897 955
...@@ -906,7 +964,7 @@ function isinputroadname(eventObj, msg){ ...@@ -906,7 +964,7 @@ function isinputroadname(eventObj, msg){
906 "messages":[ 964 "messages":[
907 { 965 {
908 "type":"text", 966 "type":"text",
909 - "text":"검색결과입니다. : " + msg 967 + "text":"검색결과입니다. : " + iclist
910 } 968 }
911 969
912 ] 970 ]
...@@ -914,8 +972,6 @@ function isinputroadname(eventObj, msg){ ...@@ -914,8 +972,6 @@ function isinputroadname(eventObj, msg){
914 },(error, response, body) => { 972 },(error, response, body) => {
915 console.log(body) 973 console.log(body)
916 }); 974 });
917 -
918 -
919 } 975 }
920 976
921 977
...@@ -978,7 +1034,7 @@ function roadcongest(eventObj, msg, userid){ ...@@ -978,7 +1034,7 @@ function roadcongest(eventObj, msg, userid){
978 "messages":[ 1034 "messages":[
979 { 1035 {
980 "type":"text", 1036 "type":"text",
981 - "text":"검색하신 노선에서 발견된 정체량은 총 " + str(userroadcongestlength[userid]) + "입니다." 1037 + "text":"검색하신 노선에서 발견된 정체량은 총 " + String(userroadcongestlength[userid]) + "입니다."
982 }, 1038 },
983 { 1039 {
984 "type":"text", 1040 "type":"text",
...@@ -1095,8 +1151,97 @@ function feelead(eventObj, msg){ ...@@ -1095,8 +1151,97 @@ function feelead(eventObj, msg){
1095 1151
1096 1152
1097 1153
1154 +function timelead(eventObj, msg){
1155 + var isstart = false;
1156 + var isend = false;
1157 + var start = "";
1158 + var end = "";
1159 + var inputoutputIC = msg.split(',');
1160 + inputoutputIC[0].trim();
1161 + inputoutputIC[1].trim();
1162 + console.log(inputoutputIC[0]);
1163 + console.log(inputoutputIC[1]);
1164 + var length = namedata.unitLists.length;
1165 + for(var i = 0; i < length; i++){
1166 + if(namedata.unitName == inputoutputIC[0]){
1167 + start = namedata.unitCode;
1168 + isstart = true;
1169 + }
1170 + if(namedata.unitName == inputoutputIC[1]){
1171 + end = namedata.unitCode;
1172 + isend = false;
1173 + }
1174 + }
1098 1175
1176 + if(isstart == true && isend == true){
1177 + jsonICtoICtime(start, end, function(Object){
1178 + var avgTime = new Array();
1179 + var ICtimejson = Object;
1180 + var avgTime = ICtimejson.realUnitTrtmVO.timeAvg.split('.');
1181 + if(ICtimejson.count > 0){
1182 + request.post(
1183 + {
1184 + url: TARGET_URL,
1185 + headers: {
1186 + 'Authorization': `Bearer ${TOKEN}`
1187 + },
1188 + json: {
1189 + "replyToken":eventObj.replyToken,
1190 + "messages":[
1191 + {
1192 + "type":"text",
1193 + "text":ICtimejson.realUnitTrtmVO[0].startUnitNm + "나들목에서 " + ICtimejson.realUnitTrtmVO[0].endUnitNm + "나들목까지 평균 소요시간은 " + avg
1194 + }
1195 + ]
1196 + }
1197 + },(error, response, body) => {
1198 + console.log(body)
1199 + });
1099 1200
1201 + }
1202 + else{
1203 + request.post(
1204 + {
1205 + url: TARGET_URL,
1206 + headers: {
1207 + 'Authorization': `Bearer ${TOKEN}`
1208 + },
1209 + json: {
1210 + "replyToken":eventObj.replyToken,
1211 + "messages":[
1212 + {
1213 + "type":"text",
1214 + "text":"죄송합니다. 정보가 없습니다."
1215 + }
1216 + ]
1217 + }
1218 + },(error, response, body) => {
1219 + console.log(body)
1220 + });
1221 + }
1222 + });
1223 + }
1224 + else{
1225 + request.post(
1226 + {
1227 + url: TARGET_URL,
1228 + headers: {
1229 + 'Authorization': `Bearer ${TOKEN}`
1230 + },
1231 + json: {
1232 + "replyToken":eventObj.replyToken,
1233 + "messages":[
1234 + {
1235 + "type":"text",
1236 + "text":"일치하는 나들목이 없습니다. 다시 입력해 주세요."
1237 + }
1238 + ]
1239 + }
1240 + },(error, response, body) => {
1241 + console.log(body)
1242 + });
1243 + }
1244 +}
1100 1245
1101 1246
1102 try { 1247 try {
......