<commit_before>"use strict";
var StepNC = require('../../../../../STEPNode/build/Release/StepNC');
var file = require('./file');
var _ = require('lodash');
var tol = file.tol;
var apt = file.apt;
var find = file.find;

var GetWorkingstepsForTolerance = function(exe, tolId) {
    if (find.IsWorkingstep(exe)) {
        let allTols = tol.GetWorkingstepToleranceAll(exe);
        if (_.indexOf(allTols, tolId) !== -1) {
            return [exe];
        }
        else {
            return [];
        }
    }
    else if (find.IsWorkplan(exe) || find.IsSelective(exe)) {
        let rtn = [];
        let children = find.GetNestedExecutableAll(exe);
        if (children !== undefined) {
            _.each(children, (childId) => {
                rtn = rtn.concat(GetWorkingstepsForTolerance(childId, tolId));
            });
        }
        return rtn;
    }
    else {
        console.log("something's afoot");
        return [];
    }
};

var _getTolerance = function(id) {
  let steps = GetWorkingstepsForTolerance(find.GetMainWorkplan(), id);
  let name = tol.GetToleranceType(id).replace(/_/g, ' ').toLowerCase();
  let tolType = name.split(' ')[0];
  
  return {
      "id":id,
      "type": 'tolerance',
      "name": name,
      "toleranceType": tolType,
      "value": tol.GetToleranceValue(id),
      "workingsteps": steps,
      "unit" : tol.GetToleranceUnit(id)
  };
};

var _getTols = function(req,res) {
  let tol_list = tol.GetToleranceAll();
  let ret = [];
  for (let id of tol_list){
      ret.push(_getTolerance(id));
  }
  res.status(200).send(ret);
};

var _getWps = function(req,res) {
  let wp_list = find.GetWorkpieceAll();
  let ret = [];
  for (let id of wp_list){
    let type = find.GetWorkpieceType(id);
    let name = find.GetWorkpieceName(id);
    if(type === 'workpiece') {
      let tolerances = tol.GetWorkpieceToleranceAll(id);
      ret.push({
        "id": id,
        "type": "workpiece",
        "name": name,
        "wpType": type,
        "tolerances": tolerances,
      });
    }
  }
  res.status(200).send(ret);
};

var _getWsTols = function(req,res) {
  if (req.params.wsId){
    let wsId = req.params.wsId;
    if (find.IsWorkingstep(wsId)) {
      let tolerances = JSON.stringify(tol.GetWorkingstepToleranceAll(wsId));
      console.log("tolerances" + tolerances);
      res.status(200).send(tolerances);
    }
    else {  // we are looking for a tolerance
      let tol = _getTolerance(req.params.wsId);
      res.status(200).send(tol);
    }
  }
};

module.exports = function(app, cb) {
  app.router.get('/v3/nc/tolerances/:wsId',_getWsTols);
  app.router.get('/v3/nc/tolerances/',_getTols);
  app.router.get('/v3/nc/workpieces/',_getWps);

  if (cb) cb();
};<commit_msg>Added workpiece property to tolerance object<commit_after>"use strict";
var StepNC = require('../../../../../STEPNode/build/Release/StepNC');
var file = require('./file');
var _ = require('lodash');
var tol = file.tol;
var apt = file.apt;
var find = file.find;

var GetWorkingstepsForTolerance = function(exe, tolId) {
    if (find.IsWorkingstep(exe)) {
        let allTols = tol.GetWorkingstepToleranceAll(exe);
        if (_.indexOf(allTols, tolId) !== -1) {
            return [exe];
        }
        else {
            return [];
        }
    }
    else if (find.IsWorkplan(exe) || find.IsSelective(exe)) {
        let rtn = [];
        let children = find.GetNestedExecutableAll(exe);
        if (children !== undefined) {
            _.each(children, (childId) => {
                rtn = rtn.concat(GetWorkingstepsForTolerance(childId, tolId));
            });
        }
        return rtn;
    }
    else {
        console.log("something's afoot");
        return [];
    }
};

var _getTolerance = function(id) {
  let steps = GetWorkingstepsForTolerance(find.GetMainWorkplan(), id);
  let name = tol.GetToleranceType(id).replace(/_/g, ' ').toLowerCase();
  let tolType = name.split(' ')[0];
  
  return {
      "id":id,
      "type": 'tolerance',
      "name": name,
      "toleranceType": tolType,
      "value": tol.GetToleranceValue(id),
      "workingsteps": steps,
      "unit" : tol.GetToleranceUnit(id),
      "workpiece": tol.GetWorkpieceOfTolerance(id),
  };
};

var _getTols = function(req,res) {
  let tol_list = tol.GetToleranceAll();
  let ret = [];
  for (let id of tol_list){
      ret.push(_getTolerance(id));
  }
  res.status(200).send(ret);
};

var _getWps = function(req,res) {
  let wp_list = find.GetWorkpieceAll();
  let ret = [];
  for (let id of wp_list){
    let type = find.GetWorkpieceType(id);
    let name = find.GetWorkpieceName(id);
    if(type === 'workpiece') {
      let tolerances = tol.GetWorkpieceToleranceAll(id);
      ret.push({
        "id": id,
        "type": "workpiece",
        "name": name,
        "wpType": type,
        "tolerances": tolerances,
      });
    }
  }
  res.status(200).send(ret);
};

var _getWsTols = function(req,res) {
  if (req.params.wsId){
    let wsId = req.params.wsId;
    if (find.IsWorkingstep(wsId)) { // this may be able to be factored out later
      let tolerances = JSON.stringify(tol.GetWorkingstepToleranceAll(wsId));
      console.log("tolerances" + tolerances);
      res.status(200).send(tolerances);
    }
    else {  // we are looking for a tolerance
      let tol = _getTolerance(req.params.wsId);
      res.status(200).send(tol);
    }
  }
};

module.exports = function(app, cb) {
  app.router.get('/v3/nc/tolerances/:wsId',_getWsTols);
  app.router.get('/v3/nc/tolerances/',_getTols);
  app.router.get('/v3/nc/workpieces/',_getWps);

  if (cb) cb();
};
{'fraction_non_alphanumeric': 0.16466367713004484, 'fraction_numerical': 0.006098654708520179, 'mean_word_length': 2.6373124592302672, 'pattern_counts': {'":': 23, '<': 3, '<?xml version=': 0, '>': 5, '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': '4800605', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1960, 'n_words': 366}