From 3f55bfea22167b9d9635b2e3b6bfec8a9812ef96 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 24 Sep 2019 18:29:06 -0400 Subject: [PATCH 1/4] Added user based time saved endpoint. --- index.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/index.js b/index.js index d3def07..f0d001c 100644 --- a/index.js +++ b/index.js @@ -548,6 +548,37 @@ app.get('/api/getViewsForUser', function (req, res) { }); }); +//Gets all the saved time added up (views * sponsor length) for one userID +//Useful to see how much one user has contributed +//In minutes +app.get('/api/getSavedTimeForUser', function (req, res) { + let userID = req.query.userID; + + if (userID == undefined) { + //invalid request + res.sendStatus(400); + return; + } + + //hash the userID + userID = getHash(userID); + + //up the view count by one + db.prepare("SELECT SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE userID = ?").get(userID, function(err, row) { + if (err) console.log(err); + + console.log(userID) + + if (row.minutesSaved != null) { + res.send({ + timeSaved: row.minutesSaved + }); + } else { + res.sendStatus(404); + } + }); +}); + app.get('/api/getTopUsers', function (req, res) { let sortType = req.query.sortType; From 55a56c3e04b007ba4676100a53ed04c5c1596289 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 24 Sep 2019 18:30:11 -0400 Subject: [PATCH 2/4] Removed log --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index f0d001c..eef91cb 100644 --- a/index.js +++ b/index.js @@ -567,8 +567,6 @@ app.get('/api/getSavedTimeForUser', function (req, res) { db.prepare("SELECT SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE userID = ?").get(userID, function(err, row) { if (err) console.log(err); - console.log(userID) - if (row.minutesSaved != null) { res.send({ timeSaved: row.minutesSaved From a6821209d12ca1bea29b633d0fbd1f818acca24b Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 20 Oct 2019 21:52:25 -0400 Subject: [PATCH 3/4] Fixed weighted random cap not working. Nothing would return if there were more than 4 sponsors. --- index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index eef91cb..8210489 100644 --- a/index.js +++ b/index.js @@ -740,11 +740,9 @@ function getVoteOrganisedSponsorTimes(sponsorTimes, votes, UUIDs) { let voteSums = weightedRandomIndexes.weightSums; //convert these into the votes - for (let i = 0; i < voteSums.length; i++) { - if (voteSums[i] != undefined) { - //it should use the sum of votes, since anyone upvoting a similar sponsor is upvoting the existence of that sponsor. - votes[finalSponsorTimeIndexes[i]] = voteSums; - } + for (let i = 0; i < finalSponsorTimeIndexes.length; i++) { + //it should use the sum of votes, since anyone upvoting a similar sponsor is upvoting the existence of that sponsor. + votes[finalSponsorTimeIndexes[i]] = voteSums[i]; } //find the indexes never dealt with and add them From ffa70d6762f4f6725691dd08ce62f646be0cb792 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sun, 20 Oct 2019 21:53:36 -0400 Subject: [PATCH 4/4] Raised cap to 8 sponsors. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8210489..c43491b 100644 --- a/index.js +++ b/index.js @@ -753,8 +753,8 @@ function getVoteOrganisedSponsorTimes(sponsorTimes, votes, UUIDs) { } //if there are too many indexes, find the best 4 - if (finalSponsorTimeIndexes.length > 4) { - finalSponsorTimeIndexes = getWeightedRandomChoice(finalSponsorTimeIndexes, votes, 4).finalChoices; + if (finalSponsorTimeIndexes.length > 8) { + finalSponsorTimeIndexes = getWeightedRandomChoice(finalSponsorTimeIndexes, votes, 8).finalChoices; } //convert this to a final array to return