@algoux/standard-ranklist-utils 0.2.1 → 0.2.3
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/dist/index.cjs +35 -11
- package/dist/index.mjs +35 -11
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -269,6 +269,21 @@ function sortRows(rows) {
|
|
|
269
269
|
});
|
|
270
270
|
return rows;
|
|
271
271
|
}
|
|
272
|
+
function cloneDeep(obj) {
|
|
273
|
+
if (obj === null || typeof obj !== "object") {
|
|
274
|
+
return obj;
|
|
275
|
+
}
|
|
276
|
+
if (Array.isArray(obj)) {
|
|
277
|
+
return obj.map((item) => cloneDeep(item));
|
|
278
|
+
}
|
|
279
|
+
const clonedObj = {};
|
|
280
|
+
for (const key in obj) {
|
|
281
|
+
if (obj.hasOwnProperty(key)) {
|
|
282
|
+
clonedObj[key] = cloneDeep(obj[key]);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return clonedObj;
|
|
286
|
+
}
|
|
272
287
|
function regenerateRanklistBySolutions(originalRanklist, solutions) {
|
|
273
288
|
var _a;
|
|
274
289
|
if (!canRegenerateRanklist(originalRanklist)) {
|
|
@@ -278,15 +293,18 @@ function regenerateRanklistBySolutions(originalRanklist, solutions) {
|
|
|
278
293
|
penalty: [20, "min"],
|
|
279
294
|
noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
|
|
280
295
|
timeRounding: "floor",
|
|
281
|
-
...
|
|
282
|
-
};
|
|
283
|
-
const ranklist = {
|
|
284
|
-
...originalRanklist,
|
|
285
|
-
rows: []
|
|
296
|
+
...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
|
|
286
297
|
};
|
|
298
|
+
const ranklist = {};
|
|
299
|
+
for (const key in originalRanklist) {
|
|
300
|
+
if (key !== "rows" && originalRanklist.hasOwnProperty(key)) {
|
|
301
|
+
ranklist[key] = cloneDeep(originalRanklist[key]);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
ranklist.rows = [];
|
|
287
305
|
const rows = [];
|
|
288
306
|
const userRowMap = /* @__PURE__ */ new Map();
|
|
289
|
-
const problemCount =
|
|
307
|
+
const problemCount = ranklist.problems.length;
|
|
290
308
|
originalRanklist.rows.forEach((row) => {
|
|
291
309
|
const userId = row.user.id && `${row.user.id}` || `${typeof row.user.name === "string" ? row.user.name : JSON.stringify(row.user.name)}`;
|
|
292
310
|
userRowMap.set(userId, {
|
|
@@ -382,7 +400,7 @@ function regenerateRowsByIncrementalSolutions(originalRanklist, solutions) {
|
|
|
382
400
|
penalty: [20, "min"],
|
|
383
401
|
noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
|
|
384
402
|
timeRounding: "floor",
|
|
385
|
-
...
|
|
403
|
+
...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
|
|
386
404
|
};
|
|
387
405
|
const userRowIndexMap = /* @__PURE__ */ new Map();
|
|
388
406
|
const rows = [...originalRanklist.rows];
|
|
@@ -608,13 +626,15 @@ function genSeriesCalcFns(series, rows, ranks, officialRanks) {
|
|
|
608
626
|
});
|
|
609
627
|
return fns;
|
|
610
628
|
}
|
|
611
|
-
function genRowRanks(rows) {
|
|
629
|
+
function genRowRanks(rows, options = {}) {
|
|
612
630
|
const compareScoreEqual = (a, b) => {
|
|
613
631
|
if (a.value !== b.value) {
|
|
614
632
|
return false;
|
|
615
633
|
}
|
|
616
|
-
const
|
|
617
|
-
const
|
|
634
|
+
const rankingTimePrecision = options.rankingTimePrecision || "ms";
|
|
635
|
+
const rankingTimeRoundingFn = options.rankingTimeRounding === "ceil" ? Math.ceil : options.rankingTimeRounding === "round" ? Math.round : Math.floor;
|
|
636
|
+
const da = a.time ? formatTimeDuration(a.time, rankingTimePrecision, rankingTimeRoundingFn) : 0;
|
|
637
|
+
const db = b.time ? formatTimeDuration(b.time, rankingTimePrecision, rankingTimeRoundingFn) : 0;
|
|
618
638
|
return da === db;
|
|
619
639
|
};
|
|
620
640
|
const genRanks = (rows2) => {
|
|
@@ -651,11 +671,15 @@ function genRowRanks(rows) {
|
|
|
651
671
|
};
|
|
652
672
|
}
|
|
653
673
|
function convertToStaticRanklist(ranklist) {
|
|
674
|
+
var _a, _b, _c, _d;
|
|
654
675
|
if (!ranklist) {
|
|
655
676
|
return ranklist;
|
|
656
677
|
}
|
|
657
678
|
const { series, rows } = ranklist;
|
|
658
|
-
const rowRanks = genRowRanks(rows
|
|
679
|
+
const rowRanks = genRowRanks(rows, {
|
|
680
|
+
rankingTimePrecision: (_b = (_a = ranklist.sorter) == null ? void 0 : _a.config) == null ? void 0 : _b.rankingTimePrecision,
|
|
681
|
+
rankingTimeRounding: (_d = (_c = ranklist.sorter) == null ? void 0 : _c.config) == null ? void 0 : _d.rankingTimeRounding
|
|
682
|
+
});
|
|
659
683
|
const seriesCalcFns = genSeriesCalcFns(series, rows, rowRanks.ranks, rowRanks.officialRanks);
|
|
660
684
|
return {
|
|
661
685
|
...ranklist,
|
package/dist/index.mjs
CHANGED
|
@@ -267,6 +267,21 @@ function sortRows(rows) {
|
|
|
267
267
|
});
|
|
268
268
|
return rows;
|
|
269
269
|
}
|
|
270
|
+
function cloneDeep(obj) {
|
|
271
|
+
if (obj === null || typeof obj !== "object") {
|
|
272
|
+
return obj;
|
|
273
|
+
}
|
|
274
|
+
if (Array.isArray(obj)) {
|
|
275
|
+
return obj.map((item) => cloneDeep(item));
|
|
276
|
+
}
|
|
277
|
+
const clonedObj = {};
|
|
278
|
+
for (const key in obj) {
|
|
279
|
+
if (obj.hasOwnProperty(key)) {
|
|
280
|
+
clonedObj[key] = cloneDeep(obj[key]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return clonedObj;
|
|
284
|
+
}
|
|
270
285
|
function regenerateRanklistBySolutions(originalRanklist, solutions) {
|
|
271
286
|
var _a;
|
|
272
287
|
if (!canRegenerateRanklist(originalRanklist)) {
|
|
@@ -276,15 +291,18 @@ function regenerateRanklistBySolutions(originalRanklist, solutions) {
|
|
|
276
291
|
penalty: [20, "min"],
|
|
277
292
|
noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
|
|
278
293
|
timeRounding: "floor",
|
|
279
|
-
...
|
|
280
|
-
};
|
|
281
|
-
const ranklist = {
|
|
282
|
-
...originalRanklist,
|
|
283
|
-
rows: []
|
|
294
|
+
...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
|
|
284
295
|
};
|
|
296
|
+
const ranklist = {};
|
|
297
|
+
for (const key in originalRanklist) {
|
|
298
|
+
if (key !== "rows" && originalRanklist.hasOwnProperty(key)) {
|
|
299
|
+
ranklist[key] = cloneDeep(originalRanklist[key]);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
ranklist.rows = [];
|
|
285
303
|
const rows = [];
|
|
286
304
|
const userRowMap = /* @__PURE__ */ new Map();
|
|
287
|
-
const problemCount =
|
|
305
|
+
const problemCount = ranklist.problems.length;
|
|
288
306
|
originalRanklist.rows.forEach((row) => {
|
|
289
307
|
const userId = row.user.id && `${row.user.id}` || `${typeof row.user.name === "string" ? row.user.name : JSON.stringify(row.user.name)}`;
|
|
290
308
|
userRowMap.set(userId, {
|
|
@@ -380,7 +398,7 @@ function regenerateRowsByIncrementalSolutions(originalRanklist, solutions) {
|
|
|
380
398
|
penalty: [20, "min"],
|
|
381
399
|
noPenaltyResults: ["FB", "AC", "?", "CE", "UKE", null],
|
|
382
400
|
timeRounding: "floor",
|
|
383
|
-
...
|
|
401
|
+
...cloneDeep(((_a = originalRanklist.sorter) == null ? void 0 : _a.config) || {})
|
|
384
402
|
};
|
|
385
403
|
const userRowIndexMap = /* @__PURE__ */ new Map();
|
|
386
404
|
const rows = [...originalRanklist.rows];
|
|
@@ -606,13 +624,15 @@ function genSeriesCalcFns(series, rows, ranks, officialRanks) {
|
|
|
606
624
|
});
|
|
607
625
|
return fns;
|
|
608
626
|
}
|
|
609
|
-
function genRowRanks(rows) {
|
|
627
|
+
function genRowRanks(rows, options = {}) {
|
|
610
628
|
const compareScoreEqual = (a, b) => {
|
|
611
629
|
if (a.value !== b.value) {
|
|
612
630
|
return false;
|
|
613
631
|
}
|
|
614
|
-
const
|
|
615
|
-
const
|
|
632
|
+
const rankingTimePrecision = options.rankingTimePrecision || "ms";
|
|
633
|
+
const rankingTimeRoundingFn = options.rankingTimeRounding === "ceil" ? Math.ceil : options.rankingTimeRounding === "round" ? Math.round : Math.floor;
|
|
634
|
+
const da = a.time ? formatTimeDuration(a.time, rankingTimePrecision, rankingTimeRoundingFn) : 0;
|
|
635
|
+
const db = b.time ? formatTimeDuration(b.time, rankingTimePrecision, rankingTimeRoundingFn) : 0;
|
|
616
636
|
return da === db;
|
|
617
637
|
};
|
|
618
638
|
const genRanks = (rows2) => {
|
|
@@ -649,11 +669,15 @@ function genRowRanks(rows) {
|
|
|
649
669
|
};
|
|
650
670
|
}
|
|
651
671
|
function convertToStaticRanklist(ranklist) {
|
|
672
|
+
var _a, _b, _c, _d;
|
|
652
673
|
if (!ranklist) {
|
|
653
674
|
return ranklist;
|
|
654
675
|
}
|
|
655
676
|
const { series, rows } = ranklist;
|
|
656
|
-
const rowRanks = genRowRanks(rows
|
|
677
|
+
const rowRanks = genRowRanks(rows, {
|
|
678
|
+
rankingTimePrecision: (_b = (_a = ranklist.sorter) == null ? void 0 : _a.config) == null ? void 0 : _b.rankingTimePrecision,
|
|
679
|
+
rankingTimeRounding: (_d = (_c = ranklist.sorter) == null ? void 0 : _c.config) == null ? void 0 : _d.rankingTimeRounding
|
|
680
|
+
});
|
|
657
681
|
const seriesCalcFns = genSeriesCalcFns(series, rows, rowRanks.ranks, rowRanks.officialRanks);
|
|
658
682
|
return {
|
|
659
683
|
...ranklist,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algoux/standard-ranklist-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"author": "bLue",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"standard ranklist",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"textcolor": "^1.0.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@algoux/standard-ranklist": "^0.3.
|
|
38
|
+
"@algoux/standard-ranklist": "^0.3.7",
|
|
39
39
|
"@types/node": "^16.18.38",
|
|
40
40
|
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
|
41
41
|
"@typescript-eslint/parser": "^5.61.0",
|