<commit_before>/**
 * Created by Reem on 6/15/2015.
 */

define(["require", "exports", 'd3'],
  function (require, exports, d3) {

    function DifflogParser(diff_file) {
      this.filepath = diff_file;
      this.diff_arrays = {
        added_rows: [],
        deleted_rows: [],
        added_cols: [],
        deleted_cols: [],
        merged_rows: [],
        split_rows: [],
        merged_cols: [],
        split_cols: [],
        ch_cells: []
      };
    }

    DifflogParser.prototype.getDiff = function(){
      var that = this;
      //so far we use the same counter for both columns and rows (it doesn't matter)
      var merge_id = 0;
      var split_id = 0;

      var promise = new Promise(function(resolve, reject){
        d3.tsv(that.filepath, function (error, data) {
          if (error) reject(error);
          data.forEach(function (d) {
            //we assume that the id is separated by comma ,
            var log_separator = ",";
            /*operation: d.operation,
             type: d.type,
             id: d.id,
             position: d.position // convert to number use: +d.position*/
            if (d.operation === "add") {
              if (d.type === 'column') {
                that.diff_arrays.added_cols.push({id: d.id, pos: +d.position});
              } else if (d.type === 'row') {
                that.diff_arrays.added_rows.push({id: d.id, pos: +d.position});
              }
            } else if (d.operation === "delete") {
              if (d.type === 'column') {
                that.diff_arrays.deleted_cols.push({id: d.id, pos: +d.position});
              } else if (d.type === 'row') {
                that.diff_arrays.deleted_rows.push({id: d.id, pos: +d.position});
              }
            } else if (d.operation === "merge") {
              var ids = d.id.split(log_separator); //the first one is the merge one!
              var pos = d.position.split(log_separator).map(Number);
              ids.forEach(function (value,index){
                if (d.type === 'column') {
                  that.diff_arrays.merged_cols.push({id: value, pos: pos[index], merge_id: merge_id, is_added:(index == 0)});
                } else if (d.type === 'row') {
                  that.diff_arrays.merged_rows.push({id: value, pos: pos[index], merge_id: merge_id, is_added:(index == 0)});
                }
              });
              //increment the merge id
              merge_id++;
            } else if (d.operation === "split") {
              var ids = d.id.split(log_separator); //the first one is the merge one!
              var pos = d.position.split(log_separator).map(Number);
              ids.forEach(function (value,index){
                if (d.type === 'column') {
                  that.diff_arrays.split_cols.push({id: value, pos: pos[index], split_id: merge_id, is_added:(index != 0)});
                } else if (d.type === 'row') {
                  that.diff_arrays.split_rows.push({id: value, pos: pos[index], split_id: merge_id, is_added:(index != 0)});
                }
              });
              //increment the split id
              split_id++;
            } else if (d.operation === "change" && d.type === 'cell'){
              var cell = d.id.split(log_separator);
              var pos = d.position.split(log_separator);
              that.diff_arrays.ch_cells.push({row: cell[0], col: cell[1], diff_data: d.data, rpos: +pos[0], cpos: +pos[1]});
            }
          });
          console.log(that.diff_arrays);
          resolve(that.diff_arrays);
          //
        });
      });

      return promise;
    };

    exports.create = function(diff_file){
      return new DifflogParser(diff_file);
    };

  });
<commit_msg>Removed parsing TLS and used JSON instead<commit_after>/**
 * Created by Reem on 6/15/2015.
 */

define(["require", "exports", 'd3'],
  function (require, exports, d3) {

    function DifflogParser(diff_file) {
      this.filepath = diff_file;
    }

    DifflogParser.prototype.getDiff = function(){
      var that = this;

      var promise = new Promise(function(resolve, reject){
        d3.json(that.filepath, function (error, data) {
          if (error) reject(error);
          //console.log(" new data ", data);
          resolve(data);
          //
        });
      });

      return promise;
    };

    exports.create = function(diff_file){
      return new DifflogParser(diff_file);
    };

  });

{'fraction_non_alphanumeric': 0.14940194087113517, 'fraction_numerical': 0.006770480704129994, 'mean_word_length': 1.7926906112161312, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1827327', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1323, 'n_words': 305}