Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-match
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-match
Commits
3a3433ea
Commit
3a3433ea
authored
Feb 20, 2017
by
Peter Xin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Predict time.
parent
51d028bd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
+24
-2
main.js
main.js
+24
-2
No files found.
main.js
View file @
3a3433ea
...
...
@@ -10,6 +10,8 @@ const config = JSON.parse(fs.readFileSync("./config.json"));
let
athleticUserPool
=
[];
let
entertainUserPool
=
[];
let
deadUserPool
=
[];
let
predictedEntertainTime
=
180
,
predictedAthleticTime
=
180
;
let
entertainRequestCountInTime
=
0
,
athleticRequestCountInTime
=
0
;
let
localLog
=
function
(
content
)
{
console
.
log
(
"
[
"
+
new
Date
().
toLocaleString
()
+
"
]
"
+
content
)
...
...
@@ -260,6 +262,25 @@ let closedUser = function (res, pool) {
deadUserPool
.
push
(
res
);
}
// 计算预期时间
let
calculatePredictedTime
=
function
()
{
if
(
entertainRequestCountInTime
==
0
)
predictedEntertainTime
=
180
;
else
{
predictedEntertainTime
=
600
/
entertainRequestCountInTime
;
entertainRequestCountInTime
=
0
;
}
localLog
(
"
entertain adjust predicted time to
"
+
predictedEntertainTime
+
"
s.
"
);
if
(
athleticRequestCountInTime
==
0
)
predictedAthleticTime
=
180
;
else
{
predictedAthleticTime
=
600
/
athleticRequestCountInTime
;
athleticRequestCountInTime
=
0
;
}
localLog
(
"
athletic adjust predicted time to
"
+
predictedAthleticTime
+
"
s.
"
);
};
setInterval
(
calculatePredictedTime
,
600000
);
// 创建服务器
const
server
=
http
.
createServer
((
req
,
res
)
=>
{
try
{
...
...
@@ -290,7 +311,9 @@ const server = http.createServer((req, res) => {
getUserConfig
(
res
,
(
ans
)
=>
{
joinPool
(
res
,
ans
,
pool
);
});
// 统计器
if
(
arg
.
arena
==
'
athletic
'
)
athleticRequestCountInTime
+=
1
;
else
entertainRequestCountInTime
+=
1
;
}
catch
(
error
)
{
localLog
(
error
);
...
...
@@ -298,7 +321,6 @@ const server = http.createServer((req, res) => {
res
.
end
();
return
;
}
})
server
.
timeout
=
0
server
.
listen
(
1025
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment