<commit_before>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

var ProjectStatistics = new function()
{
  var update_stats_fields = function(data) {
    $("#skeletons_created").text(data.skeletons_created);
    $("#treenodes_created").text(data.treenodes_created);
    $("#connectors_created").text(data.connectors_created);
  }

  var get_formated_entry = function(data) {
    var entry = '', points = 0;
    if( data.hasOwnProperty('new_treenodes') ) {
      entry += data['new_treenodes'] + ' /';
      points += data['new_treenodes'];
    } else {
      entry += '0 /';
    };
    if( data.hasOwnProperty('new_connectors') ) {
      entry += ' ' + data['new_connectors'] + ' /';
      points += data['new_connectors'];
    } else {
      entry += ' 0 /';
    };
    if( data.hasOwnProperty('new_reviewed_nodes') ) {
      entry += ' ' + data['new_reviewed_nodes'] + ' /';
      points += data['new_reviewed_nodes'];
    } else {
      entry += ' 0';
    };
    return {'entry': entry, 'points': points};
  }

  var update_user_history = function(data) {
    $('#project_stats_history_table').empty();
    var header = '';
    header += '<tr>';
    header += '<td>username</td>';
    for(var i = 0; i < data['days'].length; i++ ) {
      header += '<td>'+data['daysformatted'][i]+'</td>';
    }
    header += '</tr>';
    $('#project_stats_history_table').append( header );
    for(var username in data['stats_table']) {
      var row = '', weekpointcount = 0;
      row += '<tr>';
      if( data['stats_table'].hasOwnProperty( username ) ) {
        row += '<td>' + username + '</td>';
        for(var i = 0; i < data['days'].length; i++ ) {
          var datekey = data['days'][i],
              formated = get_formated_entry( data['stats_table'][ username ][ datekey ] );
          row += '<td>'+ formated['entry'] +'</td>';
          weekpointcount += formated['points'];
        }
      }
      row += '</tr>';
      if( weekpointcount === 0 ) {
        continue;
      } else {
        $('#project_stats_history_table').append( row );
      }
    }
  }

  var update_piechart = function(data, chart_name) {
    $(chart_name).empty();
    var rpie = Raphael(chart_name, 500, 200);
    var pie = rpie.g.piechart(90, 100, 80, data.values, { legend: data.users, legendpos: "east", colors:['red', 'blue', 'green', 'yellow', 'orange', 'black', 'gray']});
    pie.hover(function () {
      this.sector.stop();
      this.sector.scale(1.1, 1.1, this.cx, this.cy);
      if (this.label) {
        this.label[0].stop();
        this.label[0].scale(1.5);
        this.label[1].attr({"font-weight": 800});
      }
    }, function () {
      this.sector.animate({scale: [1, 1, this.cx, this.cy]}, 500, "bounce");
      if (this.label) {
        this.label[0].animate({scale: 1}, 500, "bounce");
        this.label[1].attr({"font-weight": 400});
      }
    });
  }
  
  var parseDate = function(d) {
    var d_s = d.toString();
    var year = d_s.substring(0, 4);
    var month = d_s.substring(4, 6);
    var day = d_s.substring(6, 8);
    return new Date(year + '-' + month + '-' + day);
  };
  <commit_msg>Make statistics widget work with new gRaphael version<commit_after>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

var ProjectStatistics = new function()
{
  var update_stats_fields = function(data) {
    $("#skeletons_created").text(data.skeletons_created);
    $("#treenodes_created").text(data.treenodes_created);
    $("#connectors_created").text(data.connectors_created);
  }

  var get_formated_entry = function(data) {
    var entry = '', points = 0;
    if( data.hasOwnProperty('new_treenodes') ) {
      entry += data['new_treenodes'] + ' /';
      points += data['new_treenodes'];
    } else {
      entry += '0 /';
    };
    if( data.hasOwnProperty('new_connectors') ) {
      entry += ' ' + data['new_connectors'] + ' /';
      points += data['new_connectors'];
    } else {
      entry += ' 0 /';
    };
    if( data.hasOwnProperty('new_reviewed_nodes') ) {
      entry += ' ' + data['new_reviewed_nodes'] + ' /';
      points += data['new_reviewed_nodes'];
    } else {
      entry += ' 0';
    };
    return {'entry': entry, 'points': points};
  }

  var update_user_history = function(data) {
    $('#project_stats_history_table').empty();
    var header = '';
    header += '<tr>';
    header += '<td>username</td>';
    for(var i = 0; i < data['days'].length; i++ ) {
      header += '<td>'+data['daysformatted'][i]+'</td>';
    }
    header += '</tr>';
    $('#project_stats_history_table').append( header );
    for(var username in data['stats_table']) {
      var row = '', weekpointcount = 0;
      row += '<tr>';
      if( data['stats_table'].hasOwnProperty( username ) ) {
        row += '<td>' + username + '</td>';
        for(var i = 0; i < data['days'].length; i++ ) {
          var datekey = data['days'][i],
              formated = get_formated_entry( data['stats_table'][ username ][ datekey ] );
          row += '<td>'+ formated['entry'] +'</td>';
          weekpointcount += formated['points'];
        }
      }
      row += '</tr>';
      if( weekpointcount === 0 ) {
        continue;
      } else {
        $('#project_stats_history_table').append( row );
      }
    }
  }

  var update_piechart = function(data, chart_name) {
    $(chart_name).empty();
    var rpie = Raphael(chart_name, 500, 200);
    var pie = rpie.piechart(90, 100, 80, data.values, { legend: data.users, legendpos: "east", colors:['red', 'blue', 'green', 'yellow', 'orange', 'black', 'gray']});
    pie.hover(function () {
      // scale everything up
      this.sector.stop();
      this.sector.scale(1.1, 1.1, this.cx, this.cy);
      if (this.label) {
        this.label[0].stop();
        this.label[0].attr({ r: 7.5 });
        this.label[1].attr({"font-weight": 800});
      }
    }, function () {
      this.sector.animate({ transform: "s1 1 " + this.cx + " " + this.cy }, 500, "bounce");
      if (this.label) {
        this.label[0].animate({ r: 5 }, 500, "bounce");
        this.label[1].attr({"font-weight": 400});
      }
    });
  }
  
  var parseDate = function(d) {
    var d_s = d.toString();
    var year = d_s.substring(0, 4);
    var month = d_s.substring(4, 6);
    var day = d_s.substring(6, 8);
    return new Date(year + '-' + month + '-' + day);
  };
  
{'fraction_non_alphanumeric': 0.20086393088552915, 'fraction_numerical': 0.017587164455414996, 'mean_word_length': 2.6835227272727273, 'pattern_counts': {'":': 4, '<': 31, '<?xml version=': 0, '>': 27, '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': '5319751', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2183, 'n_words': 430}