Showing
5 changed files
with
102 additions
and
15 deletions
... | @@ -22,10 +22,10 @@ app.use(express.urlencoded({ extended: false })); | ... | @@ -22,10 +22,10 @@ app.use(express.urlencoded({ extended: false })); |
22 | app.use(cookieParser()); | 22 | app.use(cookieParser()); |
23 | app.use('/',express.static(path.join(__dirname, 'public'))); | 23 | app.use('/',express.static(path.join(__dirname, 'public'))); |
24 | app.use('/',express.static(path.join(__dirname, 'code'))); | 24 | app.use('/',express.static(path.join(__dirname, 'code'))); |
25 | -app.use('/Cname/:Cname/Cbirth',express.static(path.join(__dirname, 'public'))); | 25 | +app.use('/Cname/:name/Cbirth',express.static(path.join(__dirname, 'public'))); |
26 | -app.use('/Cname/:Cname/Cbirth',express.static(path.join(__dirname, 'code'))); | 26 | +app.use('/Cname/:name/Cbirth',express.static(path.join(__dirname, 'code'))); |
27 | -app.use('/Fname/:Fname/Fbirth',express.static(path.join(__dirname, 'newpublic'))); | 27 | +app.use('/Fname/:name/Fbirth',express.static(path.join(__dirname, 'newpublic'))); |
28 | -app.use('/Fname/:Fname/Fbirth',express.static(path.join(__dirname, 'newcode'))); | 28 | +app.use('/Fname/:name/Fbirth',express.static(path.join(__dirname, 'newcode'))); |
29 | 29 | ||
30 | 30 | ||
31 | app.use('/', indexRouter); | 31 | app.use('/', indexRouter); | ... | ... |
... | @@ -27,8 +27,8 @@ module.exports = (server, app) => { | ... | @@ -27,8 +27,8 @@ module.exports = (server, app) => { |
27 | let client_birth ; | 27 | let client_birth ; |
28 | let Destiny; | 28 | let Destiny; |
29 | let sql; | 29 | let sql; |
30 | + let DeathNote=[]; | ||
30 | 31 | ||
31 | - | ||
32 | let Day3_Weather ={}; | 32 | let Day3_Weather ={}; |
33 | let info = {} | 33 | let info = {} |
34 | 34 | ||
... | @@ -141,7 +141,9 @@ module.exports = (server, app) => { | ... | @@ -141,7 +141,9 @@ module.exports = (server, app) => { |
141 | traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수 | 141 | traffic: Traffic_Accident.totalCount, // 교통사고 발생횟수 |
142 | death_factor: "", //사망요인 | 142 | death_factor: "", //사망요인 |
143 | death_countdown: 0, //죽기까지 남은 시간(단위: 초) | 143 | death_countdown: 0, //죽기까지 남은 시간(단위: 초) |
144 | - death_prob: 0 //확률 | 144 | + death_prob: 0, //확률 |
145 | + | ||
146 | + DeathNote: [] | ||
145 | } | 147 | } |
146 | console.log("API INFO \n", info); | 148 | console.log("API INFO \n", info); |
147 | console.log("Traffic count:", info.traffic); | 149 | console.log("Traffic count:", info.traffic); |
... | @@ -162,11 +164,13 @@ module.exports = (server, app) => { | ... | @@ -162,11 +164,13 @@ module.exports = (server, app) => { |
162 | //죽을 확률 계산(내맘대로 커스텀) | 164 | //죽을 확률 계산(내맘대로 커스텀) |
163 | info.death_prob = ( | 165 | info.death_prob = ( |
164 | (info.heat / 50) + (Math.abs(info.sensible_temperature - 15) / 10) + (info.discomport / 10) + (info.UV / 10) | 166 | (info.heat / 50) + (Math.abs(info.sensible_temperature - 15) / 10) + (info.discomport / 10) + (info.UV / 10) |
165 | - + info.windspd*1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) //+ (info.traffic / 5) | 167 | + + info.windspd*1 + (info.rain / 10) + (Math.abs(info.current_temperature - 15) / 10) // + (info.traffic / 5) |
166 | ); | 168 | ); |
167 | - | 169 | + |
168 | // ------------------------------ death_factor 정의 ------------------------------ | 170 | // ------------------------------ death_factor 정의 ------------------------------ |
169 | 171 | ||
172 | + Death_Factors.push("심장마비로 사망"); //반드시 하나의 요인은 추가되어야 함 | ||
173 | + | ||
170 | if (info.typhoon == "Y") | 174 | if (info.typhoon == "Y") |
171 | Death_Factors.push("태풍에 휩쓸려 사망"); | 175 | Death_Factors.push("태풍에 휩쓸려 사망"); |
172 | if (info.lightning == 1) | 176 | if (info.lightning == 1) |
... | @@ -179,10 +183,78 @@ module.exports = (server, app) => { | ... | @@ -179,10 +183,78 @@ module.exports = (server, app) => { |
179 | Death_Factors.push("학점이 너무 낮아 화병으로 사망"); | 183 | Death_Factors.push("학점이 너무 낮아 화병으로 사망"); |
180 | if (info.discomport*1 >= 40) | 184 | if (info.discomport*1 >= 40) |
181 | Death_Factors.push("날씨가 너무 찝찝해서 사망"); | 185 | Death_Factors.push("날씨가 너무 찝찝해서 사망"); |
186 | + if (info.typhoon == "Y"&& info.lightning== 1 ) | ||
187 | + Death_Factors.push("공포감에 긴장하여 사망"); | ||
188 | + if (info.heat*1 >= 100 &&info.discomport*1 >=40) | ||
189 | + Death_Factors.push("고혈압으로 사망"); | ||
182 | 190 | ||
183 | - Death_Factors.push("심장마비로 사망"); //반드시 하나의 요인은 추가되어야 함 | 191 | + if (client_birth.charAt(0)=='1') |
192 | + Death_Factors=['아이는 죽지 않아요']; | ||
193 | + | ||
194 | + info.death_factor = Death_Factors[Math.floor(Math.random()*Death_Factors.length)]; //사망요인 하나를 렌덤으로 고른다. | ||
195 | + | ||
196 | + //-----------------------------DeathNote 정의 ----------------------------------- | ||
197 | + //열지수 | ||
198 | + if(info.Forecast_1dayHeat>info.Forecast_2dayHeat&&info.Forecast_1dayHeat>info.Forecast_laterHeat){ | ||
199 | + info.DeathNote.push({hours: Math.round(Math.random()*23),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "스트레스 너무 받아 화병으로 사망"}) | ||
200 | + } | ||
201 | + else if(info.Forecast_2dayHeat>info.Forecast_1dayHeat&&info.Forecast_2dayHeat>info.Forecast_laterHeat){ | ||
202 | + info.DeathNote.push({hours: Math.round(Math.random()*23)+24,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "스트레스 너무 받아 화병으로 사망"}) | ||
203 | + } | ||
204 | + else{ | ||
205 | + info.DeathNote.push({hours: Math.round(Math.random()*9000)+48,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "스트레스 너무 받아 화병으로 사망"}) | ||
206 | + } | ||
207 | + //불쾌지수 | ||
208 | + if(info.Forecast_1dayDiscomport>info.Forecast_2dayDiscomport&&info.Forecast_1dayDiscomport>info.Forecast_laterDiscomport){ | ||
209 | + info.DeathNote.push({hours: Math.round(Math.random()*23),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "너무 불쾌해서 사망"}) | ||
210 | + } | ||
211 | + else if(info.Forecast_2dayDiscomport>info.Forecast_1dayDiscomport&&info.Forecast_2dayDiscomport>info.Forecast_laterDiscomport){ | ||
212 | + info.DeathNote.push({hours: Math.round(Math.random()*23)+24,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "너무 불쾌해서 사망"}) | ||
213 | + } | ||
214 | + else{ | ||
215 | + info.DeathNote.push({hours: Math.round(Math.random()*9000)+48,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "너무 불쾌해서 사망"}) | ||
216 | + } | ||
217 | + //체감 | ||
218 | + if(info.Forecast_1daySensible>info.Forecast_2daySensible&&info.Forecast_1daySensible>info.Forecast_laterSensible){ | ||
219 | + info.DeathNote.push({hours: Math.round(Math.random()*23),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "자외선 과다 노출로 사망"}) | ||
220 | + } | ||
221 | + else if(info.Forecast_2daySensible>info.Forecast_1daySensible&&info.Forecast_2daySensible>info.Forecast_laterSensible){ | ||
222 | + info.DeathNote.push({hours: Math.round(Math.random()*23)+24,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "자외선 과다 노출로 사망"}) | ||
223 | + } | ||
224 | + else{ | ||
225 | + info.DeathNote.push({hours: Math.round(Math.random()*9000)+48,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "자외선 과다 노출로 사망"}) | ||
226 | + } | ||
227 | + //강수량 | ||
228 | + if (info.Forecast_1dayR>=50||info.Forecast_2dayR>=50||info.Forecast_laterR>=50){ | ||
229 | + if(info.Forecast_1dayHeat>info.Forecast_2dayHeat&&info.Forecast_1dayHeat>info.Forecast_laterHeat){ | ||
230 | + info.DeathNote.push({hours: Math.round(Math.random()*23),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "빗길에 미끄러져 뇌진탕으로 사망"}) | ||
231 | + } | ||
232 | + else if(info.Forecast_2dayHeat>info.Forecast_1dayHeat&&info.Forecast_2dayHeat>info.Forecast_laterHeat){ | ||
233 | + info.DeathNote.push({hours: Math.round(Math.random()*23)+24,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "빗길에 미끄러져 뇌진탕으로 사망"}) | ||
234 | + } | ||
235 | + else{ | ||
236 | + info.DeathNote.push({hours: Math.round(Math.random()*9000)+48,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "빗길에 미끄러져 뇌진탕으로 사망"}) | ||
237 | + } | ||
238 | + } | ||
239 | + //바람속도 | ||
240 | + if(info.Forecast_1dayW>info.Forecast_2dayW&&info.Forecast_1dayW>info.Forecast_laterW){ | ||
241 | + info.DeathNote.push({hours: Math.round(Math.random()*23),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "바람이 많이 불어 애인이 바람 남, 그 충격으로 사망"}) | ||
242 | + } | ||
243 | + else if(info.Forecast_2dayHeat>info.Forecast_1dayHeat&&Forecast_2dayW>Forecast_laterW){ | ||
244 | + info.DeathNote.push({hours: Math.round(Math.random()*23)+24,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "바람이 많이 불어 애인이 바람 남, 그 충격으로 사망"}) | ||
245 | + } | ||
246 | + else{ | ||
247 | + info.DeathNote.push({hours: Math.round(Math.random()*9000)+48,minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "바람이 많이 불어 애인이 바람 남, 그 충격으로 사망"}) | ||
248 | + } | ||
249 | + //경고 | ||
184 | 250 | ||
185 | - info.death_factor = Death_Factors[Math.round(Math.random()*Death_Factors.length)]; //사망요인 하나를 렌덤으로 고른다. | 251 | + if(info.Forecast_warning=='Y'){ |
252 | + info.DeathNote.push({hours: Math.round(Math.random()*9000),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "과다 긴장으로 발작하여 사망"}) | ||
253 | + } | ||
254 | + //태풍 | ||
255 | + if(info.Forecast_typhoon=='Y'){ | ||
256 | + info.DeathNote.push({hours: Math.round(Math.random()*9000),minutes: Math.round(Math.random()*59), seconds: Math.round(Math.random()*59), factor: "태풍에 휩쓸려 사망"}) | ||
257 | + } | ||
186 | 258 | ||
187 | 259 | ||
188 | //이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보 | 260 | //이벤트 기반으로 일정 시간 간격으로 클라이언트에게 보낼 정보 |
... | @@ -193,10 +265,14 @@ module.exports = (server, app) => { | ... | @@ -193,10 +265,14 @@ module.exports = (server, app) => { |
193 | rain: info.rain, | 265 | rain: info.rain, |
194 | death: info.death_prob, | 266 | death: info.death_prob, |
195 | factor: info.death_factor, | 267 | factor: info.death_factor, |
268 | + deathnote: info.DeathNote, | ||
269 | + | ||
196 | }; | 270 | }; |
197 | function getRandom_add_prob(min, max) { | 271 | function getRandom_add_prob(min, max) { |
198 | return Math.random() * (max - min) + min; | 272 | return Math.random() * (max - min) + min; |
199 | } | 273 | } |
274 | + | ||
275 | + | ||
200 | 276 | ||
201 | 277 | ||
202 | //심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음 | 278 | //심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음 |
... | @@ -210,6 +286,9 @@ module.exports = (server, app) => { | ... | @@ -210,6 +286,9 @@ module.exports = (server, app) => { |
210 | if(Destiny==0)Destiny=1; //사용자 잘못 입력했을때 예외처리 | 286 | if(Destiny==0)Destiny=1; //사용자 잘못 입력했을때 예외처리 |
211 | Math.random() * 2 >= 1 ? client_send.death += Destiny : client_send.death -= Destiny ; | 287 | Math.random() * 2 >= 1 ? client_send.death += Destiny : client_send.death -= Destiny ; |
212 | 288 | ||
289 | + | ||
290 | + if (client_birth.charAt(0)=='1')//아이는 죽지 않아요 | ||
291 | + client_send.death=0; | ||
213 | 292 | ||
214 | //만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리 | 293 | //만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리 |
215 | if (client_send.death >= 100) { | 294 | if (client_send.death >= 100) { |
... | @@ -252,6 +331,7 @@ module.exports = (server, app) => { | ... | @@ -252,6 +331,7 @@ module.exports = (server, app) => { |
252 | socket.on('disconnect', (reason) => { | 331 | socket.on('disconnect', (reason) => { |
253 | console.log("disconnected"); | 332 | console.log("disconnected"); |
254 | clearInterval(call_interval); //연결 종료시 interval 해제 | 333 | clearInterval(call_interval); //연결 종료시 interval 해제 |
334 | + | ||
255 | }) | 335 | }) |
256 | }) | 336 | }) |
257 | 337 | ... | ... |
... | @@ -12,7 +12,7 @@ router.post('/forecasting' , (req,res) =>{ | ... | @@ -12,7 +12,7 @@ router.post('/forecasting' , (req,res) =>{ |
12 | res.redirect(`/Fname/${req.body.name}/Fbirth/${req.body.birth}`); | 12 | res.redirect(`/Fname/${req.body.name}/Fbirth/${req.body.birth}`); |
13 | }) | 13 | }) |
14 | 14 | ||
15 | -router.get('/Fname/:Fname/Fbirth/:Fbirth',(req,res)=>{ | 15 | +router.get('/Fname/:name/Fbirth/:birth',(req,res)=>{ |
16 | 16 | ||
17 | // 렌더링 변수 | 17 | // 렌더링 변수 |
18 | var time = new Array(); // 타임스탬프 | 18 | var time = new Array(); // 타임스탬프 |
... | @@ -39,7 +39,7 @@ router.get('/Fname/:Fname/Fbirth/:Fbirth',(req,res)=>{ | ... | @@ -39,7 +39,7 @@ router.get('/Fname/:Fname/Fbirth/:Fbirth',(req,res)=>{ |
39 | if (rows.length == 0) | 39 | if (rows.length == 0) |
40 | { | 40 | { |
41 | empty = 1; | 41 | empty = 1; |
42 | - } | 42 | + } |
43 | else | 43 | else |
44 | { | 44 | { |
45 | for(var i = rows.length - 1; i >= 0; i--) | 45 | for(var i = rows.length - 1; i >= 0; i--) |
... | @@ -73,7 +73,7 @@ router.get('/Fname/:Fname/Fbirth/:Fbirth',(req,res)=>{ | ... | @@ -73,7 +73,7 @@ router.get('/Fname/:Fname/Fbirth/:Fbirth',(req,res)=>{ |
73 | }); | 73 | }); |
74 | } ) | 74 | } ) |
75 | 75 | ||
76 | -router.get('/Cname/:Cname/Cbirth/:Cbirth', (req,res) => { | 76 | +router.get('/Cname/:name/Cbirth/:birth', (req,res) => { |
77 | 77 | ||
78 | // 렌더링 변수 | 78 | // 렌더링 변수 |
79 | var time = new Array(); // 타임스탬프 | 79 | var time = new Array(); // 타임스탬프 | ... | ... |
... | @@ -175,11 +175,13 @@ | ... | @@ -175,11 +175,13 @@ |
175 | }) | 175 | }) |
176 | i++; | 176 | i++; |
177 | } | 177 | } |
178 | - | 178 | + |
179 | + | ||
179 | <% for(var n; n < probArr.length; n++) {%> | 180 | <% for(var n; n < probArr.length; n++) {%> |
180 | var temp, temp2; | 181 | var temp, temp2; |
181 | temp = <%=probArr[n] %>; | 182 | temp = <%=probArr[n] %>; |
182 | - temp2 = <%=factorArr[n] %>; | 183 | + temp2 = '<%= factorArr[n] %>'; |
184 | + | ||
183 | 185 | ||
184 | // for(;j<10;j++) | 186 | // for(;j<10;j++) |
185 | // { | 187 | // { | ... | ... |
-
Please register or login to post a comment