Calculate out of Tolerance

This commit is contained in:
Tyrel Souza 2023-10-20 11:49:36 -04:00
parent 44c3bcb8fc
commit 9cd2c8c29d
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
2 changed files with 28 additions and 4 deletions

View File

@ -11,7 +11,7 @@ const delta = (index, value, masterValues) => {
return Math.abs(masterValues[index]["Low Limit"] - value); 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 accuracy = accuracy / 100.0; // Comes in as Percent
const transducerData = []; 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 // 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) => ({ transducerInfo["Gauge Reading"] = transducerInfo["Gauge Reading"].map((v, idx) => ({
Value: v, Value: v,
"In Range": inRange(idx, v, transducerInfo["Master Value"]), "In Range": inRange(idx, v, transducerInfo["Master Value"]),
Delta: delta(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); transducerData.push(transducerInfo);
} }

View File

@ -4,8 +4,6 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
import parseTransducer from "../Transducer" import parseTransducer from "../Transducer"
// const file = fs.readFileSync("src/parsers/__tests__/transducer_verify.txt", 'utf8')
function readFiles(dir) { function readFiles(dir) {
const files = []; const files = [];
@ -29,7 +27,7 @@ describe("Test for all files", () => {
let files = readFiles("src/parsers/__tests__/transducer_verify/"); let files = readFiles("src/parsers/__tests__/transducer_verify/");
for (const file of files) { for (const file of files) {
test(`Can parse ${file.name}`, () => { 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) expect(transducers.length).toBeGreaterThan(0)
for (const transducer of transducers) { 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();
}
})
});