<commit_before>/**
 * fetches youtube api calls from YoutubeServlet.java
 * and displays on youtube-genre.html
 */

const numVideosInput = document.getElementById('numVideos');
const DEFAULT_NUM_VIDS = 10;

/**
 * extracts num vids from input, otherwise returns default
 * helper fn for displayMusicGenre()
 * @returns {number} num videos user wants to retrieve
 */
function getNumVids() {
  const numVids = numVideosInput.value;
  return numVids || DEFAULT_NUM_VIDS;
}

/**
 * fetches genre count hashmap from /api/youtube and updates html
 */
async function displayMusicGenre() {
  const genreBlock = document.getElementById('genres');
  const numVids = getNumVids();
  const response = await fetch(`/api/youtube?num_videos=${numVids}`);
  if (response.status != 200) {
    // redirect to login if there are errors 
    window.location.href = "/api/oauth/login/youtube";
  }
  const genreCount = await response.text();
  genreBlock.innerHTML = genreCount;
}

/**<commit_msg>consistent var names in js and servlet<commit_after>/**
 * fetches youtube api calls from YoutubeServlet.java
 * and displays on youtube-genre.html
 */

const numVideosInput = document.getElementById('numVideos');
const DEFAULT_NUM_VIDS = 10;

/**
 * extracts num vids from input, otherwise returns default
 * helper fn for displayMusicGenre()
 * @returns {number} num videos user wants to retrieve
 */
function getNumVids() {
  const numVideos = numVideosInput.value;
  return numVideos || DEFAULT_NUM_VIDS;
}

/**
 * fetches genre count hashmap from /api/youtube and updates html
 */
async function displayMusicGenre() {
  const genreBlock = document.getElementById('genres');
  const numVideos = getNumVids();
  const response = await fetch(`/api/youtube?num_videos=${numVideos}`);
  if (response.status != 200) {
    // redirect to login if there are errors 
    window.location.href = "/api/oauth/login/youtube";
  }
  const genreCount = await response.text();
  genreBlock.innerHTML = genreCount;
}

/**
{'fraction_non_alphanumeric': 0.1128463476070529, 'fraction_numerical': 0.005037783375314861, 'mean_word_length': 4.353099730458221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3347841', 'n_tokens_mistral': 617, 'n_tokens_neox': 581, 'n_words': 176}