From 8290c9e1f483845f74f37bca587bbaaa0d76f608 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 30 Apr 2020 18:39:03 -0400 Subject: [PATCH] Added new NB overlapping code --- src/routes/postSkipSegments.js | 14 +++++++------- test/cases/postSkipSegments.js | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/routes/postSkipSegments.js b/src/routes/postSkipSegments.js index e18af9b..a41bebd 100644 --- a/src/routes/postSkipSegments.js +++ b/src/routes/postSkipSegments.js @@ -118,15 +118,15 @@ async function autoModerateSubmission(submission, callback) { let nbPredictions = await response.json(); for (const nbSegment of nbPredictions.sponsorSegments) { - // The submission needs to be a subset of the widened NB prediction - // and at least 65% of NB's prediction. - if (nbSegment[0] - 2 <= submission.startTime && submission.endTime <= nbSegment[1] + 2){ - if ((submission.endTime - submission.startTime) / (nbSegment[1]-nbSegment[0]) >= 0.65){ - overlap = true; - break; - } + // The submission needs to be similar to the NB prediction by 65% or off by less than 7 seconds + // This calculated how off it is + let offAmount = Math.abs(nbSegment[0] - submission.startTime) + Math.abs(nbSegment[1] - submission.endTime); + if (offAmount / (nbSegment[1] - nbSegment[0]) <= 0.45 || offAmount <= 7) { + overlap = true; + break; } } + if (overlap) { return false; } else{ diff --git a/test/cases/postSkipSegments.js b/test/cases/postSkipSegments.js index e524e01..c6b7eec 100644 --- a/test/cases/postSkipSegments.js +++ b/test/cases/postSkipSegments.js @@ -100,7 +100,7 @@ describe('postSkipSegments', () => { }); }); - it('Should be *rejected* if there\'s not at least 65% overlap with NB' , (done) => { + it("Should be rejected if there's not at least 65% overlap with NB", (done) => { request.get(utils.getbaseURL() + "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing", null, (err, res, body) => { @@ -110,7 +110,17 @@ describe('postSkipSegments', () => { }); }).timeout(5000); - it('Should be *accepted* if there\'s at least 65% overlap with NB' , (done) => { + it("Should be accepted if only off by 5s", (done) => { + request.get(utils.getbaseURL() + + "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=0&endTime=12&userID=testing", null, + (err, res, body) => { + if (err) done("Couldn't call endpoint"); + else if (res.statusCode === 200) done(); // pass + else done("non 403 status code: " + res.statusCode + " ("+body+")"); + }); + }).timeout(5000); + + it("Should be accepted if there's at least 65% overlap with NB" , (done) => { request.get(utils.getbaseURL() + "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=0&endTime=6&userID=testing", null, (err, res, body) => {