<commit_before>$(document).ready(function() {
  structDataForTable = structData.map((el) => {
    el.title = el.title.replace(/(\d)+ - /, '');
    if (el.ratio.toString().length > 6) { el.ratio = el.ratio.toPrecision(5); }
    if (el.words_per_sentence.toString().length > 6) { el.words_per_sentence = el.words_per_sentence.toPrecision(5); }
    if (el.lines_per_stanza.toString().length > 6) { el.lines_per_stanza = el.lines_per_stanza.toPrecision(5); }
    if (el.words_per_stanza.toString().length > 6) { el.words_per_stanza = el.words_per_stanza.toPrecision(5); }
    if (el.words_per_line.toString().length > 6) { el.words_per_line = el.words_per_line.toPrecision(5); }
    return Object.values(el);
  });

  corpusWordCount = corpusWordCount.map((el) => {
    return Object.values(el);
  });

  $('#wordFreqTable').DataTable( {
    data: corpusWordCount,
    columns: [{title: "Term"}, {title: "Count"}]
  });

  $('#structureTable').DataTable( {
    data: structDataForTable,
    columns: [
        { title: "Title" },
        { title: "Words" },
        { title: "Types" },
        { title: "Ratio" },
        { title: "Words/Sentence" },
        { title: "Collection" },
        { title: "Year Published" },
        { title: "Stanzas" },
        { title: "Lines" },
        { title: "Lines/Stanza" },
        { title: "Words/Stanza" },
        { title: "Words/Line" },
    ]
  });

  let theRoadNotTaken = structData.find(function(o) { return o.title == "The Road Not Taken"; });

  let sort_by = function(field, reverse, primer){
    var key = primer ?
       function(x) {return primer(x[field])} :
       function(x) {return x[field]};
    reverse = !reverse ? 1 : -1;
    return function (a, b) {
      return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
    }
  };

  function generateData(property, reverse, primer, limit) {
    subject = { label: theRoadNotTaken.title, value: theRoadNotTaken[property.toString()]};
    v = structData.sort(sort_by(property, reverse, primer));
    v = v.slice(0, limit);
    v = v.map((e)=>{
      return {
        label: e.title,
        value: e[property.toString()]
      };
    });
    let exists = v.find(function(o) { return o.title == "The Road Not Taken"; });
    if (exists === undefined) {
      v.unshift(subject);
    }
    return [
      {
        key: property.toString(),
        values: v
      }
    ];
  }

  function generateSentimentData(frostData) {
    let f = frostData.sort(sort_by("year_published", false, parseInt));
    let sentimentScores = f.map((el) => {
      return {
        label: el.title,
        value: el.sentiment.document.score
      };
    });
    return [
      {
        key: "Sentiment Score",
        values: sentimentScores
      }
    ];
  }

  nv.addGraph(function() {
    let structureChart = nv.models.discreteBarChart()
      .x(function(d) { return d.label })    //Specify the data accessors.
      .y(function(d) { return d.value })
      .staggerLabels(true)    //Too many bars and not enough room? Try staggering labels.
      .showValues(false);      //...instead, show the bar value right on top of each bar.
    let structureChartData = d3.select('#structure-d3 svg');
    structureChartData.datum(generateData('lines', false, parseFloat, 5))
        .transition().duration(500)
        .call(structureChart);
    nv.utils.windowResize(structureChart.update);
    return structureChart;
  });

  nv.addGraph(function() {
    let sentimentChart = nv.models.discreteBarChart()
      .x(function(d) { return d.label })    //Specify the data accessors.
      .y(function(d) { return d.value })
      .staggerLabels(true)    //Too many bars and not enough room? Try staggering labels.
      .showValues(false)      //...instead, show the bar value right on top of each bar.
      .showXAxis(false);
    sentimentChart.yAxis.tickFormat((d3.format('.3f')))
    let sentimentChartData = d3.select('#sentiment-d3 svg');
    sentimentChartData.datum(generateSentimentData(frostData))
        .transition().duration(500)
        .call(sentimentChart);
    nv.utils.windowResize(sentimentChart.update);
    return sentimentChart;
  });

  function update(property, reverse, primer, limit) {
    nv.addGraph(function() {
      let structureChart = nv.models.discreteBarChart()
        .x(function(d) { return d.label })    //Specify the data accessors.
        .y(function(d) { return d.value })
        .staggerLabels(true)    //Too many bars and not enough room? Try staggering labels.<commit_msg>Fixed the sentiment graph<commit_after>$(document).ready(function() {
  structDataForTable = structData.map((el) => {
    el.title = el.title.replace(/(\d)+ - /, '');
    if (el.ratio.toString().length > 6) { el.ratio = el.ratio.toPrecision(5); }
    if (el.words_per_sentence.toString().length > 6) { el.words_per_sentence = el.words_per_sentence.toPrecision(5); }
    if (el.lines_per_stanza.toString().length > 6) { el.lines_per_stanza = el.lines_per_stanza.toPrecision(5); }
    if (el.words_per_stanza.toString().length > 6) { el.words_per_stanza = el.words_per_stanza.toPrecision(5); }
    if (el.words_per_line.toString().length > 6) { el.words_per_line = el.words_per_line.toPrecision(5); }
    return Object.values(el);
  });

  frostData = frostData.map((el) => {
    let year_published = el.title.split('-')[0].trim();
    return Object.assign({year_published: year_published}, el);
  });

  corpusWordCount = corpusWordCount.map((el) => {
    return Object.values(el);
  });

  $('#wordFreqTable').DataTable( {
    data: corpusWordCount,
    columns: [{title: "Term"}, {title: "Count"}]
  });

  $('#structureTable').DataTable( {
    data: structDataForTable,
    columns: [
        { title: "Title" },
        { title: "Words" },
        { title: "Types" },
        { title: "Ratio" },
        { title: "Words/Sentence" },
        { title: "Collection" },
        { title: "Year Published" },
        { title: "Stanzas" },
        { title: "Lines" },
        { title: "Lines/Stanza" },
        { title: "Words/Stanza" },
        { title: "Words/Line" },
    ]
  });

  let theRoadNotTaken = structData.find(function(o) { return o.title == "The Road Not Taken"; });

  let sort_by = function(field, reverse, primer){
    var key = primer ?
       function(x) {return primer(x[field])} :
       function(x) {return x[field]};
    reverse = !reverse ? 1 : -1;
    return function (a, b) {
      return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
    }
  };

  function generateData(property, reverse, primer, limit) {
    subject = { label: theRoadNotTaken.title, value: theRoadNotTaken[property.toString()]};
    v = structData.sort(sort_by(property, reverse, primer));
    v = v.slice(0, limit);
    v = v.map((e)=>{
      return {
        label: e.title,
        value: e[property.toString()]
      };
    });
    let exists = v.find(function(o) { return o.title == "The Road Not Taken"; });
    if (exists === undefined) {
      v.unshift(subject);
    }
    return [
      {
        key: property.toString(),
        values: v
      }
    ];
  }

  function generateSentimentData() {
    let f = frostData.sort(sort_by("year_published", false, parseInt));
    let sentimentScores = f.map((el) => {
      return {
        label: el.title,
        value: el.sentiment.document.score
      };
    });
    return [
      {
        key: "Sentiment Score",
        values: sentimentScores
      }
    ];
  }

  nv.addGraph(function() {
    let structureChart = nv.models.discreteBarChart()
      .x(function(d) { return d.label })    //Specify the data accessors.
      .y(function(d) { return d.value })
      .staggerLabels(true)    //Too many bars and not enough room? Try staggering labels.
      .showValues(false);      //...instead, show the bar value right on top of each bar.
    let structureChartData = d3.select('#structure-d3 svg');
    structureChartData.datum(generateData('lines', false, parseFloat, 5))
        .transition().duration(500)
        .call(structureChart);
    nv.utils.windowResize(structureChart.update);
    return structureChart;
  });

  nv.addGraph(function() {
    let sentimentChart = nv.models.discreteBarChart()
      .x(function(d) { return d.label })    //Specify the data accessors.
      .y(function(d) { return d.value })
      .staggerLabels(true)    //Too many bars and not enough room? Try staggering labels.
      .showValues(false)      //...instead, show the bar value right on top of each bar.
      .showXAxis(false);
    sentimentChart.yAxis.tickFormat((d3.format('.3f')))
    let sentimentChartData = d3.select('#sentiment-d3 svg');
    sentimentChartData.datum(generateSentimentData())
        .transition().duration(500)
        .call(sentimentChart);
    nv.utils.windowResize(sentimentChart.update);
    return sentimentChart;
  });

  function update(property, reverse, primer, limit) {
    nv.addGraph(function() {
      let structureChart = nv.models.discreteBarChart()
        .x(function(d) { return d.label })    //Specify the data accessors.
        .y(function(d) { return d.value })
        .staggerLabels(true)    //Too many bars and not enough room? Try staggering labels.
{'fraction_non_alphanumeric': 0.1563557010365521, 'fraction_numerical': 0.005782869612656847, 'mean_word_length': 2.770464829288359, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '1722178', 'n_tokens_mistral': 3030, 'n_tokens_neox': 2947, 'n_words': 623}