From c2f2cbbc7ab146823ca53118b6b994f32ce3d7a0 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 7 Aug 2020 17:52:35 +0000 Subject: [PATCH 1/4] fixed merge bugs, fixed naming, and others --- client/analysis.html | 7 ++++--- client/js/analysis.js | 7 +++++-- .../com/google/musicanalysis/site/AnalysisServlet.java | 7 ++++--- .../java/com/google/musicanalysis/types/VideoAnalysis.java | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/client/analysis.html b/client/analysis.html index e48afcee..91f08cf8 100644 --- a/client/analysis.html +++ b/client/analysis.html @@ -41,9 +41,10 @@

Introduction

Method

In order to ensure the most accurate analysis while handling the minimum amount - of data, this tool takes 20 random comments from the Youtube API, aggregates them - into a single string of sentences, and runs the chunk through both the NLP and - Perspective APIs. Here is what each API is responsible for: + of data, this tool takes the 20 most relevant comments from the Youtube API, + weights each comment based off of the number of likes it receives, then creates + an overall score proportional to the number of likes. + Here is what each API is responsible for:

diff --git a/client/js/analysis.js b/client/js/analysis.js index c88c0414..65dd25a1 100644 --- a/client/js/analysis.js +++ b/client/js/analysis.js @@ -58,7 +58,9 @@ function renderingHandler(videoAnalysis) { const charts = document.getElementById('charts'); const list = document.getElementById('list'); const card = document.getElementById('videocard-wrapper'); - + const featuredComments = document.getElementById('commentHeader'); + featuredComments.classList.remove('hidden'); + removeAllChildNodes(charts); removeAllChildNodes(list); removeAllChildNodes(card); @@ -138,8 +140,9 @@ function createCard(id, name, channel) { */ function renderComments(array) { const totalComments = Math.min(COMMENT_TO_STOP_AT, array.length); + console.log(array); for (let i = 0; i < totalComments; i++) { - const filteredValue = array[i].comment.replace('\n/g', ' -- '); + const filteredValue = array[i].text.replace('\n/g', ' -- '); setTimeout(() => { addListElement(filteredValue); }, (i+1) * COMMENT_APPEARANCE_TIME); diff --git a/server/src/main/java/com/google/musicanalysis/site/AnalysisServlet.java b/server/src/main/java/com/google/musicanalysis/site/AnalysisServlet.java index 22213f2d..c6a283a0 100644 --- a/server/src/main/java/com/google/musicanalysis/site/AnalysisServlet.java +++ b/server/src/main/java/com/google/musicanalysis/site/AnalysisServlet.java @@ -41,6 +41,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) commentArgs.put("part", "snippet"); commentArgs.put("videoId", userInput); + commentArgs.put("order", "relevance"); String commentsJson; // Runs input through the cache first @@ -78,13 +79,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res) HashMap perspectiveMap = analyzeWithPerspective(cumulativeComments); HashMap unweightedNLPMap = new HashMap<>(); - for (CommentLikes commentAndLikes: commentArray) { - unweightedNLPMap.put(analyzeWithNLP(commentAndLikes.comment), commentAndLikes.likes); + for (Comment comment: commentArray) { + unweightedNLPMap.put(analyzeWithNLP(comment.text), comment.likes); } NLPResult weightedSentiment = createWeightedSentiment(unweightedNLPMap); VideoAnalysis servletResults = - new VideoAnalysis(perspectiveMap, commentsSentiment, commentArray, videoId, videoInfo); + new VideoAnalysis(perspectiveMap, weightedSentiment, commentArray, videoId, videoInfo); // Only add to the cache if the video is more than 10 days old, // and there are at least 20 comments diff --git a/server/src/main/java/com/google/musicanalysis/types/VideoAnalysis.java b/server/src/main/java/com/google/musicanalysis/types/VideoAnalysis.java index f86ce1c5..69bb72c3 100644 --- a/server/src/main/java/com/google/musicanalysis/types/VideoAnalysis.java +++ b/server/src/main/java/com/google/musicanalysis/types/VideoAnalysis.java @@ -11,14 +11,14 @@ public class VideoAnalysis implements Serializable { public final HashMap perspectiveMap; public final NLPResult magnitudeAndScore; - public final ArrayList commentArray; + public final ArrayList commentArray; public final String videoId; public final VideoInfo videoInfo; public VideoAnalysis( HashMap perspectiveMap, NLPResult magnitudeAndScore, - ArrayList commentArray, + ArrayList commentArray, String videoId, VideoInfo videoInfo) { this.perspectiveMap = perspectiveMap; From 8e3c4fc51f1f3951d1a40453dcb770ab1e47e428 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 7 Aug 2020 17:54:13 +0000 Subject: [PATCH 2/4] removed debug --- client/js/analysis.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/js/analysis.js b/client/js/analysis.js index 65dd25a1..c84f7c7a 100644 --- a/client/js/analysis.js +++ b/client/js/analysis.js @@ -60,7 +60,7 @@ function renderingHandler(videoAnalysis) { const card = document.getElementById('videocard-wrapper'); const featuredComments = document.getElementById('commentHeader'); featuredComments.classList.remove('hidden'); - + removeAllChildNodes(charts); removeAllChildNodes(list); removeAllChildNodes(card); @@ -140,7 +140,7 @@ function createCard(id, name, channel) { */ function renderComments(array) { const totalComments = Math.min(COMMENT_TO_STOP_AT, array.length); - console.log(array); + for (let i = 0; i < totalComments; i++) { const filteredValue = array[i].text.replace('\n/g', ' -- '); setTimeout(() => { From b1daaa15051a299a0d9eae76e00ff63561bc7f84 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 7 Aug 2020 17:57:45 +0000 Subject: [PATCH 3/4] fixed lint --- client/js/analysis.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/client/js/analysis.js b/client/js/analysis.js index c84f7c7a..e88b8f5d 100644 --- a/client/js/analysis.js +++ b/client/js/analysis.js @@ -9,7 +9,7 @@ const TEN_MINUTES_IN_SECONDS = 60 * 10; * We only want to pull from the client-side cache if two requests * are made within 10 mins of eachother. */ -var siteHeaders = new Headers(); +const siteHeaders = new Headers(); siteHeaders.set('Cache-control', `max-age=${TEN_MINUTES_IN_SECONDS}`); /* global getData */ @@ -41,7 +41,8 @@ async function fetchResponse() { if (response) { if (response.status == 500) { // This will hit when comments are disabled for the video. - alert('The video you selected is incompatible with this tool. Please try again.'); + alert(`The video you selected is incompatible with this tool. + Please try again.`); return; } renderingHandler(response); @@ -344,11 +345,11 @@ function shakeSearchBar() { /** * Sets a cooldown period for the submit button - */ - function buttonCoolDown() { - buttonElement = document.getElementById('sendbutton'); - buttonElement.disabled = true; - setTimeout(() => { - buttonElement.disabled = false; - }, COOLDOWN_TIME); - } + */ +function buttonCoolDown() { + const buttonElement = document.getElementById('sendbutton'); + buttonElement.disabled = true; + setTimeout(() => { + buttonElement.disabled = false; + }, COOLDOWN_TIME); +} From 5dde6bf0862fe1ffbf5bf7ac6454baf0e11ac2d2 Mon Sep 17 00:00:00 2001 From: Seun Date: Fri, 7 Aug 2020 17:59:04 +0000 Subject: [PATCH 4/4] removed comment --- client/analysis.html | 1 - 1 file changed, 1 deletion(-) diff --git a/client/analysis.html b/client/analysis.html index 91f08cf8..515ee25a 100644 --- a/client/analysis.html +++ b/client/analysis.html @@ -46,7 +46,6 @@

Method

an overall score proportional to the number of likes. Here is what each API is responsible for:

-

NLP