<commit_before>////////////////////////////////////////////////////////////////
// global data

var theContext = {};
var ResultTable;

////////////////////////////////////////////////////////////////
// startup
//
$(document).ready(function() {

  // retrieve the query params
  var theQuery = $.getQuery();

  // connect the button
  $("#element-generate").button().click(onGenerate);

  // Hold onto the current session information
  theContext.documentId = theQuery.documentId;
  theContext.workspaceId = theQuery.workspaceId;
  theContext.elementId = theQuery.elementId;
  refreshContextElements();

});


// update the list of elements in the context object
function refreshContextElements() {
  var dfd = $.Deferred();
  // Get all elements for the document ... only send D/W
  var params = "?documentId=" + theContext.documentId + "&workspaceId=" + theContext.workspaceId;
  $.ajax('/api/assemblies'+ params, {
    dataType: 'json',
    type: 'GET',
    success: function(data) {
      // for each assembly tab, create a select option to make that
      // assembly the current context
      $("#elt-select").empty();

      var objects = data;
      var id;

      for (var i = 0; i < objects.length; ++i) {
        $("#elt-select")
            .append(
                    "<option value='" + objects[i].id + "'" +
                    (i == 0 ? " selected" : "") + ">" +
                    objects[i].name + "</option>"
                   )
            .change(function () {
              id = $("#elt-select option:selected").val();
              theContext.elementId = id;
              });
      }
      theContext.elementId = $("#elt-select option:selected").val();
    }
  });
  return dfd.promise();
}

/////////////////////////////////////
//
// Primary BOM generation function
//
var realSize = 0.001;
var tX = 0;
var tY = 0;
var tZ = 0;

function onGenerate() {
  // Destroy anything previously created ...
  $('#bomResults').empty();

  theContext.elementId = $("#elt-select option:selected").val();

  // Get the bounding box size
  $.ajax('/api/boundingBox' + '?documentId=' + theContext.documentId + '&workspaceId=' + theContext.workspaceId + '&elementId=' + theContext.elementId, {
    dataType: 'json',
    type: 'GET',
    success: function(data) {
      var res = data;
      var xLow = res.lowX;
      var xHigh = res.highX;
      var yLow = res.lowY;
      var yHigh = res.highY;
      var zLow = res.lowZ;
      var zHigh = res.highZ;

      // Get the size of the BBox
      var xDiff = xHigh - xLow;
      var yDiff = yHigh - yLow;
      var zDiff = zHigh - zLow;
      realSize = Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);

      // Find the center of the BBox - model coordinates
      var xCenter = (xHigh + xLow) / 2;
      var yCenter = (yHigh + yLow) / 2;
      var zCenter = (zHigh + zLow) / 2;

      tX = xCenter * 0.707 + xCenter * -0.409 + xCenter * 0.577;
      tY = yCenter * 0.707 + yCenter * 0.409 + yCenter * -0.577;
      tZ = zCenter * 0 + zCenter * 0.816 + zCenter * 0.577;

      // Now, finish the rest of the work.
      onGenerate2();
    },
    error: function(data) {
      console.log("****** GET BOUNDING BOX - FAILURE - index.js");
    }
  });
}

//
// Keep track of all the components and sub-assemblies we find.
//
var Comp2Array = [];
var SubAsmArray = [];
var ThumbPromises = [];

function generateBBox(elementId, partId) {
  return new Promise(function(resolve, reject) {
    // Get the bounding box size
    $.ajax('/api/boundingBox' + '?documentId=' + theContext.documentId + '&workspaceId=' + theContext.workspaceId + '&elementId=' + elementId + '&partId=' + partId, {
      dataType: 'json',
      type: 'GET',
      success: function(data) {
        var res = data;
        var xLow = res.lowX;
        var xHigh = res.highX;
        var yLow = res.lowY;
        var yHigh = res.highY;
        var zLow = res.lowZ;
        var zHigh = res.highZ;

        // Get the size of the BBox
        var xDiff = xHigh - xLow;
        var yDiff = yHigh - yLow;
        var zDiff = zHigh - zLow;
        bSize = Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);

        // Find the center of the BBox - model coordinates
        var xCenter = (xHigh + xLow) / 2;
        var yCenter = (yHigh + yLow) / 2;
        var zCenter = (zHigh + zLow) / 2;

        var bX = xCenter * 0.707 + xCenter * -0.409 + xCenter * 0.577;
        var bY = yCenter * 0.707 + yCenter * 0.409 + yCenter * -0.577;
        var bZ = zCenter * 0 + zCenter * 0.816 + zCenter * 0.577;

        // Now, finish the rest of the work.
        generateThumbs({'Element' : elementId, 'PartId' : partId, 'xCtr' : bX, 'yCtr' : bY, 'zCtr' : bZ, 'size' : bSize });
        resolve(1);
      },
      error: function(data) {
        reject(1);
      }
    });
  });
}

var ImagesArray = [];

