From 9cd2c8c29d47635e943844d39b157ab3c11d51ed Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 20 Oct 2023 11:49:36 -0400 Subject: [PATCH] Calculate out of Tolerance --- benchtop-fe/src/parsers/Transducer.js | 11 +++++++++- .../parsers/__tests__/parseTransducer.test.js | 21 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/benchtop-fe/src/parsers/Transducer.js b/benchtop-fe/src/parsers/Transducer.js index 07da1ae..a516d9e 100644 --- a/benchtop-fe/src/parsers/Transducer.js +++ b/benchtop-fe/src/parsers/Transducer.js @@ -11,7 +11,7 @@ const delta = (index, value, masterValues) => { return Math.abs(masterValues[index]["Low Limit"] - value); } -export default function parseTransducer(fileName, content, accuracy){ +export default function parseTransducer(content, accuracy){ accuracy = accuracy / 100.0; // Comes in as Percent const transducerData = []; @@ -101,12 +101,21 @@ export default function parseTransducer(fileName, content, accuracy){ } // Once we have the readings and master values, we can do the math + // Doing Map, so we can have the paired index between GaugeReading and Master Value transducerInfo["Gauge Reading"] = transducerInfo["Gauge Reading"].map((v, idx) => ({ Value: v, "In Range": inRange(idx, v, transducerInfo["Master Value"]), Delta: delta(idx, v, transducerInfo["Master Value"]), })); + // Calculate Out of Tolerances + for (const reading of transducerInfo["Gauge Reading"]) { + reading["Out Of Tolerance"] = 0; + if (!reading["In Range"]) { + reading["Out Of Tolerance"] = reading["Delta"]; + } + } + transducerData.push(transducerInfo); } diff --git a/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js b/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js index f82c1eb..309ed01 100644 --- a/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js +++ b/benchtop-fe/src/parsers/__tests__/parseTransducer.test.js @@ -4,8 +4,6 @@ const fs = require('fs'); const path = require('path'); import parseTransducer from "../Transducer" -// const file = fs.readFileSync("src/parsers/__tests__/transducer_verify.txt", 'utf8') - function readFiles(dir) { const files = []; @@ -29,7 +27,7 @@ describe("Test for all files", () => { let files = readFiles("src/parsers/__tests__/transducer_verify/"); for (const file of files) { test(`Can parse ${file.name}`, () => { - const transducers = parseTransducer(file.name, file.content, 0.05) + const transducers = parseTransducer(file.content, 0.05) expect(transducers.length).toBeGreaterThan(0) for (const transducer of transducers) { @@ -44,3 +42,20 @@ describe("Test for all files", () => { }); } }); + +describe("Testing actual calculations", () => { + test("It can detect if out of tolerance", () => { + const content = fs.readFileSync("src/parsers/__tests__/transducer_verify/Blackbelt with flow 220601_143736 Transducer Verify.txt", 'utf8'); + const transducers = parseTransducer(content, 0.05); + for (const transducer of transducers) { + let anyOOT = false; + for (const gauge of transducer["Gauge Reading"]) { + if (!gauge["In Range"]) { + anyOOT = true; + expect(gauge["Out Of Tolerance"]).toBeGreaterThan(0) + } + } + expect(anyOOT).toBeTruthy(); + } + }) +}); \ No newline at end of file