Merge branch 'master' into 'master'
db통합, 배경적용 See merge request !7
Showing
16 changed files
with
52 additions
and
65 deletions
db_total.PNG
0 → 100644
71.6 KB
db_traffic.PNG
deleted
100644 → 0
56.2 KB
db_weather.png
deleted
100644 → 0
23.9 KB
developImg/3_Image.PNG
0 → 100644
249 KB
1 | module.exports = { | 1 | module.exports = { |
2 | host: 'localhost', | 2 | host: 'localhost', |
3 | user: 'root', | 3 | user: 'root', |
4 | - password: 'abcd', | 4 | + password: 'Serrmica0!', |
5 | - database: 'db_option' | 5 | + database: 'db_option_total' |
6 | } | 6 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
keys/db_option_traffic.js
deleted
100644 → 0
lib/db_traffic.js
deleted
100644 → 0
1 | -const db = require('./db.js'); | 1 | +const db_total = require('./db_total.js'); //DB 합침 |
2 | -const db_traffic = require('./db_traffic.js'); | ||
3 | const secret_key = require('../keys/api_option').key; | 2 | const secret_key = require('../keys/api_option').key; |
4 | const secret_key_traffic = require('../keys/api_option_traffic').key; | 3 | const secret_key_traffic = require('../keys/api_option_traffic').key; |
5 | 4 | ||
... | @@ -26,19 +25,12 @@ module.exports = (server, app) => { | ... | @@ -26,19 +25,12 @@ module.exports = (server, app) => { |
26 | let sending_to_client_info = {}; | 25 | let sending_to_client_info = {}; |
27 | let client_send = {}; | 26 | let client_send = {}; |
28 | let client_name = ""; | 27 | let client_name = ""; |
29 | - let client_birth ; | 28 | + let client_birth; |
30 | let Destiny; | 29 | let Destiny; |
31 | let sql; | 30 | let sql; |
32 | let info = {} //;? | 31 | let info = {} //;? |
33 | 32 | ||
34 | let Current_TrafficAcc = {}; | 33 | let Current_TrafficAcc = {}; |
35 | - let sql_traffic; | ||
36 | - //let DeathNum_index = {}; //사상자 | ||
37 | - //let M_HurtNum_index = {}; //중상자 | ||
38 | - //let L_HurtNum_index = {}; //경상자 | ||
39 | - //let LocalName_index = {}; //지역 이름 | ||
40 | - //let OccurNum_index = {}; //발생 건수 | ||
41 | - //afos_fid: 다발지역 FID, bjd_cd: 법정동 코드, spot_cd:지점코드 | ||
42 | 34 | ||
43 | //API 호출_Weather | 35 | //API 호출_Weather |
44 | const req_API = (when, what) => { | 36 | const req_API = (when, what) => { |
... | @@ -62,6 +54,8 @@ module.exports = (server, app) => { | ... | @@ -62,6 +54,8 @@ module.exports = (server, app) => { |
62 | }); | 54 | }); |
63 | }) | 55 | }) |
64 | } | 56 | } |
57 | + | ||
58 | + | ||
65 | //API 호출_Traffic | 59 | //API 호출_Traffic |
66 | const req_API_traffic = (cate1, cate2) => { | 60 | const req_API_traffic = (cate1, cate2) => { |
67 | //async await 사용하기 위하여 promise 사용 | 61 | //async await 사용하기 위하여 promise 사용 |
... | @@ -101,11 +95,6 @@ module.exports = (server, app) => { | ... | @@ -101,11 +95,6 @@ module.exports = (server, app) => { |
101 | Ultra_Violet_index = await req_API("index", "uv"); //자외선지수 | 95 | Ultra_Violet_index = await req_API("index", "uv"); //자외선지수 |
102 | 96 | ||
103 | Current_TrafficAcc = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); //cate1, cate2 | 97 | Current_TrafficAcc = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); //cate1, cate2 |
104 | - /*DeathNum_index = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); | ||
105 | - M_HurtNum_index = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); | ||
106 | - L_HurtNum_index = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); | ||
107 | - LocalName_index = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg"); | ||
108 | - OccurNum_index = await req_API_traffic("frequentzoneLg", "getRestFrequentzoneLg");*/ | ||
109 | 98 | ||
110 | info = { | 99 | info = { |
111 | heat: Heat_index.weather.wIndex.heatIndex[0].current.index, //열지수 | 100 | heat: Heat_index.weather.wIndex.heatIndex[0].current.index, //열지수 |
... | @@ -121,7 +110,7 @@ module.exports = (server, app) => { | ... | @@ -121,7 +110,7 @@ module.exports = (server, app) => { |
121 | typhoon: Current_Weather.common.stormYn, //현재 태풍 | 110 | typhoon: Current_Weather.common.stormYn, //현재 태풍 |
122 | time: Current_Weather.weather.minutely[0].timeObservation, // 불러온 시각 | 111 | time: Current_Weather.weather.minutely[0].timeObservation, // 불러온 시각 |
123 | death_prob: 0, //확률 | 112 | death_prob: 0, //확률 |
124 | - death_number: Current_TrafficAcc.items.item[0].caslt_cnt, //사상자 수 | 113 | + death_number: Current_TrafficAcc.items.item[0].dth_dnv_cnt, //사망자 수 |
125 | midhurt_number: Current_TrafficAcc.items.item[0].se_dnv_cnt, //중상자 수 | 114 | midhurt_number: Current_TrafficAcc.items.item[0].se_dnv_cnt, //중상자 수 |
126 | lighthurt_number: Current_TrafficAcc.items.item[0].sl_dnv_cnt, //경상자 수 | 115 | lighthurt_number: Current_TrafficAcc.items.item[0].sl_dnv_cnt, //경상자 수 |
127 | occur_number: Current_TrafficAcc.items.item[0].occrrnc_cnt //발생건수 | 116 | occur_number: Current_TrafficAcc.items.item[0].occrrnc_cnt //발생건수 |
... | @@ -143,7 +132,8 @@ module.exports = (server, app) => { | ... | @@ -143,7 +132,8 @@ module.exports = (server, app) => { |
143 | //죽을 확률 계산(내맘대로 커스텀) | 132 | //죽을 확률 계산(내맘대로 커스텀) |
144 | info.death_prob = ( | 133 | info.death_prob = ( |
145 | (info.heat / 50) + (Math.abs(info.sensible_temperature - 15) / 10) + (info.discomport / 10) + (info.UV / 10) | 134 | (info.heat / 50) + (Math.abs(info.sensible_temperature - 15) / 10) + (info.discomport / 10) + (info.UV / 10) |
146 | - + info.windspd*1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) | 135 | + + info.windspd * 1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) |
136 | + + (info.death_number / 60) + (info.midhurt_number / 80) + (info.lighthurt_number / 90) + (info.occur_number / 90) | ||
147 | ); | 137 | ); |
148 | 138 | ||
149 | //이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보, 홈페이지 그래프에 나타날 정보 | 139 | //이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보, 홈페이지 그래프에 나타날 정보 |
... | @@ -164,15 +154,15 @@ module.exports = (server, app) => { | ... | @@ -164,15 +154,15 @@ module.exports = (server, app) => { |
164 | 154 | ||
165 | 155 | ||
166 | // 심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음 | 156 | // 심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음 |
167 | - Math.random() * 2 >= 1 ? client_send.death += getRandom_add_prob(0,5) : client_send.death -= getRandom_add_prob(0,5) ; | 157 | + Math.random() * 2 >= 1 ? client_send.death += getRandom_add_prob(0, 5) : client_send.death -= getRandom_add_prob(0, 5); |
168 | 158 | ||
169 | 159 | ||
170 | //운명의 장난으로 죽을 확률이 증가하거나 감소함 | 160 | //운명의 장난으로 죽을 확률이 증가하거나 감소함 |
171 | const rand = Math.floor(Math.random() * 6) //생년월일 중 한자리 뽑음 | 161 | const rand = Math.floor(Math.random() * 6) //생년월일 중 한자리 뽑음 |
172 | 162 | ||
173 | - Destiny=client_birth.charAt(rand)/3; //명시적 형 변환 | 163 | + Destiny = client_birth.charAt(rand) / 3; //명시적 형 변환 |
174 | - if(Destiny==0)Destiny=1; //사용자 잘못 입력했을때 예외처리 | 164 | + if (Destiny == 0) Destiny = 1; //사용자 잘못 입력했을때 예외처리 |
175 | - Math.random() * 2 >= 1 ? client_send.death += Destiny : client_send.death -= Destiny ; | 165 | + Math.random() * 2 >= 1 ? client_send.death += Destiny : client_send.death -= Destiny; |
176 | 166 | ||
177 | 167 | ||
178 | //만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리 | 168 | //만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리 |
... | @@ -180,21 +170,17 @@ module.exports = (server, app) => { | ... | @@ -180,21 +170,17 @@ module.exports = (server, app) => { |
180 | client_send.death = 100; | 170 | client_send.death = 100; |
181 | } | 171 | } |
182 | 172 | ||
183 | - console.log("client send data \n",client_send) | 173 | + console.log("client send data \n", client_send) |
184 | 174 | ||
185 | app.get("socket").emit("weather_and_traffic_Info_minutely_send_to_client", client_send); // 클라이언트에게 정보 담아서 이벤트 발산 | 175 | app.get("socket").emit("weather_and_traffic_Info_minutely_send_to_client", client_send); // 클라이언트에게 정보 담아서 이벤트 발산 |
186 | console.log("emit"); | 176 | console.log("emit"); |
187 | 177 | ||
188 | //db에 저장 | 178 | //db에 저장 |
189 | - sql = "INSERT INTO weatherInfo (time,wind,temperature,rain,prob) VALUES (?,?,?,?,?)"; | 179 | + sql = "INSERT INTO apisInfo (time,wind,temperature,rain,prob,tdeath,mhurt,lhurt,occurence) VALUES (?,?,?,?,?,?,?,?,?)"; |
190 | - db.query(sql, [client_send.time, client_send.wind, client_send.temperature, client_send.rain, client_send.death], (err, result) => { | 180 | + db_total.query(sql, [client_send.time, client_send.wind, client_send.temperature, client_send.rain, client_send.death, client_send.trafficdeath, client_send.mhurt, client_send.lhurt, client_send.occurence], (err, result) => { |
191 | if (err) console.log(err); | 181 | if (err) console.log(err); |
192 | }) | 182 | }) |
193 | 183 | ||
194 | - sql_traffic = "INSERT INTO trafficInfo (tdeath,mhurt,lhurt,occurence,prob) VALUES (?,?,?,?,?)"; | ||
195 | - db_traffic.query(sql_traffic, [client_send.trafficdeath, client_send.mhurt, client_send.lhurt, client_send.occurence, client_send.death], (err, result) => { | ||
196 | - if (err) console.log(err); | ||
197 | - }) | ||
198 | } catch (err) { //promise err or try err catch | 184 | } catch (err) { //promise err or try err catch |
199 | console.log("================Error Occured !!================\n", err); | 185 | console.log("================Error Occured !!================\n", err); |
200 | } | 186 | } | ... | ... |
public/images/newbackground.png
0 → 100644
1.18 MB
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var router = express.Router(); | 2 | var router = express.Router(); |
3 | -var db = require('../lib/db'); | 3 | +var db = require('../lib/db_total'); |
4 | 4 | ||
5 | /* GET home page. */ | 5 | /* GET home page. */ |
6 | 6 | ||
7 | router.post('/starting' , (req,res) => { | 7 | router.post('/starting' , (req,res) => { |
8 | res.redirect(`/name/${req.body.name}/birth/${req.body.birth}`); | 8 | res.redirect(`/name/${req.body.name}/birth/${req.body.birth}`); |
9 | }) | 9 | }) |
10 | -router.get('/name/:name/birth/:birth', (req,res) => { | 10 | +router.get('/name/:name/birth/:birth', (req, res) => { |
11 | 11 | ||
12 | // 렌더링 변수 | 12 | // 렌더링 변수 |
13 | var time = new Array(); // 타임스탬프 | 13 | var time = new Array(); // 타임스탬프 |
... | @@ -21,32 +21,40 @@ router.get('/name/:name/birth/:birth', (req,res) => { | ... | @@ -21,32 +21,40 @@ router.get('/name/:name/birth/:birth', (req,res) => { |
21 | var count = 0; | 21 | var count = 0; |
22 | const name = req.params.name; | 22 | const name = req.params.name; |
23 | const birth = req.params.birth; | 23 | const birth = req.params.birth; |
24 | + //const address = req.params.address; | ||
25 | + //////////////////////////////////////// | ||
26 | + var deathArr = new Array(); | ||
27 | + var mhurtArr = new Array(); | ||
28 | + var lhurtArr = new Array(); | ||
29 | + var occurArr = new Array(); | ||
30 | + //////////////////////////////////////// | ||
31 | + | ||
24 | 32 | ||
25 | // 이전 10분간 데이터 찾기 | 33 | // 이전 10분간 데이터 찾기 |
26 | - sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -20 MINUTE), '%Y-%m-%d %H:%i:%s')"; | 34 | + sql = "SELECT * FROM apisInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -20 MINUTE), '%Y-%m-%d %H:%i:%s')"; |
27 | - db.query(sql, function(err, rows, fields){ | 35 | + db.query(sql, function (err, rows, fields) { |
28 | - if(err) | 36 | + if (err) { |
29 | - { | ||
30 | console.log(err); | 37 | console.log(err); |
31 | } | 38 | } |
32 | - else | 39 | + else { |
33 | - { | 40 | + if (rows.length == 0) { |
34 | - if (rows.length == 0) | ||
35 | - { | ||
36 | empty = 1; | 41 | empty = 1; |
37 | } | 42 | } |
38 | - else | 43 | + else { |
39 | - { | 44 | + for (var i = rows.length - 1; i >= 0; i--) { |
40 | - for(var i = rows.length - 1; i >= 0; i--) | ||
41 | - { | ||
42 | probArr.unshift(rows[i].prob); | 45 | probArr.unshift(rows[i].prob); |
43 | time.unshift(rows[i].time); | 46 | time.unshift(rows[i].time); |
44 | ptArr.unshift(rows[i].temperature); | 47 | ptArr.unshift(rows[i].temperature); |
45 | wsArr.unshift(rows[i].wind); | 48 | wsArr.unshift(rows[i].wind); |
46 | rainArr.unshift(rows[i].rain); | 49 | rainArr.unshift(rows[i].rain); |
50 | + //// | ||
51 | + deathArr.unshift(rows[i].tdeath); | ||
52 | + mhurtArr.unshift(rows[i].mhurt); | ||
53 | + lhurtArr.unshift(rows[i].lhurt); | ||
54 | + occurArr.unshift(rows[i].occurence); | ||
47 | count = count + 1; | 55 | count = count + 1; |
48 | 56 | ||
49 | - if (count == 10){ | 57 | + if (count == 10) { |
50 | break; | 58 | break; |
51 | } | 59 | } |
52 | } | 60 | } |
... | @@ -62,13 +70,17 @@ router.get('/name/:name/birth/:birth', (req,res) => { | ... | @@ -62,13 +70,17 @@ router.get('/name/:name/birth/:birth', (req,res) => { |
62 | probArr, | 70 | probArr, |
63 | dataLen, | 71 | dataLen, |
64 | name, | 72 | name, |
65 | - birth | 73 | + birth, |
74 | + deathArr, | ||
75 | + mhurtArr, | ||
76 | + lhurtArr, | ||
77 | + occurArr | ||
66 | }); | 78 | }); |
67 | } | 79 | } |
68 | }); | 80 | }); |
69 | -} ) | 81 | +}) |
70 | -router.get('/', function(req, res, next) { | 82 | +router.get('/', function (req, res, next) { |
71 | - res.render( 'main' ); | 83 | + res.render('main'); |
72 | }); | 84 | }); |
73 | 85 | ||
74 | module.exports = router; | 86 | module.exports = router; | ... | ... |
views/index - 복사본.ejs
deleted
100644 → 0
This diff is collapsed. Click to expand it.
1 | <!-- <!DOCTYPE html> | 1 | <!-- <!DOCTYPE html> |
2 | <html> | 2 | <html> |
3 | - | ||
4 | <head> | 3 | <head> |
5 | <!-- font --> | 4 | <!-- font --> |
6 | <link href="https://fonts.googleapis.com/css?family=Nanum+Brush+Script&subset=korean" rel="stylesheet" /> | 5 | <link href="https://fonts.googleapis.com/css?family=Nanum+Brush+Script&subset=korean" rel="stylesheet" /> |
... | @@ -39,7 +38,7 @@ | ... | @@ -39,7 +38,7 @@ |
39 | <script src="modules/exporting.js"></script> | 38 | <script src="modules/exporting.js"></script> |
40 | <script src="modules/export-data.js"></script> | 39 | <script src="modules/export-data.js"></script> |
41 | 40 | ||
42 | - <img src="images/background.jpg" alt="" style="z-index:-1; min-width: 100%; min-height: 100%"> | 41 | + <img src="images/newbackground.png" alt="" style="z-index:-1; min-width: 100%; min-height: 100%"> |
43 | 42 | ||
44 | <div id="banner"> | 43 | <div id="banner"> |
45 | <div id="container1" style="width:1260px; height: 400px; margin: 0 auto;"></div> | 44 | <div id="container1" style="width:1260px; height: 400px; margin: 0 auto;"></div> | ... | ... |
... | @@ -34,7 +34,7 @@ | ... | @@ -34,7 +34,7 @@ |
34 | margin: 0; | 34 | margin: 0; |
35 | padding: 0; | 35 | padding: 0; |
36 | 36 | ||
37 | - /* background-image: url('background.jpg'); | 37 | + /* background-image: url('newbackground.png'); |
38 | background-repeat: no-repeat; | 38 | background-repeat: no-repeat; |
39 | background-size: cover; */ | 39 | background-size: cover; */ |
40 | /* background: linear-gradient( to bottom, #fbc2eb, #a6c1ee ); */ | 40 | /* background: linear-gradient( to bottom, #fbc2eb, #a6c1ee ); */ | ... | ... |
views/newbackground.png
0 → 100644
1.18 MB
... | @@ -21,7 +21,7 @@ | ... | @@ -21,7 +21,7 @@ |
21 | 21 | ||
22 | /* background: linear-gradient( to bottom, #65799B, rgb(38, 14, 41) ); */ | 22 | /* background: linear-gradient( to bottom, #65799B, rgb(38, 14, 41) ); */ |
23 | /* background-color:#65799B; */ | 23 | /* background-color:#65799B; */ |
24 | - /* background-image: url("2.jpg"); | 24 | + /* background-image: url("newbackground.png"); |
25 | background-repeat: no-repeat; | 25 | background-repeat: no-repeat; |
26 | background-size: cover; */ | 26 | background-size: cover; */ |
27 | } | 27 | } |
... | @@ -38,7 +38,7 @@ | ... | @@ -38,7 +38,7 @@ |
38 | <script src="highcharts.js"></script> | 38 | <script src="highcharts.js"></script> |
39 | <script src="modules/exporting.js"></script> | 39 | <script src="modules/exporting.js"></script> |
40 | <script src="modules/export-data.js"></script> | 40 | <script src="modules/export-data.js"></script> |
41 | - <img src="images/background.jpg" alt="" style="z-index:-1; min-width: 100%; min-height: 100%"> | 41 | + <img src="images/newbackground.png" alt="" style="z-index:-1; min-width: 100%; min-height: 100%"> |
42 | 42 | ||
43 | <div id="banner"> | 43 | <div id="banner"> |
44 | <div id="container1" style="width:1260px; height: 400px; margin: 0 auto"></div> | 44 | <div id="container1" style="width:1260px; height: 400px; margin: 0 auto"></div> | ... | ... |
-
Please register or login to post a comment