function generateThumbs(argMap) {

  var thumb = new Promise(function(resolve, reject) {

    var elementId = argMap.Element;
    var partId = argMap.PartId;
    var xCtr = argMap.xCtr;
    var yCtr = argMap.yCtr;
    var zCtr = argMap.zCtr;
    var size = argMap.size;<commit_msg>Sizing<commit_after>////////////////////////////////////////////////////////////////
// global data

var theContext = {};
var ResultTable;

////////////////////////////////////////////////////////////////
// startup
//
$(document).ready(function() {

  // retrieve the query params
  var theQuery = $.getQuery();

  // connect the button
  $("#element-generate").button().click(onGenerate);

  // Hold onto the current session information
  theContext.documentId = theQuery.documentId;
  theContext.workspaceId = theQuery.workspaceId;
  theContext.elementId = theQuery.elementId;
  refreshContextElements();

});


// update the list of elements in the context object
function refreshContextElements() {
  var dfd = $.Deferred();
  // Get all elements for the document ... only send D/W
  var params = "?documentId=" + theContext.documentId + "&workspaceId=" + theContext.workspaceId;
  $.ajax('/api/assemblies'+ params, {
    dataType: 'json',
    type: 'GET',
    success: function(data) {
      // for each assembly tab, create a select option to make that
      // assembly the current context
      $("#elt-select").empty();

      var objects = data;
      var id;

      for (var i = 0; i < objects.length; ++i) {
        $("#elt-select")
            .append(
                    "<option value='" + objects[i].id + "'" +
                    (i == 0 ? " selected" : "") + ">" +
                    objects[i].name + "</option>"
                   )
            .change(function () {
              id = $("#elt-select option:selected").val();
              theContext.elementId = id;
              });
      }
      theContext.elementId = $("#elt-select option:selected").val();
    }
  });
  return dfd.promise();
}

/////////////////////////////////////
//
// Primary BOM generation function
//
var realSize = 0.001;
var tX = 0;
var tY = 0;
var tZ = 0;

function onGenerate() {
  // Destroy anything previously created ...
  $('#bomResults').empty();

  theContext.elementId = $("#elt-select option:selected").val();

  // Get the bounding box size
  $.ajax('/api/boundingBox' + '?documentId=' + theContext.documentId + '&workspaceId=' + theContext.workspaceId + '&elementId=' + theContext.elementId, {
    dataType: 'json',
    type: 'GET',
    success: function(data) {
      var res = data;
      var xLow = res.lowX;
      var xHigh = res.highX;
      var yLow = res.lowY;
      var yHigh = res.highY;
      var zLow = res.lowZ;
      var zHigh = res.highZ;

      // Get the size of the BBox
      var xDiff = xHigh - xLow;
      var yDiff = yHigh - yLow;
      var zDiff = zHigh - zLow;
      realSize = Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);

      // Find the center of the BBox - model coordinates
      var xCenter = (xHigh + xLow) / 2;
      var yCenter = (yHigh + yLow) / 2;
      var zCenter = (zHigh + zLow) / 2;

      tX = xCenter * 0.707 + xCenter * -0.409 + xCenter * 0.577;
      tY = yCenter * 0.707 + yCenter * 0.409 + yCenter * -0.577;
      tZ = zCenter * 0 + zCenter * 0.816 + zCenter * 0.577;

      // Now, finish the rest of the work.
      onGenerate2();
    },
    error: function(data) {
      console.log("****** GET BOUNDING BOX - FAILURE - index.js");
    }
  });
}

//
// Keep track of all the components and sub-assemblies we find.
//
var Comp2Array = [];
var SubAsmArray = [];
var ThumbPromises = [];

function generateBBox(elementId, partId) {
  return new Promise(function(resolve, reject) {
    // Get the bounding box size
    $.ajax('/api/boundingBox' + '?documentId=' + theContext.documentId + '&workspaceId=' + theContext.workspaceId + '&elementId=' + elementId + '&partId=' + partId, {
      dataType: 'json',
      type: 'GET',
      success: function(data) {
        var res = data;
        var xLow = res.lowX;
        var xHigh = res.highX;
        var yLow = res.lowY;
        var yHigh = res.highY;
        var zLow = res.lowZ;
        var zHigh = res.highZ;

        // Get the size of the BBox
        var xDiff = xHigh - xLow;
        var yDiff = yHigh - yLow;
        var zDiff = zHigh - zLow;
        bSize = Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);

        // Find the center of the BBox - model coordinates
        var xCenter = (xHigh + xLow) / 2;
        var yCenter = (yHigh + yLow) / 2;
        var zCenter = (zHigh + zLow) / 2;

        var bX = xCenter * 0.707 + xCenter * -0.409 + xCenter * 0.577;
        var bY = yCenter * 0.707 + yCenter * 0.409 + yCenter * -0.577;
        var bZ = zCenter * 0 + zCenter * 0.816 + zCenter * 0.577;

        // Now, finish the rest of the work.
        generateThumbs({'Element' : elementId, 'PartId' : partId, 'xCtr' : -bX, 'yCtr' : -bY, 'zCtr' : bZ, 'size' : bSize });
        resolve(1);
      },
      error: function(data) {
        reject(1);
      }
    });
  });
}

var ImagesArray = [];

function generateThumbs(argMap) {

  var thumb = new Promise(function(resolve, reject) {

    var elementId = argMap.Element;
    var partId = argMap.PartId;
    var xCtr = argMap.xCtr;
    var yCtr = argMap.yCtr;
    var zCtr = argMap.zCtr;
    var size = argMap.size;
{'fraction_non_alphanumeric': 0.17248459958932238, 'fraction_numerical': 0.016622665493302043, 'mean_word_length': 1.9672178706121264, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6136050', 'n_tokens_mistral': 3410, 'n_tokens_neox': 3248, 'n_words': 909}