mechanical-tolerance-calculator 1.0.5 → 1.0.6

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 (2) hide show
  1. package/index.js +33 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -225,7 +225,7 @@ function processOneMeasurement(materialType, measurement, tolerances) {
225
225
  );
226
226
  return {
227
227
  ...processedMeasurement,
228
- meets_IT_tolerance: processedMeasurement.meet_specification,
228
+ meets_IT_tolerance: processedMeasurement.meets_specification.meetsSpec,
229
229
  };
230
230
  }
231
231
 
@@ -303,21 +303,13 @@ function parseStringFloat(value) {
303
303
  // Return 0 if parsing fails (NaN)
304
304
  return isNaN(parsed) ? 0 : parsed;
305
305
  }
306
- function processIndividualMeasurement(
307
- materialType,
308
- measurement,
309
- tolerances,
310
- meetsIT,
311
- ITMeetingReason
312
- ) {
306
+ function processIndividualMeasurement(materialType, measurement, tolerances) {
313
307
  const processedMeasurement = processMeasurement(
314
308
  materialType,
315
309
  measurement,
316
310
  tolerances
317
311
  );
318
- return {
319
- ...processedMeasurement,
320
- };
312
+ return processedMeasurement;
321
313
  }
322
314
 
323
315
  function checkMultipleMeasurementsFor(materialType, measurements) {
@@ -333,27 +325,28 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
333
325
  largestMeasurement - smallestMeasurement
334
326
  );
335
327
 
336
- const ITs = {
337
- IT5: 0,
338
- IT6: 0,
339
- IT7: 0,
340
- IT8: 0,
341
- IT9: 0,
342
- };
343
-
328
+ const nominals = {};
329
+ let count = 0;
344
330
  const results = measurements.map((measurement) => {
345
331
  const result = processIndividualMeasurement(
346
332
  camcoStandardTolerances.type,
347
333
  measurement,
348
334
  camcoStandardTolerances
349
335
  );
350
-
351
- ITs[result.IT_grade]++;
352
-
336
+ nominals[result.nominal] = count++;
353
337
  return result;
354
338
  });
355
339
 
356
- const baseSpec = results[0];
340
+ let countOfMostOccuredNominal = Math.max(...Object.values(nominals));
341
+
342
+ let mostOccuredNominal = Object.keys(nominals).find(
343
+ (nominal) => nominals[nominal] === countOfMostOccuredNominal
344
+ );
345
+ console.log(mostOccuredNominal);
346
+
347
+ const baseSpec = results.find(
348
+ (result) => result.nominal === parseInt(mostOccuredNominal)
349
+ );
357
350
  const baseITValue = baseSpec.matched_spec[baseSpec.IT_grade];
358
351
 
359
352
  const meetsIT = ITDifference <= baseITValue;
@@ -369,9 +362,25 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
369
362
  smallestMeasurement
370
363
  )} is greater than to ${baseITValue}.`;
371
364
 
365
+ // Check if measurement meets specification
366
+ const meetsSpec = checkMeetsSpecification(
367
+ largestMeasurement,
368
+ baseSpec?.computed_specification_bounds
369
+ );
370
+ console.log(meetsSpec);
371
+
372
+ const specMeetingReason = meetsSpec
373
+ ? `${parseToFixedThreeString(baseSpec.measurement)} falls between ${
374
+ baseSpec.computed_specification_bounds.lowerBound
375
+ } and ${baseSpec.computed_specification_bounds.upperBound}`
376
+ : `${parseToFixedThreeString(largestMeasurement)} doesn't fall between ${
377
+ baseSpec.computed_specification_bounds.lowerBound
378
+ } and ${baseSpec.computed_specification_bounds.upperBound}`;
372
379
  return {
373
- baseSpec,
380
+ meets_specification: { meetsSpec, reason: specMeetingReason },
374
381
  meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
382
+ meets_final_compliance: meetsIT && baseSpec?.meets_specification?.meetsSpec,
383
+ ...baseSpec,
375
384
  };
376
385
  }
377
386
 
@@ -387,7 +396,6 @@ function validateMeasurements(measurements) {
387
396
  error: "Measurements array cannot be empty",
388
397
  };
389
398
  }
390
-
391
399
  return null;
392
400
  }
393
401
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mechanical-tolerance-calculator",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
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": {