startgg-helper 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +4 -1
- package/package.json +1 -1
- package/src/jsUtil.js +51 -1
- package/src/query.js +0 -1
- package/src/queryLimiter.js +6 -10
- package/src/smashggData.js +3 -0
- package/src/tournamentUtil.js +81 -0
package/main.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "startgg-helper",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A set of functions and classes useful to communicate with the start.gg API, using any client (YOU NEED TO PROVIDE A CLIENT YOURSELF, SEE README)",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"scripts": {
|
package/src/jsUtil.js
CHANGED
|
@@ -9,7 +9,7 @@ function processObjectPath(path){
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
return path;
|
|
12
|
-
}
|
|
12
|
+
}//jsutil
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
@@ -41,4 +41,54 @@ export function deep_set(obj, path, value){
|
|
|
41
41
|
}
|
|
42
42
|
obj[finalName] = value;
|
|
43
43
|
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let currentID = 1;
|
|
47
|
+
export function generateUniqueID(){
|
|
48
|
+
return currentID++;
|
|
49
|
+
}//jsutil
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {(() => any)[]} fArray
|
|
54
|
+
*/
|
|
55
|
+
export function fResultsArray(fArray){
|
|
56
|
+
let result = [];
|
|
57
|
+
for (let f of fArray){
|
|
58
|
+
let res = f();
|
|
59
|
+
if (res !== undefined){
|
|
60
|
+
result.push(res);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {...(() => any)} functions
|
|
70
|
+
*/
|
|
71
|
+
export function fResults(...functions){
|
|
72
|
+
return fResultsArray(functions);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @param {any} data
|
|
78
|
+
* @param {boolean} pretty
|
|
79
|
+
*/
|
|
80
|
+
export function toJSON(data, pretty){
|
|
81
|
+
return JSON.stringify(data, null, pretty ? 4 : undefined);
|
|
82
|
+
}//jsutil
|
|
83
|
+
|
|
84
|
+
export function isNumber(n){
|
|
85
|
+
return typeof n == "number";
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
*
|
|
90
|
+
* @param {number | Date | string} d
|
|
91
|
+
*/
|
|
92
|
+
export function toUNIXTimestamp(d){
|
|
93
|
+
return isNaN(d) ? new Date(d).getTime() / 1000 : d;
|
|
44
94
|
}
|
package/src/query.js
CHANGED
package/src/queryLimiter.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
//i am a god of JS
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
class Client {
|
|
8
|
-
request(){}
|
|
9
|
-
}
|
|
3
|
+
//voir la diff avec la version de sgghelper ?
|
|
4
|
+
|
|
5
|
+
import { GraphQLClient } from "graphql-request";
|
|
10
6
|
|
|
11
7
|
export class TimedQuerySemaphore {
|
|
12
8
|
/**
|
|
13
|
-
* @typedef {{client:
|
|
9
|
+
* @typedef {{client: GraphQLClient, schema: string,
|
|
14
10
|
* params: {[varName: string]: value},
|
|
15
11
|
* resolve: (value: any) => void,
|
|
16
12
|
* reject: (reason?: any) => void}
|
|
@@ -47,7 +43,7 @@ export class TimedQuerySemaphore {
|
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
/**
|
|
50
|
-
* @param {
|
|
46
|
+
* @param {GraphQLClient} client
|
|
51
47
|
* @param {string} schema
|
|
52
48
|
* @param {{[varName: string]: value}} params
|
|
53
49
|
* @returns
|
|
@@ -74,7 +70,7 @@ export class TimedQuerySemaphore {
|
|
|
74
70
|
|
|
75
71
|
/**
|
|
76
72
|
* Executes the given query with the given GraphQL Client
|
|
77
|
-
* @param {
|
|
73
|
+
* @param {GraphQLClient} client
|
|
78
74
|
* @param {string} schema
|
|
79
75
|
* @param {{[varName: string]: value}} params
|
|
80
76
|
* @returns
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const placements = [
|
|
2
|
+
1, 2, 3, 4, 6,
|
|
3
|
+
8, 12, 16, 24, 32,
|
|
4
|
+
48, 64, 96, 128, 192,
|
|
5
|
+
256, 384, 512, 768, 1024,
|
|
6
|
+
1536, 2048, 3072, 4096, 6144,
|
|
7
|
+
8192, 12288, 16384, 24576, 32768,
|
|
8
|
+
49152, 65536, 98304, 131072, 196608,
|
|
9
|
+
262144, 393216, 524288, 786432, 1048576,
|
|
10
|
+
1572864, 2097152
|
|
11
|
+
]
|
|
12
|
+
//sggutil
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Extracts a slug from a string. Can be either the slug directly or the full URL.
|
|
16
|
+
* @param {string} string
|
|
17
|
+
*/
|
|
18
|
+
export function extractSlug(string){
|
|
19
|
+
if (string.includes("start.gg/")){
|
|
20
|
+
return string.split("start.gg/")[1];
|
|
21
|
+
}
|
|
22
|
+
return string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {string[]} list
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export function extractSlugs(list){
|
|
31
|
+
return list.map(str => extractSlug(str));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getDoubleEliminationPlacementTier(placement){
|
|
35
|
+
for (let tier of placements){
|
|
36
|
+
if (placement <= tier) return tier;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getDoubleEliminationUpsetFactorFromSeeds(winnerSeed, loserSeed){
|
|
41
|
+
if (winnerSeed < loserSeed) return 0;
|
|
42
|
+
|
|
43
|
+
let winnerExpectedTierID = -1, loserExpectedTierID = -1;
|
|
44
|
+
|
|
45
|
+
for (let i = 0; i < placements.length; i++){
|
|
46
|
+
if (winnerSeed <= placements[i]) {winnerExpectedTierID = i; break;}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (let i = 0; i < placements.length; i++){
|
|
50
|
+
if (loserSeed <= placements[i]) {
|
|
51
|
+
loserExpectedTierID = i;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!winnerExpectedTierID < 0 || !loserExpectedTierID < 0) return undefined;
|
|
57
|
+
|
|
58
|
+
return (winnerExpectedTierID - loserExpectedTierID);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function getDoubleEliminationUpsetFactorFromSet(set){
|
|
62
|
+
let score1 = set.slots[0].standing.stats.score.value;
|
|
63
|
+
let score2 = set.slots[1].standing.stats.score.value;
|
|
64
|
+
let seed1 = set.slots[0].entrant.initialSeedNum;
|
|
65
|
+
let seed2 = set.slots[1].entrant.initialSeedNum;
|
|
66
|
+
|
|
67
|
+
if (score1 < 0 || score2 < 0) return [0, 0];
|
|
68
|
+
|
|
69
|
+
//console.log(set.slots[0].entrant.name, set.slots[1].entrant.name);
|
|
70
|
+
//console.log(score1, score2, seed1, seed2);
|
|
71
|
+
|
|
72
|
+
return (score1 > score2) ? [getDoubleEliminationUpsetFactorFromSeeds(seed1, seed2), 0] : [getDoubleEliminationUpsetFactorFromSeeds(seed2, seed1), 1];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns the tournament part in an event slug. Assumes the event slug is valid
|
|
77
|
+
* @param {string} eventSlug
|
|
78
|
+
*/
|
|
79
|
+
export function getTournamentSlugFromEventSlug(eventSlug){
|
|
80
|
+
return eventSlug.split(/\/event/g)[0];
|
|
81
|
+
}
|