mechanical-tolerance-calculator 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +22 -10
  2. package/package.json +1 -1
  3. package/test.js +3 -1
package/index.js CHANGED
@@ -379,28 +379,27 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
379
379
  largestMeasurement - smallestMeasurement,
380
380
  );
381
381
 
382
- let mostFarMeasurement = largestMeasurement;
383
382
  const nominals = {};
384
383
  let count = 0;
385
- let withInSpecs = [];
384
+ // let withInSpecs = [];
386
385
  const results = measurements.map((measurement) => {
387
386
  const result = processIndividualMeasurement(
388
387
  camcoStandardTolerances.type,
389
388
  measurement,
390
389
  camcoStandardTolerances,
391
390
  );
392
- withInSpecs.push(result.meets_specification.meetsSpec);
391
+ // withInSpecs.push(result.meets_specification.meetsSpec);
393
392
  const nominal = result.nominal;
394
393
 
395
394
  // count occurrences
396
395
  nominals[nominal] = (nominals[nominal] || 0) + 1;
397
396
 
398
- if (
399
- Math.abs(result.nominal - result.measurement) >
400
- Math.abs(result.nominal - mostFarMeasurement)
401
- ) {
402
- mostFarMeasurement = result.measurement;
403
- }
397
+ // if (
398
+ // Math.abs(result.nominal - result.measurement) >
399
+ // Math.abs(result.nominal - mostFarMeasurement)
400
+ // ) {
401
+ // mostFarMeasurement = result.measurement;
402
+ // }
404
403
 
405
404
  return result;
406
405
  });
@@ -410,6 +409,12 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
410
409
  let mostOccuredNominal = Object.keys(nominals).find(
411
410
  (nominal) => nominals[nominal] === countOfMostOccuredNominal,
412
411
  );
412
+ let mostFarMeasurement = measurements.reduce((farthest, current) => {
413
+ return Math.abs(current - mostOccuredNominal) >
414
+ Math.abs(farthest - mostOccuredNominal)
415
+ ? current
416
+ : farthest;
417
+ });
413
418
 
414
419
  const baseSpec = results.find(
415
420
  (result) => result.nominal === parseInt(mostOccuredNominal),
@@ -425,7 +430,14 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
425
430
  baseSpec.IT_grade,
426
431
  );
427
432
 
428
- const meetsSpec = withInSpecs.every((v) => v === true);
433
+ const meetsSpec = results.every((r) => {
434
+ const value = r.measurement;
435
+ return (
436
+ value >= baseSpec.computed_specification_bounds.lowerBound &&
437
+ value <= baseSpec.computed_specification_bounds.upperBound
438
+ );
439
+ });
440
+
429
441
  const specMeetingReason = generateReasonForSpecs(
430
442
  meetsSpec,
431
443
  mostFarMeasurement,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mechanical-tolerance-calculator",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Calculates international standard specification and tolerances for bores, round bars and metals of mechanical units. For examples; H7, H8, H9, h8, h9 specifications and IT5/IT6 tolerances.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -1,4 +1,6 @@
1
1
  const { checkMultipleMeasurementsFor } = require("./index");
2
2
  // console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05]));
3
3
  // console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05, 95.06]));
4
- console.log(checkMultipleMeasurementsFor("housing", [99.99, 99.98, 99.99]));
4
+ console.log(
5
+ checkMultipleMeasurementsFor("housing", [100, 32, 32, 1, 100, 100]),
6
+ );