Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ <h3>Introduction</h3>
<h3>Method</h3>
<p>
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:
</p>
<!--Potentially, we will take the most popular comments.-->
<p>
NLP
<p class="indent">
Expand Down
26 changes: 15 additions & 11 deletions client/js/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -58,6 +59,8 @@ 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);
Expand Down Expand Up @@ -138,8 +141,9 @@ function createCard(id, name, channel) {
*/
function renderComments(array) {
const totalComments = Math.min(COMMENT_TO_STOP_AT, array.length);

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);
Expand Down Expand Up @@ -341,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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,13 +79,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse res)
HashMap<String, String> perspectiveMap = analyzeWithPerspective(cumulativeComments);

HashMap<NLPResult, Integer> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
public class VideoAnalysis implements Serializable {
public final HashMap<String, String> perspectiveMap;
public final NLPResult magnitudeAndScore;
public final ArrayList<String> commentArray;
public final ArrayList<Comment> commentArray;
public final String videoId;
public final VideoInfo videoInfo;

public VideoAnalysis(
HashMap<String, String> perspectiveMap,
NLPResult magnitudeAndScore,
ArrayList<String> commentArray,
ArrayList<Comment> commentArray,
String videoId,
VideoInfo videoInfo) {
this.perspectiveMap = perspectiveMap;
Expand Down