Skip to content

Commit

Permalink
feat: support srk 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Sep 4, 2023
1 parent 259c23a commit 4e900e0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algoux/standard-ranklist-utils",
"version": "0.1.0",
"version": "0.1.1",
"author": "bLue",
"keywords": [
"standard ranklist",
Expand All @@ -24,7 +24,7 @@
"textcolor": "^1.0.2"
},
"devDependencies": {
"@algoux/standard-ranklist": "^0.3.2",
"@algoux/standard-ranklist": "^0.3.3",
"@types/node": "^16.18.38",
"@types/semver": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^5.61.0",
Expand All @@ -47,5 +47,6 @@
"bugs": {
"url": "https://github.com/algoux/standard-ranklist-utils/issues"
},
"homepage": "https://github.com/algoux/standard-ranklist-utils#readme"
"homepage": "https://github.com/algoux/standard-ranklist-utils#readme",
"srkSupportedVersions": ">=0.3.0 <=0.3.3"
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 41 additions & 7 deletions src/ranklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,45 @@ function genSeriesCalcFns(
}
case 'ICPC': {
const options = rule.options as srk.RankSeriesRulePresetICPC['options'];
let filteredRows = rows.filter((row) => row.user.official === undefined || row.user.official === true);
let filteredOfficialRanks = [...officialRanks];
if (options.filter) {
if (Array.isArray(options.filter.byUserFields) && options.filter.byUserFields.length) {
const currentFilteredRows: typeof filteredRows = [];
filteredOfficialRanks = filteredOfficialRanks.map(() => null);
let currentOfficialRank = 0;
let currentOfficialRankOld = 0;
rows.forEach((row, index) => {
const shouldInclude = options.filter!.byUserFields!.every((filter) => {
const { field, rule } = filter;
const value = row.user[field];
if (value === undefined) {
return false;
}
return new RegExp(rule).test(`${value}`);
});
if (shouldInclude) {
currentFilteredRows.push(row);
const oldRank = officialRanks[index]!;
if (oldRank !== null) {
if (currentOfficialRankOld !== oldRank) {
currentOfficialRank++;
currentOfficialRankOld = oldRank;
}
filteredOfficialRanks[index] = currentOfficialRank;
} else {
filteredOfficialRanks[index] = null;
}
}
});
filteredRows = currentFilteredRows;
}
}
const usingEndpointRules: number[][] = [];
let noTied = false;
if (options.ratio) {
const { value, rounding = 'ceil', denominator = 'all' } = options.ratio;
const officialRows = rows.filter((row) => row.user.official === undefined || row.user.official === true);
const officialRows = filteredRows;
let total =
denominator === 'submitted'
? officialRows.filter((row) => !row.statuses.every((s) => s.result === null)).length
Expand Down Expand Up @@ -402,13 +436,13 @@ function genSeriesCalcFns(
noTied = true;
}
}
const officialRanksNoTied: typeof officialRanks = [];
const officialRanksNoTied: typeof filteredOfficialRanks = [];
let currentOfficialRank = 0;
for (let i = 0; i < officialRanks.length; i++) {
officialRanksNoTied.push(officialRanks[i] === null ? null : ++currentOfficialRank);
for (let i = 0; i < filteredOfficialRanks.length; i++) {
officialRanksNoTied.push(filteredOfficialRanks[i] === null ? null : ++currentOfficialRank);
}
return (row, index) => {
if (row.user.official === false) {
if (row.user.official === false || !filteredRows.find((r) => r.user.id === row.user.id)) {
return {
rank: null,
segmentIndex: null,
Expand All @@ -417,10 +451,10 @@ function genSeriesCalcFns(
const usingSegmentIndex = (seriesConfig.segments || []).findIndex((_, segIndex) => {
return usingEndpointRules
.map((e) => e[segIndex])
.every((endpoints) => (noTied ? officialRanksNoTied : officialRanks)[index]! <= endpoints);
.every((endpoints) => (noTied ? officialRanksNoTied : filteredOfficialRanks)[index]! <= endpoints);
});
return {
rank: officialRanks[index],
rank: filteredOfficialRanks[index],
segmentIndex: usingSegmentIndex > -1 ? usingSegmentIndex : null,
};
};
Expand Down

0 comments on commit 4e900e0

Please sign in to comment.