<commit_before>import macros from "../macros.sjs";

var data = require("./data.json");

function stackToDiff(stack) {
  var diff = {};
  forattr(view, facts of stack) {
    diff[view] = {adds: facts};
  }
  return diff;
};

function getFields(view, stack) {
  var fields = [];
  const FIELD_VIEW = 1;
  foreach(row of stack.field) {
    if(row[FIELD_VIEW] == view) {
    }
  }
}

console.log(stackToDiff(data["department heads"]));

// [[viewId]: [rows:Fact]]
var viewUI = {};

// Update view UI in response to added, removed, or updated facts.
function diffRenderer(diffs, stack) {
  forattr(view, diff of diffs) {
    var rowId;
    var rowElem;

    // Find removed rows to prune.
    foreach(row of diff.removes) {
      rowId = factToId(row);
      // Ensure that the node exists to remove.
      if(viewUI[view] && viewUI[view][rowId]) {
        rowElem = viewUI[view][rowId];
        rowElem.parentNode.removeChild();
      }
    }

    // Build and insert added rows.
    foreach(row of diff.adds) {
      rowId = factToId(row);
      rowElem = document.createElement("div");
    }
  }

};<commit_msg>Wire test diff into diffRenderer for testing<commit_after>import macros from "../macros.sjs";

var data = require("./data.json");

function stackToDiff(stack) {
  var diff = {};
  forattr(view, facts of stack) {
    diff[view] = {adds: facts};
  }
  return diff;
};

function getFields(view, stack) {
  const FIELD_FIELD = 0;
  const FIELD_VIEW = 1;

  var fields = [];
  foreach(row of stack.field) {
    if(row[FIELD_VIEW] == view) {
      fields.push(row);
    }
  }

  return fields;
}



// [[viewId]: [rows:Fact]]
var viewsContainer = document.createElement("div");
document.body.appendChild(viewsContainer);
var viewUI = {};
// Update view UI in response to added, removed, or updated facts.
function diffRenderer(diffs) {
  document.body.removeChild(viewsContainer);
  forattr(view, diff of diffs) {
    var rowId;
    var rowElem;
    console.log('V', view, 'D', diff);

    if(!viewUI[view]) {
      var viewContainer = document.createElement("div");
      viewContainer.className = "card table-card open";
      var viewGrid = document.createElement("div");
      viewGrid.className = "grid";
      viewContainer.appendChild(viewGrid);
      viewUI[view] = {
        $container: viewContainer,
        $title: null, //@FIXME
        $header: null, //@FIXME
        $grid: viewGrid
      };
      viewsContainer.appendChild(viewContainer);
    }

    // Find removed rows to prune.
    foreach(row of diff.removes) {
      rowId = factToId(row);
      // Ensure that the node exists to remove.
      if(viewUI[view] && viewUI[view][rowId]) {
        rowElem = viewUI[view][rowId];
        rowElem.parentNode.removeChild();
      }
    }

    // Build and insert added rows.
    foreach(row of diff.adds) {
      rowId = factToId(row);
      rowElem = document.createElement("div");

      foreach(field of row) {
        var fieldElem = document.createElement("div");
        fieldElem.className = "grid-row";
        fieldElem.appendChild(document.createTextNode(field));
        rowElem.appendChild(fieldElem);
      }

      viewUI[view].$grid.appendChild(rowElem);
    }
  }
  document.body.appendChild(viewsContainer);
}


var diffs = stackToDiff(data["department heads"]);
console.log(diffs);

diffRenderer(diffs);
{'fraction_non_alphanumeric': 0.14076070679844266, 'fraction_numerical': 0.0008984725965858042, 'mean_word_length': 2.957345971563981, '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': '1730099', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1057, 'n_words': 252}