Toggle navigation
Toggle navigation
This project
Loading...
Sign in
kkl
/
Probability Death
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
DESKTOP-PC6TBNS\강환석씨
2018-12-12 01:16:42 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f7683df1230078ea642a61e049cf58924a7460ab
f7683df1
1 parent
de17b8ba
create main page , added death cause => name , birth
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
7 deletions
app.js
lib/socketio.js
routes/index.js
views/index.ejs
views/main.ejs
app.js
View file @
f7683df
...
...
@@ -20,6 +20,7 @@ app.use(express.urlencoded({ extended: false }));
app
.
use
(
cookieParser
());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'public'
)));
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'code'
)));
app
.
use
(
'/name/:name/birth'
,
express
.
static
(
path
.
join
(
__dirname
,
'code'
)));
app
.
use
(
'/'
,
indexRouter
);
app
.
use
(
'/users'
,
usersRouter
);
...
...
lib/socketio.js
View file @
f7683df
...
...
@@ -16,6 +16,9 @@ module.exports = (server, app) => {
let
Ultra_Violet_index
=
{};
let
sending_to_client_info
=
{};
let
client_send
=
{};
let
client_name
=
""
;
let
client_birth
;
let
Destiny
;
let
sql
;
let
info
=
{}
...
...
@@ -99,9 +102,18 @@ module.exports = (server, app) => {
return
Math
.
random
()
*
(
max
-
min
)
+
min
;
}
// 심장마비로 갑자기 확률 증가 할 수 있음
// 심장이 크게 뛰며 확률이 증가하거나 감소 할 수 있음
Math
.
random
()
*
2
>=
1
?
client_send
.
death
+=
getRandom_add_prob
(
0
,
10
)
:
client_send
.
death
-=
getRandom_add_prob
(
0
,
10
)
;
//운명의 장난으로 죽을 확률이 증가하거나 감소함
const
rand
=
Math
.
floor
(
Math
.
random
()
*
6
)
//생년월일 중 한자리 뽑음
Destiny
=
client_birth
.
charAt
(
rand
)
*
1
;
//명시적 형 변환
if
(
Destiny
==
0
)
Destiny
=
1
;
//사용자 잘못 입력했을때 예외처리
Math
.
random
()
*
2
>=
1
?
client_send
.
death
+=
Destiny
:
client_send
.
death
-=
Destiny
;
//만약 날이 너무 안좋아서 확률이 100을 넘긴다면 100으로 예외처리
if
(
client_send
.
death
>=
100
)
{
...
...
@@ -133,9 +145,10 @@ module.exports = (server, app) => {
io
.
on
(
'connection'
,
(
socket
)
=>
{
//프론트와 소켓 연결시 이벤트 루프 동작
app
.
set
(
"socket"
,
socket
);
socket
.
on
(
"connection"
,
()
=>
{
socket
.
on
(
"connection"
,
(
client_data
)
=>
{
console
.
log
(
"SOCKET CONNECTED"
);
client_name
=
client_data
.
name
;
client_birth
=
client_data
.
birth
;
Start_Interval
(
60
,
API_bundle
);
//소켓 연결후 interval 활성화하여 1분마다 API 호출
});
...
...
routes/index.js
View file @
f7683df
...
...
@@ -3,8 +3,12 @@ var router = express.Router();
var
db
=
require
(
'../lib/db'
);
/* GET home page. */
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/starting'
,
(
req
,
res
)
=>
{
res
.
redirect
(
`/name/
${
req
.
body
.
name
}
/birth/
${
req
.
body
.
birth
}
`
);
})
router
.
get
(
'/name/:name/birth/:birth'
,
(
req
,
res
)
=>
{
// 렌더링 변수
var
time
=
new
Array
();
// 타임스탬프
var
ptArr
=
new
Array
();
// 현재 온도
...
...
@@ -15,6 +19,8 @@ router.get('/', function(req, res, next) {
var
empty
=
0
;
// 초기값 유뮤, 0 : 자료 있음, 1 : 자료 없음
var
sql
=
""
;
// 쿼리
var
count
=
0
;
const
name
=
req
.
params
.
name
;
const
birth
=
req
.
params
.
birth
;
// 이전 10분간 데이터 찾기
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) {
wsArr
,
rainArr
,
probArr
,
dataLen
dataLen
,
name
,
birth
});
}
});
}
)
router
.
get
(
'/'
,
function
(
req
,
res
,
next
)
{
res
.
render
(
'main'
);
});
module
.
exports
=
router
;
...
...
views/index.ejs
View file @
f7683df
...
...
@@ -42,8 +42,12 @@
<script
src=
"/socket.io/socket.io.js"
></script>
<script>
let
client_data
=
{
birth
:
"<%=birth%>"
,
name
:
"<%=name%>"
}
var
socket
=
io
.
connect
(
'/'
,{
transports
:
[
'websocket'
],
upgrade
:
false
});
socket
.
emit
(
"connection"
,
"client in"
);
socket
.
emit
(
"connection"
,
client_data
);
socket
.
on
(
"weatherInfo_minutely_send_to_client"
,(
info
)
=>
{
//서버에서 client에게 메세지 전송
console
.
log
(
info
);
});
...
...
@@ -73,7 +77,7 @@
},
title
:
{
text
:
"실시간 사망률"
text
:
"
<%=name%>님의
실시간 사망률"
},
xAxis
:
{
type
:
"datetime"
,
...
...
views/main.ejs
0 → 100644
View file @
f7683df
<form action = "/starting" method = "post">
<label>이름</label>
<input type="text" name = "name">
<label>생년월일</label>
<input type="text" name = "birth">
<input type="submit" value = "시작">
</form>
\ No newline at end of file
Please
register
or
login
to post a comment