<commit_before>// Copyright (c) 2013 <NAME> - see LICENSE for further details

// J Resig says this is okay (add methods to built in prototypes, that is)

// Function to get the Max value in Array
Array.max = function( array ){
    return Math.max.apply( Math, array );
};

// Function to get the Min value in Array
Array.min = function( array ){
   return Math.min.apply( Math, array );
};

Array.has = function( array, fn ) {
   for ( i=0 ; i<array.length ; i++) {
      if (fn(array[i]) === true) return true;
   }
   return false;
};

$coverage = function(){};

(function($coverage) {

  $coverage.coverageTable = function coverageTable(log_id, where, name, coverpoint, options) {
    var self    = this;
    var buckets = coverpoint.buckets;
    var axes    = $.extend(true, [], coverpoint.axes);
    var offset  = coverpoint.offset;
    var table;
    options = options || {hide_hits : false, hide_illegal : false, hide_dont_care : false, matrix : false};

    function visible_axes() {
      return axes.reduce(function(sum, it, idx){
        if (it.visible !== false) {
          sum.push(it);
        }
        return sum;
      }, Array());
    }
    function two_axes() {
      return visible_axes().length == 2;
    }

    function permsFromBucket(axes, bucket) {
      if (axes.length == 0) return ""; // terminal case
      var last = axes.slice(-1)[0];
      if (last.visible === false) {
        return permsFromBucket(axes.slice(0, -1), bucket);
      }
      return permsFromBucket(axes.slice(0, -1), Math.floor(bucket/last.values.length))+"<td>"+last.values[bucket % last.values.length]+"</td>";
    }

    function axisIdxs(bucket, axesSlice) {
      axesSlice = axesSlice || axes;
      if (axesSlice.length == 0) return []; // terminal case
      var last = axesSlice.slice(-1)[0];
      return axisIdxs(Math.floor(bucket/last.values.length), axesSlice.slice(0,-1)).concat([[bucket % last.values.length, last.values.length]]);
    }

    function bucketIdx(axisIdxs) {
      var cumul = 1;
      return axisIdxs.reduceRight(function(p, c, idx) {
        if (axes[idx].visible === false) return p;
        var result = p + c[0]*cumul;
        cumul *= c[1];
        return result;
      }, 0);
    }

    function showBucket(node) {
      var bucket_id = parseInt(node.attr('bkt'));
      var bucket    = buckets[bucket_id];
      var url       = '/bkt/' + log_id + '/';
      if (bucket.length < 3) {
        url += (bucket_id + offset);
      } else {
        url += bucket[2].map(function(bkt){return bkt+offset}).join(',');
      }
      node.html(function(){
        return '<a class="popup">' + $(this).text() + '<span id="hits-' + bucket_id + '" title="hit details for ' + log_id + '/' + bucket_id + '"></span></a>';
      });
      $.getJSON(url, function(data) {
        $('span', node).html(function() {
          if (data.length) {
            return $('<table/>', {
              class : 'bucket',
              html : '<tbody>'+data.slice(0,10).map(function(it){
                return '<tr class="'+coverageTable.classFromBucket([bucket[0], it.hits])+'"><td>'+it.log_id+'</td><td>'+it.hits+'</td></tr>';
              })+'</tbody>'
            });
          } else {
            return $('<i/>', {html : 'no hits'});
          }
  	});
      });
      node.unbind('mouseenter.coverage'); // don't do again
      node.bind('click.coverage', function(){
        $('span', node).clone().dialog();
      });
    }

    function updateVisible() {
      $('th.axis.selected', where).each(function(idx, node){<commit_msg>use datatables for hit table in dialog<commit_after>// Copyright (c) 2013 <NAME> - see LICENSE for further details

// <NAME> says this is okay (add methods to built in prototypes, that is)

// Function to get the Max value in Array
Array.max = function( array ){
    return Math.max.apply( Math, array );
};

// Function to get the Min value in Array
Array.min = function( array ){
   return Math.min.apply( Math, array );
};

Array.has = function( array, fn ) {
   for ( i=0 ; i<array.length ; i++) {
      if (fn(array[i]) === true) return true;
   }
   return false;
};

$coverage = function(){};

(function($coverage) {

  $coverage.coverageTable = function coverageTable(log_id, where, name, coverpoint, options) {
    var self    = this;
    var buckets = coverpoint.buckets;
    var axes    = $.extend(true, [], coverpoint.axes);
    var offset  = coverpoint.offset;
    var table;
    options = options || {hide_hits : false, hide_illegal : false, hide_dont_care : false, matrix : false};

    function visible_axes() {
      return axes.reduce(function(sum, it, idx){
        if (it.visible !== false) {
          sum.push(it);
        }
        return sum;
      }, Array());
    }
    function two_axes() {
      return visible_axes().length == 2;
    }

    function permsFromBucket(axes, bucket) {
      if (axes.length == 0) return ""; // terminal case
      var last = axes.slice(-1)[0];
      if (last.visible === false) {
        return permsFromBucket(axes.slice(0, -1), bucket);
      }
      return permsFromBucket(axes.slice(0, -1), Math.floor(bucket/last.values.length))+"<td>"+last.values[bucket % last.values.length]+"</td>";
    }

    function axisIdxs(bucket, axesSlice) {
      axesSlice = axesSlice || axes;
      if (axesSlice.length == 0) return []; // terminal case
      var last = axesSlice.slice(-1)[0];
      return axisIdxs(Math.floor(bucket/last.values.length), axesSlice.slice(0,-1)).concat([[bucket % last.values.length, last.values.length]]);
    }

    function bucketIdx(axisIdxs) {
      var cumul = 1;
      return axisIdxs.reduceRight(function(p, c, idx) {
        if (axes[idx].visible === false) return p;
        var result = p + c[0]*cumul;
        cumul *= c[1];
        return result;
      }, 0);
    }

    function showDialog(event) {
      // create table of all hits in a dialog popup
      var container = $('<div><div><table/></div></div>');
      var table = $('table', container).dataTable({
        "bJQueryUI": true,
        "bFilter": false,
        "aoColumns": [
  	  { "sTitle": "log id" },
	  { "sTitle": "hits" }
        ],
        "aaData" : event.data.coverage.map(function(hit){return [hit.log_id, hit.hits]}),
        "aaSorting": [[1, "desc"]], // sort hits descending
        "aLengthMenu": [[10, 25, 50, 100 , -1], [10, 25, 50, 100, "All"]],
        "iDisplayLength": 10,
        "fnCreatedRow": function(nRow, aData, iDisplayIndex) {
          $(nRow).addClass(coverageTable.classFromBucket([event.data.goal, aData[1]]));
        }
      });
      container.bind('mousewheel', function(event) {
        var oSettings = table.fnSettings();
        if (event.originalEvent.wheelDelta/120 < 0) {
          if (oSettings._iDisplayStart >= (oSettings.aoData.length - oSettings._iDisplayLength)) {
            return false;
          }
          oSettings.iInitDisplayStart = oSettings._iDisplayStart + 1;
        } else {
          if (oSettings._iDisplayStart < 1) {
            return false;
          }
          oSettings.iInitDisplayStart = oSettings._iDisplayStart - 1;
        }
        table.fnDraw();
        return false;
      });
      container.dialog();
    }

    function showBucket(node) {
      var bucket_id = parseInt(node.attr('bkt'));
      var bucket    = buckets[bucket_id];
      var goal      = bucket[0];
      var url       = '/bkt/' + log_id + '/';
      if (bucket.length < 3) {
        url += (bucket_id + offset);
      } else {
        url += bucket[2].map(function(bkt){return bkt+offset}).join(',');
      }
      node.html(function(){
        return '<a class="popup">' + $(this).text() + '<span id="hits-' + bucket_id + '" title="hit details for ' + log_id + '/' + bucket_id + '"></span></a>';
      });
      $.getJSON(url, function(data) {
        $('span', node).html(function() {
          if (data.length) {
            node.bind('click.coverage', {coverage:data, goal:goal}, showDialog);
            return $('<table/>', {
              class : 'bucket',
              html : '<tbody>'+data.slice(0,10).map(function(it){
                return '<tr class="'+coverageTable.classFromBucket([goal, it.hits])+'"><td>'+it.log_id+'</td><td>'+it.hits+'</td></tr>';
              })+'</tbody>'
            });
          } else {
            return $('<i/>', {html : 'no hits'});
          }
  	});
      });
      node.unbind('mouseenter.coverage'); // don't do again
    }

    function updateVisible() {
      $('th.axis.selected', where).each(function(idx, node){
{'fraction_non_alphanumeric': 0.1729437991317611, 'fraction_numerical': 0.010090343775665846, 'mean_word_length': 2.4150641025641026, 'pattern_counts': {'":': 9, '<': 49, '<?xml version=': 0, '>': 44, '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': '477782', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2676, 'n_words': 616}