<commit_before>/* global saveAs, Uint8Array */

'use strict';

/***************************************************************
 *
 * Interface for generating session key and initiating a new
 * session.
 *
 */

var analyst = (function () {

  function checkStatus(session, password) {
    if (!session || session.trim() === '' || !password) {
      return $.Deferred().reject();
    }

    return $.ajax({
      type: 'POST',
      url: '/fetch_status',
      contentType: 'application/json',
      data: JSON.stringify({session: session})
    }).then(function (resp) {
      return resp;
    }).catch(function () {
      alert('error');
    });
  }

  function changeStatus(session, password, status) {
    if (status === 'START' || status === 'PAUSE' || status === 'STOP') {
      return $.ajax({
        type: 'POST',
        url: '/change_status',
        contentType: 'application/json',
        data: JSON.stringify({status: status, session: session, password: password})
      }).then(function (resp) {
        return status;
      }).catch(function () {
        alert('error');
      });
    } else {
      // TODO add better error reporting
      alert('Error Not a valid Session Status');
      //console.log('Error Not a valid Session Status');
    }
  }

  function formatUrls(urls) {
    var baseUrl = window.location.protocol + '//' + window.location.hostname + ':' + window.location.port;

    var result = [];
    for (var i = 0; i < urls.length; i++) {
      result.push(baseUrl + urls[i]);
    }

    return result;
  }

  function generateUrls(session, password, count) {
    return $.ajax({
      type: 'POST',
      url: '/generate_client_urls',
      contentType: 'application/json',
      data: JSON.stringify({count: count, session: session, password: password})
    })
      .then(function (resp) {
        return formatUrls(resp.result);<commit_msg>Fix URL generation without port<commit_after>/* global saveAs, Uint8Array */

'use strict';

/***************************************************************
 *
 * Interface for generating session key and initiating a new
 * session.
 *
 */

var analyst = (function () {

  function checkStatus(session, password) {
    if (!session || session.trim() === '' || !password) {
      return $.Deferred().reject();
    }

    return $.ajax({
      type: 'POST',
      url: '/fetch_status',
      contentType: 'application/json',
      data: JSON.stringify({session: session})
    }).then(function (resp) {
      return resp;
    }).catch(function () {
      alert('error');
    });
  }

  function changeStatus(session, password, status) {
    if (status === 'START' || status === 'PAUSE' || status === 'STOP') {
      return $.ajax({
        type: 'POST',
        url: '/change_status',
        contentType: 'application/json',
        data: JSON.stringify({status: status, session: session, password: password})
      }).then(function (resp) {
        return status;
      }).catch(function () {
        alert('error');
      });
    } else {
      // TODO add better error reporting
      alert('Error Not a valid Session Status');
      //console.log('Error Not a valid Session Status');
    }
  }

  function formatUrls(urls) {
    var port = window.location.port ? ':' + window.location.port : '';
    var baseUrl = window.location.protocol + '//' + window.location.hostname + port;

    var result = [];
    for (var i = 0; i < urls.length; i++) {
      result.push(baseUrl + urls[i]);
    }

    return result;
  }

  function generateUrls(session, password, count) {
    return $.ajax({
      type: 'POST',
      url: '/generate_client_urls',
      contentType: 'application/json',
      data: JSON.stringify({count: count, session: session, password: password})
    })
      .then(function (resp) {
        return formatUrls(resp.result);
{'fraction_non_alphanumeric': 0.18800733176224144, 'fraction_numerical': 0.0010473946059177796, 'mean_word_length': 2.7195715676728334, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1173455', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1078, 'n_words': 283}