Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
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
nanahira
srvpro
Commits
051abd18
Commit
051abd18
authored
Feb 28, 2019
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ygopro-generate-result.js
parent
9961d6b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
0 deletions
+102
-0
ygopro-generate-result.js
ygopro-generate-result.js
+102
-0
No files found.
ygopro-generate-result.js
0 → 100644
View file @
051abd18
/*
ygopro-generate-result.js
ygopro tournament result generator
Author: Yuzurisa
License: MIT
Will generate the tournament result in a specific format.
*/
var
output_path
=
"
./config
"
if
(
process
.
argv
[
2
])
output_path
=
process
.
argv
[
2
];
const
loadJSON
=
require
(
'
load-json-file
'
).
sync
;
const
fs
=
require
(
'
fs
'
);
const
settings
=
loadJSON
(
'
./config/config.json
'
);
const
challonge_config
=
settings
.
modules
.
challonge
;
if
(
challonge_config
.
enabled
)
{
challonge
=
require
(
'
challonge
'
).
createClient
({
apiKey
:
challonge_config
.
api_key
});
}
else
{
console
.
error
(
"
Challonge is not enabled.
"
);
return
1
;
}
var
name_list
=
{};
var
results
=
{};
console
.
log
(
"
Requesting player datas from Challonge.
"
);
challonge
.
participants
.
index
({
id
:
challonge_config
.
tournament_id
,
callback
:
(
error
,
data
)
=>
{
if
(
error
||
!
data
)
{
console
.
error
(
error
);
return
;
}
for
(
var
k
in
data
)
{
const
player
=
data
[
k
];
if
(
!
player
||
!
player
.
participant
)
{
continue
;
}
const
player_info
=
player
.
participant
;
const
name
=
player_info
.
name
;
const
id
=
player_info
.
id
;
name_list
[
id
]
=
name
;
}
console
.
log
(
"
Requesting match datas from Challonge.
"
);
//for (var i = 1; i <=)
challonge
.
matches
.
index
({
id
:
challonge_config
.
tournament_id
,
callback
:
(
error
,
data
)
=>
{
if
(
error
||
!
data
)
{
console
.
error
(
error
);
return
;
}
for
(
var
k
in
data
)
{
const
match
=
data
[
k
];
if
(
!
match
||
!
match
.
match
)
{
continue
;
}
const
match_info
=
match
.
match
;
if
(
match_info
.
state
!=
"
complete
"
)
{
continue
;
}
const
sign
=
match_info
.
identifier
;
const
round
=
match_info
.
round
;
const
scores
=
match_info
.
scoresCsv
;
const
scores_data
=
scores
.
split
(
"
-
"
)
if
(
!
scores_data
||
scores_data
.
length
!=
2
)
continue
;
const
player1
=
match_info
.
player1Id
;
const
player2
=
match_info
.
player2Id
;
const
match_result
=
{
player1
:
scores_data
[
0
],
player2
:
scores_data
[
1
]
}
const
match_txt
=
"
[
"
+
sign
+
"
]组:
\n
[1号]
"
+
name_list
[
player1
]
+
"
"
+
scores_data
[
0
]
+
"
\n
[2号]
"
+
name_list
[
player2
]
+
"
"
+
scores_data
[
1
]
+
"
\n
"
;
if
(
!
results
[
round
])
results
[
round
]
=
[];
results
[
round
].
push
(
match_txt
);
}
console
.
log
(
"
Request completed. Outputing data.
"
)
var
player_text
=
""
;
for
(
var
k
in
name_list
)
{
player_text
=
player_text
+
name_list
[
k
]
+
"
\n
"
;
}
fs
.
writeFileSync
(
output_path
+
"
/player_list.txt
"
,
player_text
);
for
(
var
k
in
results
)
{
const
round_data
=
results
[
k
];
var
text
=
""
;
for
(
var
k1
in
round_data
)
{
text
=
text
+
round_data
[
k1
];
}
fs
.
writeFileSync
(
output_path
+
"
/match_
"
+
k
+
"
.txt
"
,
text
);
}
console
.
log
(
"
Finished.
"
)
}
})
}
})
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