From 412a77d7c8dfbba5268745c9e1f8ba3157baa676 Mon Sep 17 00:00:00 2001 From: BreadFish64 Date: Sun, 18 Mar 2018 20:22:51 -0500 Subject: [PATCH] Display weighted average of compatibility submissions (#78) --- scripts/games/app.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/games/app.js b/scripts/games/app.js index 7fcdbd4..1d1d721 100644 --- a/scripts/games/app.js +++ b/scripts/games/app.js @@ -179,7 +179,19 @@ function processGame(game) { model.testcase_date = "2000-01-01"; } else { let recent = model.testcases[0]; - model.compatibility = recent.compatibility; + // The displayed compatibility rating is an weighted arithmetic mean of the submitted ratings. + let numerator = 0; + let denominator = 0; + model.testcases.forEach(testcase => { + // Build date is a better metric but testcases from the TOML files only have a submission date. + let weigh_date = new Date(testcase.buildDate == undefined ? testcase.date : testcase.buildDate); + // The test case is weighted on an exponential decay curve such that a test case is half as relevant as each month (30 days) passes. + // The exponent is obtained by dividing the time in millisecond between the current date and date of testing by the number of milliseconds in 30 days (but negative because it's a decay). + let weight = Math.pow(.5, (currentDate - weigh_date) / -(30 * 1000 * 3600 * 24)); + numerator += testcase.compatibility * weight; + denominator += weight; + }); + model.compatibility = Math.round(numerator / denominator).toString(); model.testcase_date = recent.date; }