DESKTOP-PC6TBNS\강환석씨

create main page , added death cause => name , birth

...@@ -20,6 +20,7 @@ app.use(express.urlencoded({ extended: false })); ...@@ -20,6 +20,7 @@ app.use(express.urlencoded({ extended: false }));
20 app.use(cookieParser()); 20 app.use(cookieParser());
21 app.use(express.static(path.join(__dirname, 'public'))); 21 app.use(express.static(path.join(__dirname, 'public')));
22 app.use(express.static(path.join(__dirname, 'code'))); 22 app.use(express.static(path.join(__dirname, 'code')));
23 +app.use('/name/:name/birth',express.static(path.join(__dirname, 'code')));
23 24
24 app.use('/', indexRouter); 25 app.use('/', indexRouter);
25 app.use('/users', usersRouter); 26 app.use('/users', usersRouter);
......
...@@ -16,6 +16,9 @@ module.exports = (server, app) => { ...@@ -16,6 +16,9 @@ module.exports = (server, app) => {
16 let Ultra_Violet_index = {}; 16 let Ultra_Violet_index = {};
17 let sending_to_client_info = {}; 17 let sending_to_client_info = {};
18 let client_send = {}; 18 let client_send = {};
19 + let client_name = "";
20 + let client_birth ;
21 + let Destiny;
19 let sql; 22 let sql;
20 23
21 let info = {} 24 let info = {}
...@@ -99,9 +102,18 @@ module.exports = (server, app) => { ...@@ -99,9 +102,18 @@ module.exports = (server, app) => {
99 return Math.random() * (max - min) + min; 102 return Math.random() * (max - min) + min;
100 } 103 }
101 104
102 - // 심장마비로 갑자기 확률 증가 할 수 있음 105 +
106 + // 심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음
103 Math.random() * 2 >= 1 ? client_send.death += getRandom_add_prob(0,10) : client_send.death -= getRandom_add_prob(0,10) ; 107 Math.random() * 2 >= 1 ? client_send.death += getRandom_add_prob(0,10) : client_send.death -= getRandom_add_prob(0,10) ;
108 +
109 +
110 + //운명의 장난으로 죽을 확률이 증가하거나 감소함
111 + const rand = Math.floor(Math.random() * 6) //생년월일 중 한자리 뽑음
104 112
113 + Destiny=client_birth.charAt(rand)*1; //명시적 형 변환
114 + if(Destiny==0)Destiny=1; //사용자 잘못 입력했을때 예외처리
115 + Math.random() * 2 >= 1 ? client_send.death += Destiny : client_send.death -= Destiny ;
116 +
105 117
106 //만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리 118 //만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리
107 if (client_send.death >= 100) { 119 if (client_send.death >= 100) {
...@@ -133,9 +145,10 @@ module.exports = (server, app) => { ...@@ -133,9 +145,10 @@ module.exports = (server, app) => {
133 io.on('connection', (socket) => { //프론트와 소켓 연결시 이벤트 루프 동작 145 io.on('connection', (socket) => { //프론트와 소켓 연결시 이벤트 루프 동작
134 146
135 app.set("socket", socket); 147 app.set("socket", socket);
136 - socket.on("connection", () => { 148 + socket.on("connection", (client_data) => {
137 console.log("SOCKET CONNECTED"); 149 console.log("SOCKET CONNECTED");
138 - 150 + client_name = client_data.name;
151 + client_birth = client_data.birth;
139 Start_Interval(60, API_bundle); //소켓 연결후 interval 활성화하여 1분마다 API 호출 152 Start_Interval(60, API_bundle); //소켓 연결후 interval 활성화하여 1분마다 API 호출
140 153
141 }); 154 });
......
...@@ -3,8 +3,12 @@ var router = express.Router(); ...@@ -3,8 +3,12 @@ var router = express.Router();
3 var db = require('../lib/db'); 3 var db = require('../lib/db');
4 4
5 /* GET home page. */ 5 /* GET home page. */
6 -router.get('/', function(req, res, next) {
7 6
7 +router.post('/starting' , (req,res) => {
8 + res.redirect(`/name/${req.body.name}/birth/${req.body.birth}`);
9 +})
10 +router.get('/name/:name/birth/:birth', (req,res) => {
11 +
8 // 렌더링 변수 12 // 렌더링 변수
9 var time = new Array(); // 타임스탬프 13 var time = new Array(); // 타임스탬프
10 var ptArr = new Array(); // 현재 온도 14 var ptArr = new Array(); // 현재 온도
...@@ -15,6 +19,8 @@ router.get('/', function(req, res, next) { ...@@ -15,6 +19,8 @@ router.get('/', function(req, res, next) {
15 var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음 19 var empty = 0; // 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
16 var sql = ""; // 쿼리 20 var sql = ""; // 쿼리
17 var count = 0; 21 var count = 0;
22 + const name = req.params.name;
23 + const birth = req.params.birth;
18 24
19 // 이전 10분간 데이터 찾기 25 // 이전 10분간 데이터 찾기
20 sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -20 MINUTE), '%Y-%m-%d %H:%i:%s')"; 26 sql = "SELECT * FROM weatherInfo WHERE time >= DATE_FORMAT(DATE_ADD(now(), INTERVAL -20 MINUTE), '%Y-%m-%d %H:%i:%s')";
...@@ -55,10 +61,15 @@ router.get('/', function(req, res, next) { ...@@ -55,10 +61,15 @@ router.get('/', function(req, res, next) {
55 wsArr, 61 wsArr,
56 rainArr, 62 rainArr,
57 probArr, 63 probArr,
58 - dataLen 64 + dataLen,
65 + name,
66 + birth
59 }); 67 });
60 } 68 }
61 }); 69 });
70 +} )
71 +router.get('/', function(req, res, next) {
72 + res.render( 'main' );
62 }); 73 });
63 74
64 module.exports = router; 75 module.exports = router;
......
...@@ -42,8 +42,12 @@ ...@@ -42,8 +42,12 @@
42 42
43 <script src="/socket.io/socket.io.js"></script> 43 <script src="/socket.io/socket.io.js"></script>
44 <script> 44 <script>
45 + let client_data={
46 + birth : "<%=birth%>",
47 + name : "<%=name%>"
48 + }
45 var socket = io.connect('/',{transports: ['websocket'],upgrade:false}); 49 var socket = io.connect('/',{transports: ['websocket'],upgrade:false});
46 - socket.emit("connection","client in"); 50 + socket.emit("connection",client_data);
47 socket.on("weatherInfo_minutely_send_to_client",(info)=>{ //서버에서 client에게 메세지 전송 51 socket.on("weatherInfo_minutely_send_to_client",(info)=>{ //서버에서 client에게 메세지 전송
48 console.log(info); 52 console.log(info);
49 }); 53 });
...@@ -73,7 +77,7 @@ ...@@ -73,7 +77,7 @@
73 }, 77 },
74 78
75 title: { 79 title: {
76 - text: "실시간 사망률" 80 + text: "<%=name%>님의 실시간 사망률"
77 }, 81 },
78 xAxis: { 82 xAxis: {
79 type: "datetime", 83 type: "datetime",
......
1 +<form action = "/starting" method = "post">
2 + <label>이름</label>
3 + <input type="text" name = "name">
4 + <label>생년월일</label>
5 + <input type="text" name = "birth">
6 + <input type="submit" value = "시작">
7 +</form>
...\ No newline at end of file ...\ No newline at end of file