Skip to content

Commit

Permalink
update; refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
conlacda committed Aug 24, 2024
1 parent dae7960 commit 1d7b5fc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion browser-extension/chrome-extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Atcoder Companion",
"description": "Enhance your experience by providing some useful features designed to streamline your workflow and boost your productivity.",
"version": "0.1.9",
"version": "0.2.0",
"action": {
"default_popup": "index.html",
"default_icon": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PredictedVirtualStandingTable extends StandingTable {
this.virtualStandings = virtualStandings;
this.standings = standings;
this.rank2Perf = rank2Perf;
this.result = this.calPerfAndRating();
this.calPerfAndRating();
this.fillDataToColumns();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ExtendedStandingTable extends StandingTable {
this.extendedStandings = extendedStandings;
this.finalStandings = finalStandings;
this.calPerfAndRating();
this.correctPerformance();
this.fillDataToColumns();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class FixedStandingTable extends StandingTable {
this.fixedResult = fixedResult;
this.rank2Perf = rank2Perf;
this.calPerfAndRating();
this.correctPerformance();
this.fillDataToColumns();
}

calPerfAndRating() {
this.correctPerformance();
this.addRatedRankToStandings();

this.perfRatingData = new Map(); // map of {username: DataObject{}}
Expand Down Expand Up @@ -66,37 +66,6 @@ class FixedStandingTable extends StandingTable {
}
}
}

// Correct data - the lower rank users should have lower performance
let curPerf = 5000;
for (let i = 0; i < this.standings.StandingsData.length; i++) {
const userScreenName = this.standings.StandingsData[i].UserScreenName;
const userData = this.perfRatingData.get(userScreenName);
if (userData.performance > curPerf) {
userData.performance = curPerf;
} else {
curPerf = userData.performance;
}
}
}

/*
* Correct input data
* Check https://atcoder.jp/contests/wtf22-day1-open/standings/ rank 271
* Many people with same rank but not same performance
*/
correctPerformance() {
let rank2Perf = new Map();
for (let i = 0; i < this.fixedResult.length; i++) {
if (!rank2Perf.has(this.fixedResult[i].Place)) {
rank2Perf.set(this.fixedResult[i].Place, this.fixedResult[i].Performance);
} else {
rank2Perf.set(this.fixedResult[i].Place, Math.max(this.fixedResult[i].Performance, rank2Perf.get(this.fixedResult[i].Place)));
}
}
for (let i = 0; i < this.fixedResult.length; i++) {
this.fixedResult[i].Performance = rank2Perf.get(this.fixedResult[i].Place);
}
}

addRatedRankToStandings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ const USER_SETTINGS = {

const fixedResult = await contest.fetchFinalResultFromAtcoder();
if (isVirtualStandingPage()) {
const standings = await contest.fetchStandingFromAtcoder();
if (fixedResult.length > 0) {
const standings = await contest.fetchStandingFromAtcoder();
// https://img.atcoder.jp/public/a68b1c6/js/standings.js
const virtualStandings = (vueStandings && vueStandings.hasOwnProperty('standings')) ? vueStandings.standings : (await contest.fetchVirtualStandingFromAtcoder());
new VirtualStandingTable(virtualStandings, standings, fixedResult);
} else {
// Estimate perf on the virtual standing page without the final result from Atcoder
const rank2Perf = await contest.fetchPredictedPerfArr();
const standings = await contest.fetchStandingFromAtcoder();
const virtualStandings = (vueStandings && vueStandings.hasOwnProperty('standings')) ? vueStandings.standings : (await contest.fetchVirtualStandingFromAtcoder());
new PredictedVirtualStandingTable(virtualStandings, standings, rank2Perf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ class StandingTable {
this.observer.disconnect();

const displayingUsers = this.getDisplayingUserList();
const data = displayingUsers.map((userScreenName) => {
return this.perfRatingData.get(userScreenName);
});
const data = displayingUsers.map(userScreenName => this.perfRatingData.get(userScreenName));
const trows = this._table.querySelector('tbody').querySelectorAll('tr');

// Remove old cells
document.querySelectorAll('.ext-added').forEach(e => e.remove());

// Add cells with new data
for (let i = 0; i < trows.length - 2; i++) {
const confident = (data[i]?.confident === false) ? false: true;
let performanceSpan = data[i]?.performance ? Color.performance(data[i].performance): '-';
if (!confident)
performanceSpan += '*';

trows[i].insertAdjacentHTML('beforeend', `<td class="standings-result ext-added"><p ${confident ? '': 'title="not sure"'}>${performanceSpan}</p></td>`);
const confident = (data[i]?.confident === false) ? false : true;

const performanceSpan = (data[i]?.performance ? Color.performance(data[i].performance) : '-') + (confident ? '' : '*');
trows[i].insertAdjacentHTML('beforeend', `<td class="standings-result ext-added"><p ${confident ? '' : 'title="not sure"'}>${performanceSpan}</p></td>`);

const diffSpan = data[i]?.isRated ? Color.diff(data[i].newRating - data[i].oldRating) : '-';
trows[i].insertAdjacentHTML('beforeend', `<td class="standings-result ext-added"><p>${diffSpan}</p></td>`);
Expand All @@ -45,6 +41,21 @@ class StandingTable {
this.observer.observe(this._table, { childList: true, subtree: true });
}

/**
* Correct data - the lower rank users should have lower performance
* Check the bottom users
* https://atcoder.jp/contests/wtf22-day1-open/standings/
* https://atcoder.jp/contests/ahc035/standings/extended
* Many people with same rank but not same performance
*/
correctPerformance() {
let maxPerf = 5000;
this.perfRatingData.forEach((data, user) => {
maxPerf = Math.min(maxPerf, data.performance);
data.performance = maxPerf;
});
}

/**
* Add columns for performance, diff, color change
*/
Expand Down

0 comments on commit 1d7b5fc

Please sign in to comment.