Showing
3 changed files
with
233 additions
and
178 deletions
... | @@ -5,12 +5,4 @@ | ... | @@ -5,12 +5,4 @@ |
5 | 5 | ||
6 | .card-body { | 6 | .card-body { |
7 | text-align: center; | 7 | text-align: center; |
8 | -} | ||
9 | - | ||
10 | -.alert{ | ||
11 | - text-align : center; | ||
12 | - width : 50%; | ||
13 | - display: inline-block; | ||
14 | - margin-left: auto; | ||
15 | - margin-right: auto; | ||
16 | } | 8 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -13,144 +13,199 @@ let user_dong; | ... | @@ -13,144 +13,199 @@ let user_dong; |
13 | let userLocation; | 13 | let userLocation; |
14 | let user_latitude; | 14 | let user_latitude; |
15 | let user_longitude; | 15 | let user_longitude; |
16 | +// 등급을 위한 변수 | ||
17 | +let food_A = 2; | ||
18 | +let food_B = 1; | ||
19 | +let fast_food_A = 9; | ||
20 | +let fast_food_B = 5; | ||
21 | +let library_A = 1; | ||
22 | +let institute_A = 60; | ||
23 | +let institute_B = 20; | ||
24 | +let park_A = 10; | ||
25 | +let park_B = 5; | ||
26 | +let cctv_A = 30; | ||
27 | +let cctv_B = 10; | ||
28 | +let light_A = 2; | ||
29 | +let light_B = 1; | ||
30 | +let culture_A = 25; | ||
31 | +let culture_B = 10; | ||
32 | +let shop_A = 5; | ||
33 | +let shop_B = 2; | ||
34 | +let gym_A = 20; | ||
35 | +let gym_B = 10; | ||
36 | + | ||
37 | + | ||
38 | + | ||
16 | // 결과 중 사용자 근처인지 검사하기 위한 변수 | 39 | // 결과 중 사용자 근처인지 검사하기 위한 변수 |
17 | let user_target; | 40 | let user_target; |
18 | let sigun = [{ | 41 | let sigun = [{ |
19 | - sigun_name: '가평군', | 42 | + sigun_name: '가평군', |
20 | - sigun_code: 41820 | 43 | + sigun_code: 41820 |
21 | - }, | 44 | + }, |
22 | - { | 45 | + { |
23 | - sigun_name: '경기도', | 46 | + sigun_name: '경기도', |
24 | - sigun_code: 41000 | 47 | + sigun_code: 41000 |
25 | - }, | 48 | + }, |
26 | - { | 49 | + { |
27 | - sigun_name: '고양시', | 50 | + sigun_name: '고양시', |
28 | - sigun_code: 41280 | 51 | + sigun_code: 41280 |
29 | - }, | 52 | + }, |
30 | - { | 53 | + { |
31 | - sigun_name: '과천시', | 54 | + sigun_name: '과천시', |
32 | - sigun_code: 41290 | 55 | + sigun_code: 41290 |
33 | - }, | 56 | + }, |
34 | - { | 57 | + { |
35 | - sigun_name: '광명시', | 58 | + sigun_name: '광명시', |
36 | - sigun_code: 41210 | 59 | + sigun_code: 41210 |
37 | - }, | 60 | + }, |
38 | - { | 61 | + { |
39 | - sigun_name: '광주시', | 62 | + sigun_name: '광주시', |
40 | - sigun_code: 41610 | 63 | + sigun_code: 41610 |
41 | - }, | 64 | + }, |
42 | - { | 65 | + { |
43 | - sigun_name: '구리시', | 66 | + sigun_name: '구리시', |
44 | - sigun_code: 41310 | 67 | + sigun_code: 41310 |
45 | - }, | 68 | + }, |
46 | - { | 69 | + { |
47 | - sigun_name: '군포시', | 70 | + sigun_name: '군포시', |
48 | - sigun_code: 41410 | 71 | + sigun_code: 41410 |
49 | - }, | 72 | + }, |
50 | - { | 73 | + { |
51 | - sigun_name: '김포시', | 74 | + sigun_name: '김포시', |
52 | - sigun_code: 41570 | 75 | + sigun_code: 41570 |
53 | - }, | 76 | + }, |
54 | - { | 77 | + { |
55 | - sigun_name: '남양주시', | 78 | + sigun_name: '남양주시', |
56 | - sigun_code: 41360 | 79 | + sigun_code: 41360 |
57 | - }, | 80 | + }, |
58 | - { | 81 | + { |
59 | - sigun_name: '동두천시', | 82 | + sigun_name: '동두천시', |
60 | - sigun_code: 41250 | 83 | + sigun_code: 41250 |
61 | - }, | 84 | + }, |
62 | - { | 85 | + { |
63 | - sigun_name: '부천시', | 86 | + sigun_name: '부천시', |
64 | - sigun_code: 41190 | 87 | + sigun_code: 41190 |
65 | - }, | 88 | + }, |
66 | - { | 89 | + { |
67 | - sigun_name: '성남시', | 90 | + sigun_name: '성남시', |
68 | - sigun_code: 41130 | 91 | + sigun_code: 41130 |
69 | - }, | 92 | + }, |
70 | - { | 93 | + { |
71 | - sigun_name: '수원시', | 94 | + sigun_name: '수원시', |
72 | - sigun_code: 41110 | 95 | + sigun_code: 41110 |
73 | - }, | 96 | + }, |
74 | - { | 97 | + { |
75 | - sigun_name: '시흥시', | 98 | + sigun_name: '시흥시', |
76 | - sigun_code: 41390 | 99 | + sigun_code: 41390 |
77 | - }, | 100 | + }, |
78 | - { | 101 | + { |
79 | - sigun_name: '안산시', | 102 | + sigun_name: '안산시', |
80 | - sigun_code: 41270 | 103 | + sigun_code: 41270 |
81 | - }, | 104 | + }, |
82 | - { | 105 | + { |
83 | - sigun_name: '안성시', | 106 | + sigun_name: '안성시', |
84 | - sigun_code: 41550 | 107 | + sigun_code: 41550 |
85 | - }, | 108 | + }, |
86 | - { | 109 | + { |
87 | - sigun_name: '안양시', | 110 | + sigun_name: '안양시', |
88 | - sigun_code: 41170 | 111 | + sigun_code: 41170 |
89 | - }, | 112 | + }, |
90 | - { | 113 | + { |
91 | - sigun_name: '양주시', | 114 | + sigun_name: '양주시', |
92 | - sigun_code: 41630 | 115 | + sigun_code: 41630 |
93 | - }, | 116 | + }, |
94 | - { | 117 | + { |
95 | - sigun_name: '양평군', | 118 | + sigun_name: '양평군', |
96 | - sigun_code: 41830 | 119 | + sigun_code: 41830 |
97 | - }, | 120 | + }, |
98 | - { | 121 | + { |
99 | - sigun_name: '여주시', | 122 | + sigun_name: '여주시', |
100 | - sigun_code: 41670 | 123 | + sigun_code: 41670 |
101 | - }, | 124 | + }, |
102 | - { | 125 | + { |
103 | - sigun_name: '연천군', | 126 | + sigun_name: '연천군', |
104 | - sigun_code: 41800 | 127 | + sigun_code: 41800 |
105 | - }, | 128 | + }, |
106 | - { | 129 | + { |
107 | - sigun_name: '오산시', | 130 | + sigun_name: '오산시', |
108 | - sigun_code: 41370 | 131 | + sigun_code: 41370 |
109 | - }, | 132 | + }, |
110 | - { | 133 | + { |
111 | - sigun_name: '용인시', | 134 | + sigun_name: '용인시', |
112 | - sigun_code: 41460 | 135 | + sigun_code: 41460 |
113 | - }, | 136 | + }, |
114 | - { | 137 | + { |
115 | - sigun_name: '의왕시', | 138 | + sigun_name: '의왕시', |
116 | - sigun_code: 41430 | 139 | + sigun_code: 41430 |
117 | - }, | 140 | + }, |
118 | - { | 141 | + { |
119 | - sigun_name: '의정부시', | 142 | + sigun_name: '의정부시', |
120 | - sigun_code: 41150 | 143 | + sigun_code: 41150 |
121 | - }, | 144 | + }, |
122 | - { | 145 | + { |
123 | - sigun_name: '이천시', | 146 | + sigun_name: '이천시', |
124 | - sigun_code: 41500 | 147 | + sigun_code: 41500 |
125 | - }, | 148 | + }, |
126 | - { | 149 | + { |
127 | - sigun_name: '파주시', | 150 | + sigun_name: '파주시', |
128 | - sigun_code: 41480 | 151 | + sigun_code: 41480 |
129 | - }, | 152 | + }, |
130 | - { | 153 | + { |
131 | - sigun_name: '평택시', | 154 | + sigun_name: '평택시', |
132 | - sigun_code: 41220 | 155 | + sigun_code: 41220 |
133 | - }, | 156 | + }, |
134 | - { | 157 | + { |
135 | - sigun_name: '포천시', | 158 | + sigun_name: '포천시', |
136 | - sigun_code: 41650 | 159 | + sigun_code: 41650 |
137 | - }, | 160 | + }, |
138 | - { | 161 | + { |
139 | - sigun_name: '하남시', | 162 | + sigun_name: '하남시', |
140 | - sigun_code: 41450 | 163 | + sigun_code: 41450 |
141 | - }, | 164 | + }, |
142 | - { | 165 | + { |
143 | - sigun_name: '화성시', | 166 | + sigun_name: '화성시', |
144 | - sigun_code: 41590 | 167 | + sigun_code: 41590 |
145 | - }, | 168 | + }, |
146 | - ] | 169 | +] |
170 | + | ||
171 | +// 등급 평가하는 함수 | ||
172 | +let evalGrade = function(A, B, count) { | ||
173 | + if (count >= A) { | ||
174 | + return 'A'; | ||
175 | + } else if (count >= B) { | ||
176 | + return 'B'; | ||
177 | + } else { | ||
178 | + return 'C'; | ||
179 | + } | ||
180 | +} | ||
181 | + | ||
182 | +let gradetoScore = function(grade) { | ||
183 | + if (grade == 'A') { | ||
184 | + return 3; | ||
185 | + } else if (grade == 'B') { | ||
186 | + return 2; | ||
187 | + } else { | ||
188 | + return 1; | ||
189 | + } | ||
190 | +} | ||
191 | +let scoretoGrade = function(score) { | ||
192 | + if (score == 3) { | ||
193 | + return 'A'; | ||
194 | + } else if (score == 2) { | ||
195 | + return 'B'; | ||
196 | + } else { | ||
197 | + return 'C'; | ||
198 | + } | ||
199 | +} | ||
200 | +let avgGrade = function(grade1, grade2) { | ||
201 | + score1 = gradetoScore(grade1); | ||
202 | + score2 = gradetoScore(grade2); | ||
203 | + return scoretoGrade(Math.round((score1 + score2) / 2)); | ||
204 | + } | ||
147 | // 결과 중 사용자 근처인지 검사하기 위한 함수 | 205 | // 결과 중 사용자 근처인지 검사하기 위한 함수 |
148 | let userArea = function(target, targetKey, user) { | 206 | let userArea = function(target, targetKey, user) { |
149 | 207 | ||
150 | if (target[targetKey] != null && target[targetKey].includes(user)) { | 208 | if (target[targetKey] != null && target[targetKey].includes(user)) { |
151 | - console.log('param1', target[targetKey]); | ||
152 | - console.log('param2', user); | ||
153 | - console.log('result', target[targetKey].includes(user)) | ||
154 | return true; | 209 | return true; |
155 | } else { | 210 | } else { |
156 | return false; | 211 | return false; |
... | @@ -159,7 +214,7 @@ let userArea = function(target, targetKey, user) { | ... | @@ -159,7 +214,7 @@ let userArea = function(target, targetKey, user) { |
159 | 214 | ||
160 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 | 215 | // 사용자가 index 페이지에서 주소를 입력하고 넘어오면 |
161 | router.post('/', function(req, res) { | 216 | router.post('/', function(req, res) { |
162 | - console.log(req.body); | 217 | + |
163 | user_sigun = req.body.sigun; | 218 | user_sigun = req.body.sigun; |
164 | user_gu = req.body.gu; | 219 | user_gu = req.body.gu; |
165 | user_dong = req.body.dong; | 220 | user_dong = req.body.dong; |
... | @@ -188,7 +243,7 @@ router.post('/', function(req, res) { | ... | @@ -188,7 +243,7 @@ router.post('/', function(req, res) { |
188 | // sigun code 받는 부분 | 243 | // sigun code 받는 부분 |
189 | for (var key in sigun) { | 244 | for (var key in sigun) { |
190 | if (userLocation.includes(sigun[key].sigun_name)) { | 245 | if (userLocation.includes(sigun[key].sigun_name)) { |
191 | - console.log('hey!'); | 246 | + |
192 | SIGUN_CODE = sigun[key].sigun_code; | 247 | SIGUN_CODE = sigun[key].sigun_code; |
193 | } | 248 | } |
194 | console.log(sigun[key].sigun_name); | 249 | console.log(sigun[key].sigun_name); |
... | @@ -220,18 +275,18 @@ router.get('/food', function(req, res) { | ... | @@ -220,18 +275,18 @@ router.get('/food', function(req, res) { |
220 | }, function(err, response, body) { | 275 | }, function(err, response, body) { |
221 | if (!err && res.statusCode == 200) { | 276 | if (!err && res.statusCode == 200) { |
222 | let food_result = JSON.parse(body); | 277 | let food_result = JSON.parse(body); |
223 | - // console.log('food_result', food_result.PlaceThatDoATasteyFoodSt[1]); | ||
224 | let stores = []; | 278 | let stores = []; |
225 | for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { | 279 | for (let i = 0; i < food_result.PlaceThatDoATasteyFoodSt[1].row.length; i++) { |
226 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) | 280 | // 상호명, 음식명, 전화번호, 도로명주소(REFINE_ROADNM_ADDR), 지번 주소(REFINE_LOTNO_ADDR) |
227 | store = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; | 281 | store = food_result.PlaceThatDoATasteyFoodSt[1].row[i]; |
228 | if (userArea(store, 'REFINE_LOTNO_ADDR', user_target)) { | 282 | if (userArea(store, 'REFINE_LOTNO_ADDR', user_target)) { |
229 | - console.log('store', store); | 283 | + |
230 | stores.push(store); | 284 | stores.push(store); |
231 | } | 285 | } |
232 | } | 286 | } |
233 | - console.log('food_result', food_result); | 287 | + |
234 | - console.log('stores', stores); | 288 | + food_grade = evalGrade(food_A, food_B, stores.length); |
289 | + | ||
235 | request({ | 290 | request({ |
236 | url: fastfood_url + qs, | 291 | url: fastfood_url + qs, |
237 | method: 'GET' | 292 | method: 'GET' |
... | @@ -243,11 +298,13 @@ router.get('/food', function(req, res) { | ... | @@ -243,11 +298,13 @@ router.get('/food', function(req, res) { |
243 | fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i]; | 298 | fast_food_store = fast_food_result.Genrestrtfastfood[1].row[i]; |
244 | // 폐업인 지점 제외 | 299 | // 폐업인 지점 제외 |
245 | if (fast_food_store['BSN_STATE_NM'] != '폐업' && userArea(fast_food_store, 'REFINE_LOTNO_ADDR', user_target)) { | 300 | if (fast_food_store['BSN_STATE_NM'] != '폐업' && userArea(fast_food_store, 'REFINE_LOTNO_ADDR', user_target)) { |
246 | - console.log('fast_store_name', fast_food_store); | ||
247 | fast_food_stores.push(fast_food_store); | 301 | fast_food_stores.push(fast_food_store); |
248 | } | 302 | } |
249 | } | 303 | } |
250 | - res.render('result', { category: 'food', stores: stores, fast_food_stores: fast_food_stores, userLocation: userLocation, grade: 'A' }); | 304 | + fast_food_grade = evalGrade(fast_food_A, fast_food_B, fast_food_stores.length); |
305 | + | ||
306 | + grade = avgGrade(food_grade, fast_food_grade); | ||
307 | + res.render('result', { category: 'food', stores: stores, fast_food_stores: fast_food_stores, userLocation: userLocation, grade: grade }); | ||
251 | } | 308 | } |
252 | 309 | ||
253 | }) | 310 | }) |
... | @@ -267,32 +324,31 @@ router.get('/school', function(req, res) { | ... | @@ -267,32 +324,31 @@ router.get('/school', function(req, res) { |
267 | }, function(err, response, body) { | 324 | }, function(err, response, body) { |
268 | if (!err && res.statusCode == 200) { | 325 | if (!err && res.statusCode == 200) { |
269 | let library_result = JSON.parse(body); | 326 | let library_result = JSON.parse(body); |
270 | - console.log(library_result); | ||
271 | let librarys = []; | 327 | let librarys = []; |
272 | for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) { | 328 | for (let i = 0; i < library_result.Tbggibllbrm[1].row.length; i++) { |
273 | library = library_result.Tbggibllbrm[1].row[i]; | 329 | library = library_result.Tbggibllbrm[1].row[i]; |
274 | if (userArea(library, 'REFINE_LOTNO_ADDR', user_target)) { | 330 | if (userArea(library, 'REFINE_LOTNO_ADDR', user_target)) { |
275 | - console.log('library', library); | ||
276 | librarys.push(library); | 331 | librarys.push(library); |
277 | } | 332 | } |
278 | 333 | ||
279 | } | 334 | } |
335 | + library_grade = evalGrade(library_A, 0.5, librarys.length); | ||
280 | request({ | 336 | request({ |
281 | url: institute_url + qs, | 337 | url: institute_url + qs, |
282 | method: 'GET' | 338 | method: 'GET' |
283 | }, function(err, response, body) { | 339 | }, function(err, response, body) { |
284 | if (!err && res.statusCode == 200) { | 340 | if (!err && res.statusCode == 200) { |
285 | let institute_result = JSON.parse(body); | 341 | let institute_result = JSON.parse(body); |
286 | - console.log(institute_result); | ||
287 | let institutes = []; | 342 | let institutes = []; |
288 | for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) { | 343 | for (let i = 0; i < institute_result.TninsttInstutM[1].row.length; i++) { |
289 | institute = institute_result.TninsttInstutM[1].row[i]; | 344 | institute = institute_result.TninsttInstutM[1].row[i]; |
290 | if (userArea(institute, 'REFINE_LOTNO_ADDR', user_target)) { | 345 | if (userArea(institute, 'REFINE_LOTNO_ADDR', user_target)) { |
291 | - console.log('institute', institute); | ||
292 | institutes.push(institute); | 346 | institutes.push(institute); |
293 | } | 347 | } |
294 | } | 348 | } |
295 | - res.render('result', { category: 'school', librarys: librarys, institutes: institutes, userLocation: userLocation, grade: 'A' }); | 349 | + institute_grade = evalGrade(institute_A, institute_B, institutes); |
350 | + grade = avgGrade(library_grade, institute_grade); | ||
351 | + res.render('result', { category: 'school', librarys: librarys, institutes: institutes, userLocation: userLocation, grade: grade }); | ||
296 | } | 352 | } |
297 | }) | 353 | }) |
298 | } | 354 | } |
... | @@ -307,10 +363,8 @@ router.get('/park', function(req, res) { | ... | @@ -307,10 +363,8 @@ router.get('/park', function(req, res) { |
307 | url: citypark_url + qs, | 363 | url: citypark_url + qs, |
308 | method: 'GET' | 364 | method: 'GET' |
309 | }, function(err, response, body) { | 365 | }, function(err, response, body) { |
310 | - // console.log('park_result', park_result.CityPark[0].head); | ||
311 | if (!err && res.statusCode == 200) { | 366 | if (!err && res.statusCode == 200) { |
312 | let city_park_result = JSON.parse(body); | 367 | let city_park_result = JSON.parse(body); |
313 | - console.log('park', city_park_result) | ||
314 | let city_parks = []; | 368 | let city_parks = []; |
315 | for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) { | 369 | for (let i = 0; i < city_park_result.CityPark[1].row.length; i++) { |
316 | city_park = city_park_result.CityPark[1].row[i]; | 370 | city_park = city_park_result.CityPark[1].row[i]; |
... | @@ -318,7 +372,8 @@ router.get('/park', function(req, res) { | ... | @@ -318,7 +372,8 @@ router.get('/park', function(req, res) { |
318 | city_parks.push(city_park); | 372 | city_parks.push(city_park); |
319 | } | 373 | } |
320 | } | 374 | } |
321 | - res.render('result', { category: 'park', city_parks: city_parks, userLocation: userLocation, grade: 'A' }); | 375 | + grade = evalGrade(park_A, park_B, city_parks.length); |
376 | + res.render('result', { category: 'park', city_parks: city_parks, userLocation: userLocation, grade: grade }); | ||
322 | } | 377 | } |
323 | }) | 378 | }) |
324 | }); | 379 | }); |
... | @@ -331,7 +386,6 @@ router.get('/transport', function(req, res) { | ... | @@ -331,7 +386,6 @@ router.get('/transport', function(req, res) { |
331 | let qs = `?lang=0&x=${user_latitude}&y=${user_longitude}&radius=1000&stationClass=2&apiKey=${ODSAY_API_KEY}`; | 386 | let qs = `?lang=0&x=${user_latitude}&y=${user_longitude}&radius=1000&stationClass=2&apiKey=${ODSAY_API_KEY}`; |
332 | let busCnt = 0; | 387 | let busCnt = 0; |
333 | let subwayCnt = 0; | 388 | let subwayCnt = 0; |
334 | - console.log(bus_url); | ||
335 | 389 | ||
336 | request({ | 390 | request({ |
337 | url: bus_url + qs, | 391 | url: bus_url + qs, |
... | @@ -343,13 +397,10 @@ router.get('/transport', function(req, res) { | ... | @@ -343,13 +397,10 @@ router.get('/transport', function(req, res) { |
343 | let bus_result = JSON.parse(body); | 397 | let bus_result = JSON.parse(body); |
344 | // console.log('bus_result', bus_result.result.station); | 398 | // console.log('bus_result', bus_result.result.station); |
345 | let busStations = []; | 399 | let busStations = []; |
346 | - console.log(bus_result.result) | ||
347 | for (let i = 0; i < bus_result.result.station.length; i++) { | 400 | for (let i = 0; i < bus_result.result.station.length; i++) { |
348 | station = bus_result.result.station[i]; | 401 | station = bus_result.result.station[i]; |
349 | - console.log('station', station) | ||
350 | busStations.push(station); | 402 | busStations.push(station); |
351 | } | 403 | } |
352 | - console.log('busStations', busStations); | ||
353 | request({ | 404 | request({ |
354 | url: subway_url + qs, | 405 | url: subway_url + qs, |
355 | method: 'GET' | 406 | method: 'GET' |
... | @@ -357,14 +408,13 @@ router.get('/transport', function(req, res) { | ... | @@ -357,14 +408,13 @@ router.get('/transport', function(req, res) { |
357 | if (!err && res.statusCode == 200) { | 408 | if (!err && res.statusCode == 200) { |
358 | let subway_result = JSON.parse(body); | 409 | let subway_result = JSON.parse(body); |
359 | let subwayStations = []; | 410 | let subwayStations = []; |
360 | - console.log('subway_result', subway_result); | ||
361 | for (let i = 0; i < subway_result.result.station.length; i++) { | 411 | for (let i = 0; i < subway_result.result.station.length; i++) { |
362 | station = subway_result.result.station[i]; | 412 | station = subway_result.result.station[i]; |
363 | subwayStations.push(station); | 413 | subwayStations.push(station); |
364 | } | 414 | } |
365 | console.log(busStations); | 415 | console.log(busStations); |
366 | console.log('subwayStaions', subwayStations); | 416 | console.log('subwayStaions', subwayStations); |
367 | - res.render('result', { category: 'transport', busStations: busStations, subwayStations: subwayStations, userLocation: userLocation, grade: 'A' }) | 417 | + res.render('result', { category: 'transport', busStations: busStations, subwayStations: subwayStations, userLocation: userLocation, grade: grade }) |
368 | } | 418 | } |
369 | }) | 419 | }) |
370 | 420 | ||
... | @@ -384,14 +434,13 @@ router.get('/safe', function(req, res) { | ... | @@ -384,14 +434,13 @@ router.get('/safe', function(req, res) { |
384 | if (!err && res.statusCode == 200) { | 434 | if (!err && res.statusCode == 200) { |
385 | let cctv_result = JSON.parse(body); | 435 | let cctv_result = JSON.parse(body); |
386 | let cctvs = []; | 436 | let cctvs = []; |
387 | - console.log(cctv_result); | ||
388 | for (let i = 0; i < cctv_result.CCTV[1].row.length; i++) { | 437 | for (let i = 0; i < cctv_result.CCTV[1].row.length; i++) { |
389 | cctv = cctv_result.CCTV[1].row[i]; | 438 | cctv = cctv_result.CCTV[1].row[i]; |
390 | if (userArea(cctv, 'REFINE_LOTNO_ADDR', user_target)) { | 439 | if (userArea(cctv, 'REFINE_LOTNO_ADDR', user_target)) { |
391 | - console.log('cctv', cctv); | ||
392 | cctvs.push(cctv); | 440 | cctvs.push(cctv); |
393 | } | 441 | } |
394 | } | 442 | } |
443 | + cctv_grade = evalGrade(cctv_A, cctv_B, cctvs.length); | ||
395 | request({ | 444 | request({ |
396 | url: light_url + qs, | 445 | url: light_url + qs, |
397 | method: 'GET' | 446 | method: 'GET' |
... | @@ -399,15 +448,15 @@ router.get('/safe', function(req, res) { | ... | @@ -399,15 +448,15 @@ router.get('/safe', function(req, res) { |
399 | if (!err && res.statusCode == 200) { | 448 | if (!err && res.statusCode == 200) { |
400 | let light_result = JSON.parse(body); | 449 | let light_result = JSON.parse(body); |
401 | let lights = []; | 450 | let lights = []; |
402 | - console.log(light_result); | ||
403 | for (let i = 0; i < light_result.SECRTLGT[1].row.length; i++) { | 451 | for (let i = 0; i < light_result.SECRTLGT[1].row.length; i++) { |
404 | light = light_result.SECRTLGT[1].row[i]; | 452 | light = light_result.SECRTLGT[1].row[i]; |
405 | if (userArea(light, 'REFINE_LOTNO_ADDR', user_target)) { | 453 | if (userArea(light, 'REFINE_LOTNO_ADDR', user_target)) { |
406 | - console.log('light', light); | ||
407 | lights.push(light); | 454 | lights.push(light); |
408 | } | 455 | } |
409 | } | 456 | } |
410 | - res.render('result', { category: 'safe', cctvs: cctvs, lights: lights, userLocation: userLocation, grade: 'A' }); | 457 | + light_grade = evalGrade(light_A, light_B, lights.length); |
458 | + grade = avgGrade(cctv_grade, light_grade); | ||
459 | + res.render('result', { category: 'safe', cctvs: cctvs, lights: lights, userLocation: userLocation, grade: grade }); | ||
411 | } | 460 | } |
412 | }) | 461 | }) |
413 | } | 462 | } |
... | @@ -425,17 +474,17 @@ router.get('/culture', function(req, res) { | ... | @@ -425,17 +474,17 @@ router.get('/culture', function(req, res) { |
425 | }, function(err, response, body) { | 474 | }, function(err, response, body) { |
426 | if (!err && res.statusCode == 200) { | 475 | if (!err && res.statusCode == 200) { |
427 | let movie_result = JSON.parse(body); | 476 | let movie_result = JSON.parse(body); |
428 | - console.log(movie_result); | ||
429 | let movies = []; | 477 | let movies = []; |
430 | for (let i = 0; i < movie_result.MovieTheater[1].row.length; i++) { | 478 | for (let i = 0; i < movie_result.MovieTheater[1].row.length; i++) { |
431 | movie = movie_result.MovieTheater[1].row[i]; | 479 | movie = movie_result.MovieTheater[1].row[i]; |
432 | // 폐업인 지점 제외 | 480 | // 폐업인 지점 제외 |
433 | if (!movie['BSN_STATE_NM'].includes('폐업') && userArea(movie, 'REFINE_LOTNO_ADDR', user_target)) { | 481 | if (!movie['BSN_STATE_NM'].includes('폐업') && userArea(movie, 'REFINE_LOTNO_ADDR', user_target)) { |
434 | - console.log('movie', movie); | ||
435 | movies.push(movie); | 482 | movies.push(movie); |
436 | } | 483 | } |
484 | + | ||
437 | } | 485 | } |
438 | - res.render('result', { category: 'culture', movies: movies, userLocation: userLocation, grade: 'A' }); | 486 | + grade = evalGrade(culture_A, culture_B, movies.length); |
487 | + res.render('result', { category: 'culture', movies: movies, userLocation: userLocation, grade: grade }); | ||
439 | } | 488 | } |
440 | }); | 489 | }); |
441 | }); | 490 | }); |
... | @@ -456,11 +505,11 @@ router.get('/shop', function(req, res) { | ... | @@ -456,11 +505,11 @@ router.get('/shop', function(req, res) { |
456 | shop = shop_result.MrktStoreM[1].row[i]; | 505 | shop = shop_result.MrktStoreM[1].row[i]; |
457 | // 폐업인 지점 제외 | 506 | // 폐업인 지점 제외 |
458 | if (userArea(shop, 'REFINE_LOTNO_ADDR', user_target)) { | 507 | if (userArea(shop, 'REFINE_LOTNO_ADDR', user_target)) { |
459 | - console.log('shop', shop); | ||
460 | shops.push(shop); | 508 | shops.push(shop); |
461 | } | 509 | } |
462 | } | 510 | } |
463 | - res.render('result', { category: 'shop', shops: shops, userLocation: userLocation, grade: 'A' }); | 511 | + grade = evalGrade(shop_A, shop_B, shops.length) |
512 | + res.render('result', { category: 'shop', shops: shops, userLocation: userLocation, grade: grade }); | ||
464 | } | 513 | } |
465 | 514 | ||
466 | }) | 515 | }) |
... | @@ -476,16 +525,14 @@ router.get('/gym', function(req, res) { | ... | @@ -476,16 +525,14 @@ router.get('/gym', function(req, res) { |
476 | if (!err && res.statusCode == 200) { | 525 | if (!err && res.statusCode == 200) { |
477 | let gym_result = JSON.parse(body); | 526 | let gym_result = JSON.parse(body); |
478 | let gyms = []; | 527 | let gyms = []; |
479 | - console.log(gym_result.PhysicaFitnessTrainingPlace[1]); | ||
480 | for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) { | 528 | for (let i = 0; i < gym_result.PhysicaFitnessTrainingPlace[1].row.length; i++) { |
481 | gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i]; | 529 | gym = gym_result.PhysicaFitnessTrainingPlace[1].row[i]; |
482 | - console.log(gym); | ||
483 | if (userArea(gym, 'REFINE_LOTNO_ADDR', user_target)) { | 530 | if (userArea(gym, 'REFINE_LOTNO_ADDR', user_target)) { |
484 | - console.log('gym', gym); | ||
485 | gyms.push(gym); | 531 | gyms.push(gym); |
486 | } | 532 | } |
487 | } | 533 | } |
488 | - res.render('result', { category: 'gym', gyms: gyms, userLocation: userLocation, grade: 'A' }); | 534 | + grade = evalGrade(gym_A, gym_B, gyms.length) |
535 | + res.render('result', { category: 'gym', gyms: gyms, userLocation: userLocation, grade: grade }); | ||
489 | } | 536 | } |
490 | }) | 537 | }) |
491 | }); | 538 | }); | ... | ... |
1 | -<div class="alert alert-primary" role="alert"> | ||
2 | - <h3>평가 등급 : <%=grade%></h3> | ||
3 | -</div> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +<%if(grade == 'A'){%> | ||
2 | + <div class="alert alert-primary" role="alert"> | ||
3 | + <h3>평가 등급 : | ||
4 | + <%=grade%> | ||
5 | + </h3> | ||
6 | + </div> | ||
7 | + <%} else if(grade == 'B'){%> | ||
8 | + <div class="alert alert-warning" role="alert"> | ||
9 | + <h3>평가 등급 : | ||
10 | + <%=grade%> | ||
11 | + </h3> | ||
12 | + </div> | ||
13 | + <%} else{%> | ||
14 | + <div class="alert alert-danger" role="alert"> | ||
15 | + <h3>평가 등급 : | ||
16 | + <%=grade%> | ||
17 | + </h3> | ||
18 | + </div> | ||
19 | + <%}%> | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment