Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix winrate updating #180

Merged
merged 2 commits into from Jun 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions classes/dbutils.js
Expand Up @@ -7,6 +7,16 @@ const {

const cache_matches = new Cacheman("matches", { ttl: "1y" });

function _update_winrate(matches) {
matches.forEach(match => {
match.SPRT = SPRT(match.network1_wins, match.network1_losses);
if (match.SPRT === null) {
match.SPRT = Math.round(100 * (2.9444389791664403 + LLR(match.network1_wins, match.network1_losses, 0, 35)) / 5.88887795833);
}
match.winrate = (match.network1_wins && match.network1_wins * 100 / (match.network1_wins + match.network1_losses)).toFixed(2);
});
}

async function get_matches_from_db(db, { limit = 100, network } = {}) {
const matches = await db.collection("matches")
.aggregate([
Expand All @@ -27,12 +37,8 @@ async function get_matches_from_db(db, { limit = 100, network } = {}) {

matches.forEach(match => {
match.time = match._id.getTimestamp().getTime();
match.SPRT = SPRT(match.network1_wins, match.network1_losses);
if (match.SPRT === null) {
match.SPRT = Math.round(100 * (2.9444389791664403 + LLR(match.network1_wins, match.network1_losses, 0, 35)) / 5.88887795833);
}
match.winrate = (match.network1_wins && match.network1_wins * 100 / (match.network1_wins + match.network1_losses)).toFixed(2);
});
_update_winrate(matches);

return matches;
}
Expand All @@ -52,6 +58,7 @@ async function update_matches_stats_cache(db, match_id, is_network1_win) {
} else {
match.network1_losses += 1;
}
_update_winrate(matches.slice(0, 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The match being updated isn't always the first match. Probably could just pass in [match]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

cache_matches.set("matches", matches);
}

Expand Down