<commit_before>/*
  table.js is released under the GNU Affero General Public License.
  See COPYRIGHT.txt and LICENSE.txt.

  Part of the OpenEnergyMonitor project: http://openenergymonitor.org
*/
var table = {
  'data':0,
  'groupshow':{},

  'eventsadded':false,
  'deletedata':true,

  'sortfield':null,
  'sortorder':null,
  'sortable':true,

  'groupprefix':"",

  'timeServerLocalOffset':0, // offset of server to client time in ms

  'draw':function() {
    /*if (table.data && table.sortable) {
      table.data.sort(function(a,b) {
      if(a[table.sortfield]<b[table.sortfield]) return -1;
      if(a[table.sortfield]>b[table.sortfield]) return 1;
      return 0;
      });
    }*/

    if (table.data && table.sortable && table.sortfield) {
      table.data.sort(function(a,b) {
        var x=a[table.sortfield];
        var y=b[table.sortfield];
        if (x===null)x=Number.POSITIVE_INFINITY;
        if (y===null)y=Number.POSITIVE_INFINITY;
        if ((x==true) || (x== false)) x==false? x=0:x=1;
        if ((y==true) || (y== false)) y==false? y=0:y=1;
        if ($.isNumeric(x) && $.isNumeric(y)){
          var numa=parseFloat(x);
          var numb=parseFloat(y);

          if (table.sortorder==1){
            return numa-numb;
          } else {
            return numb-numa;
          }

        } else {
           if (typeof x == 'string') x=x.toUpperCase().replace(" ", "");
           if (typeof y == 'string') y=y.toUpperCase().replace(" ", "");
        }

        if (table.sortorder==1){
          if(x<y) return -1;
          if(x>y) return 1;
          return 0;
        } else{
          if(x>y) return -1;
          if(x<y) return 1;
          return 0;
        }
      });
    }

    var group_num = 0;
    var groups = {};
    for (row in table.data) {
      var group = table.data[row][table.groupby];
      if (!group) group = 'NoGroup';
      if (!groups[group]) {groups[group] = {}; groups[group]['ui_rows'] = ""; groups[group]['rows_id'] = []; group_num++;}
      groups[group]['ui_rows'] += table.draw_row(row);
      groups[group]['rows_id'].push(row);
    }

    var html = "";
    for (group in groups) {
      var visible = '';
      htmlg = "";
      if (group_num>1) {
        var symbol ='<i class="icon-minus-sign"></i>'; 
        if (table.groupshow[group]==undefined) table.groupshow[group]=false; // default is collapsed
        if (table.groupshow[group]==false) {symbol = '<i class="icon-plus-sign"></i>'; visible = "display:none";}
        htmlg += "<tr><th colspan='3'><a class='MINMAX' group='"+group+"' >"+symbol+"</a> "+table.groupprefix+group+"</th>";
        var countFields = 0; for (field in table.fields) countFields++; // Calculate amount of padding required
        if (table.groupfields == undefined) {
          for (i=2; i<countFields-1; i++) htmlg += "<th></th>"; // Add th padding
        } else {
          for (fieldg in table.groupfields) htmlg += "<th group='"+group+"' fieldg='"+fieldg+"' >"+table.fieldtypes[table.groupfields[fieldg].type].draw(group,groups[group]['rows_id'],fieldg)+"</th>";
        }
        htmlg += "</tr>";
      }
      html += htmlg;

      html += "<tbody id='"+group+"' style='"+visible+"'><tr>";
      for (field in table.fields)
      {
        var title = field; if (table.fields[field].title!=undefined) title = table.fields[field].title;
        html += "<th><a type='sort' field='"+field+"'>"+title+"</a></th>";
      }
      html += "</tr>";
      html += groups[group]['ui_rows'];
      html += "</tbody>";
    }

    $(table.element).html("<table class='table table-hover'>"+html+"</table>");

    if (table.eventsadded==false) {table.add_events(); table.eventsadded = true}
    
    $(table.element).trigger("onDraw");
  },

  'draw_row': function(row) {
    var html = "<tr uid='"+row+"' >";
    for (field in table.fields) html += "<td row='"+row+"' field='"+field+"' >"+table.fieldtypes[table.fields[field].type].draw(row,field)+"</td>";
    html += "</tr>";
    return html;
  },<commit_msg>Better group click/dblclick for touch devices.<commit_after>/*
  table.js is released under the GNU Affero General Public License.
  See COPYRIGHT.txt and LICENSE.txt.

  Part of the OpenEnergyMonitor project: http://openenergymonitor.org
*/
var table = {
  'data':0,
  'groupshow':{},

  'eventsadded':false,
  'deletedata':true,

  'sortfield':null,
  'sortorder':null,
  'sortable':true,

  'groupprefix':"",

  'timeServerLocalOffset':0, // offset of server to client time in ms

  'draw':function() {
    /*if (table.data && table.sortable) {
      table.data.sort(function(a,b) {
      if(a[table.sortfield]<b[table.sortfield]) return -1;
      if(a[table.sortfield]>b[table.sortfield]) return 1;
      return 0;
      });
    }*/

    if (table.data && table.sortable && table.sortfield) {
      table.data.sort(function(a,b) {
        var x=a[table.sortfield];
        var y=b[table.sortfield];
        if (x===null)x=Number.POSITIVE_INFINITY;
        if (y===null)y=Number.POSITIVE_INFINITY;
        if ((x==true) || (x== false)) x==false? x=0:x=1;
        if ((y==true) || (y== false)) y==false? y=0:y=1;
        if ($.isNumeric(x) && $.isNumeric(y)){
          var numa=parseFloat(x);
          var numb=parseFloat(y);

          if (table.sortorder==1){
            return numa-numb;
          } else {
            return numb-numa;
          }

        } else {
           if (typeof x == 'string') x=x.toUpperCase().replace(" ", "");
           if (typeof y == 'string') y=y.toUpperCase().replace(" ", "");
        }

        if (table.sortorder==1){
          if(x<y) return -1;
          if(x>y) return 1;
          return 0;
        } else{
          if(x>y) return -1;
          if(x<y) return 1;
          return 0;
        }
      });
    }

    var group_num = 0;
    var groups = {};
    for (row in table.data) {
      var group = table.data[row][table.groupby];
      if (!group) group = 'NoGroup';
      if (!groups[group]) {groups[group] = {}; groups[group]['ui_rows'] = ""; groups[group]['rows_id'] = []; group_num++;}
      groups[group]['ui_rows'] += table.draw_row(row);
      groups[group]['rows_id'].push(row);
    }

    var html = "";
    for (group in groups) {
      var visible = '';
      htmlg = "";
      if (group_num>1) {
        var symbol ='<i class="MINMAX icon-minus-sign" group="'+group+'" style="cursor:pointer"></i>'; 
        if (table.groupshow[group]==undefined) table.groupshow[group]=false; // default is collapsed
        if (table.groupshow[group]==false) {symbol = '<i class="MINMAX icon-plus-sign" group="'+group+'" style="cursor:pointer"></i>'; visible = "display:none";}
        htmlg += "<tr><th colspan='3'>"+symbol+" <a class='MINMAX' group='"+group+"' style='cursor:pointer'>"+table.groupprefix+group+"</a></th>";
        var countFields = 0; for (field in table.fields) countFields++; // Calculate amount of padding required
        if (table.groupfields == undefined) {
          for (i=2; i<countFields-1; i++) htmlg += "<th></th>"; // Add th padding
        } else {
          for (fieldg in table.groupfields) htmlg += "<th group='"+group+"' fieldg='"+fieldg+"' >"+table.fieldtypes[table.groupfields[fieldg].type].draw(group,groups[group]['rows_id'],fieldg)+"</th>";
        }
        htmlg += "</tr>";
      }
      html += htmlg;

      html += "<tbody id='"+group+"' style='"+visible+"'><tr>";
      for (field in table.fields)
      {
        var title = field; if (table.fields[field].title!=undefined) title = table.fields[field].title;
        html += "<th><a type='sort' field='"+field+"' style='cursor:pointer'>"+title+"</a></th>";
      }
      html += "</tr>";
      html += groups[group]['ui_rows'];
      html += "</tbody>";
    }

    $(table.element).html("<table class='table table-hover'>"+html+"</table>");

    if (table.eventsadded==false) {table.add_events(); table.eventsadded = true}
    
    $(table.element).trigger("onDraw");
  },

  'draw_row': function(row) {
    var html = "<tr uid='"+row+"' >";
    for (field in table.fields) html += "<td row='"+row+"' field='"+field+"' >"+table.fieldtypes[table.fields[field].type].draw(row,field)+"</td>";
    html += "</tr>";
    return html;
  },
{'fraction_non_alphanumeric': 0.2037579306979014, 'fraction_numerical': 0.005612493899463153, 'mean_word_length': 2.714091526959674, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, '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': '3264587', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2719, 'n_words': 560}