make the Gauge Readings look the same format in the arrays
This commit is contained in:
parent
ec4eb418d5
commit
9b181287eb
@ -3,16 +3,18 @@ import {ONE_NEW_LINE, TWO_NEW_LINES} from "./utils/constants.js";
|
||||
const isInRange = (value, masterValue) => {
|
||||
return (masterValue["Low Limit"] <= value && value <= masterValue["High Limit"]);
|
||||
}
|
||||
const calculateDelta = (value, masterValue) => {
|
||||
return Math.abs(masterValue["Low Limit"] - value);
|
||||
const calculateDelta = (value, lowLimit) => {
|
||||
return Math.abs(lowLimit - value);
|
||||
}
|
||||
function outOfTolerance(reading) {
|
||||
function outOfTolerance(readings) {
|
||||
// Calculate Out of Tolerances
|
||||
for (const reading of reading) {
|
||||
for (const reading of readings) {
|
||||
reading["Out Of Tolerance"] = 0;
|
||||
if (!reading["In Range"]) {
|
||||
reading["Out Of Tolerance"] = reading["Delta"];
|
||||
if (reading["In Range"]) {
|
||||
// We are good.
|
||||
continue
|
||||
}
|
||||
reading["Out Of Tolerance"] = reading["Delta"];
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,10 +53,11 @@ const KEEP = {
|
||||
"Pressure Transducer": ["Instrument Pressure", "Master Value"],
|
||||
};
|
||||
|
||||
function deviceDataToObj(lines, keep, name) {
|
||||
function deviceDataToObj(lines, name, kind) {
|
||||
const keep = KEEP[kind]
|
||||
const deviceData = {
|
||||
"Name":name,
|
||||
"Master Values":[],
|
||||
"Master Values":{},
|
||||
"Gauge Reading": []
|
||||
};
|
||||
for (const line of lines) {
|
||||
@ -65,28 +68,30 @@ function deviceDataToObj(lines, keep, name) {
|
||||
deviceData[keyTrimmed] = value.trim();
|
||||
}
|
||||
}
|
||||
|
||||
for (const start of keep) {
|
||||
if (keyTrimmed.startsWith(start)) {
|
||||
if (keyTrimmed.includes("Master")) {
|
||||
// Master values occur twice, but due to the fact that this is
|
||||
// editing KeyValues not Indexes, it will replace
|
||||
// the masters with the second instance of these.
|
||||
// No manual checks to skip the first.
|
||||
for (const start of keep) {
|
||||
if (keyTrimmed.startsWith(start)) {
|
||||
if (keyTrimmed.includes("Master")) {
|
||||
deviceData["Master Values"].push(
|
||||
{
|
||||
"Value": value.trim()
|
||||
}
|
||||
)
|
||||
deviceData["Master Values"][keyTrimmed] = {"v": value.trim()}
|
||||
} else {
|
||||
deviceData["Gauge Reading"].push(
|
||||
{
|
||||
"Value": value.trim()
|
||||
}
|
||||
)
|
||||
deviceData["Gauge Reading"].push({"Value": value.trim()})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Because of the annoyances of two entries,
|
||||
// Loop through, merging the objects and deleting the old
|
||||
for (let i in deviceData["Gauge Reading"]) {
|
||||
i = parseInt(i)
|
||||
|
||||
const key = (kind === "Mass Flow Trans") ? `Master Reading ${i+1}` : `Master Value ${i+1}`
|
||||
deviceData["Gauge Reading"][i]["Master Value"] = deviceData["Master Values"][key]["v"]
|
||||
}
|
||||
delete deviceData["Master Values"]
|
||||
return deviceData;
|
||||
}
|
||||
|
||||
@ -100,23 +105,21 @@ function calculateLimitsAndTolerances(calibrationDatum, accuracy) {
|
||||
}
|
||||
|
||||
let limit = accuracy * value * 1000
|
||||
for (const mv of calibrationDatum["Master Values"]) {
|
||||
const reading = parseInt(mv["Value"].split(" ")[0]) * 1000;
|
||||
mv["Low Limit"] = reading - limit
|
||||
mv["High Limit"] = reading + limit
|
||||
mv["Value"] = reading
|
||||
for (const gr of calibrationDatum["Gauge Reading"]) {
|
||||
const master_value = parseInt(gr["Master Value"].split(" ")[0]) * 1000;
|
||||
gr["Low Limit"] = master_value - limit
|
||||
gr["Master Value"] = master_value
|
||||
gr["High Limit"] = master_value + limit
|
||||
}
|
||||
for (const i in calibrationDatum["Gauge Reading"]) {
|
||||
let gr = calibrationDatum["Gauge Reading"][i];
|
||||
const mv = calibrationDatum["Master Values"][i];
|
||||
for (const gr of calibrationDatum["Gauge Reading"]) {
|
||||
const [val, unit] = gr["Value"].split(" ")
|
||||
const reading = parseInt(val) * 1000;
|
||||
|
||||
gr["Value"] = reading; // Update the original, ignoring the units
|
||||
gr["Unit"] = unit;
|
||||
gr["In Range"] = isInRange(reading, mv)
|
||||
gr["Delta"] = calculateDelta(reading, mv)
|
||||
|
||||
gr["In Range"] = isInRange(reading, gr["Master Value"])
|
||||
gr["Delta"] = calculateDelta(reading, gr["Low Limit"])
|
||||
console.log(0)
|
||||
}
|
||||
outOfTolerance(calibrationDatum["Gauge Reading"])
|
||||
}
|
||||
@ -135,7 +138,7 @@ const parseCalibrationData = (text, accuracy) => {
|
||||
lines.shift(); // Remove "=======" line
|
||||
const deviceName = lines.shift().trim().split(/\s+/).slice(-1)[0].trim();
|
||||
|
||||
calibrationData[blockTitle] = deviceDataToObj(lines, KEEP[blockTitle], deviceName);
|
||||
calibrationData[blockTitle] = deviceDataToObj(lines, deviceName, blockTitle);
|
||||
}
|
||||
|
||||
for (const bt of blockTitles) {
|
||||
@ -151,7 +154,7 @@ function parseHardwareCalibration(content, accuracy) {
|
||||
const instrumentInfo = parseInstrumentInfo(instrument);
|
||||
const portData = parsePorts(ports, accuracy);
|
||||
|
||||
return {instrument: instrumentInfo, calibration: portData};
|
||||
return {"Instrument": instrumentInfo, "Calibration": portData};
|
||||
}
|
||||
|
||||
export default function ParseHardwareCalibration(content, accuracy) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import {ONE_NEW_LINE, TWO_NEW_LINES} from "./utils/constants.js";
|
||||
import {tr} from "date-fns/locale";
|
||||
|
||||
const isInRange = (index, value, masterValues) => {
|
||||
return (masterValues[index]["Low Limit"] <= value && value <= masterValues[index]["High Limit"]);
|
||||
@ -55,6 +56,24 @@ function outOfTolerance(transducerInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
function doMerge(transducerInfo) {
|
||||
let idx = 0;
|
||||
while (transducerInfo["Master Value"].length > 0) {
|
||||
const mv = transducerInfo["Master Value"].shift()
|
||||
transducerInfo["Gauge Reading"][idx] = {...transducerInfo["Gauge Reading"][idx], ...mv}
|
||||
idx++;
|
||||
}
|
||||
delete transducerInfo["Master Value"] // clean up
|
||||
}
|
||||
|
||||
function refactorData(transducerInfo) {
|
||||
const {['Gauge Reading']: gr, ...instrument} = transducerInfo
|
||||
return {
|
||||
"Instrument": instrument,
|
||||
"Gauge Reading": gr
|
||||
}
|
||||
}
|
||||
|
||||
function parseSection(section, accuracy) {
|
||||
const lines = section.trim().split(ONE_NEW_LINE);
|
||||
const filteredLines = lines.filter((line) => !line.startsWith("==") && line !== "|| Transducer Verify Report ||");
|
||||
@ -77,6 +96,7 @@ function parseSection(section, accuracy) {
|
||||
[, value, unit] = match;
|
||||
value = parseInt(value);
|
||||
}
|
||||
unit = unit.toUpperCase()
|
||||
if (unit === "SCCM" || unit === "LPM") {
|
||||
// SCCM and LPM are Flow
|
||||
transducerType = "Flow";
|
||||
@ -91,15 +111,15 @@ function parseSection(section, accuracy) {
|
||||
|
||||
// Create an object to store the data for each transducer
|
||||
const transducerInfo = {
|
||||
Accuracy: accuracy,
|
||||
Value: value,
|
||||
Unit: unit,
|
||||
"Accuracy": accuracy,
|
||||
"Value": value,
|
||||
"Unit": unit,
|
||||
"Part Number": partNumber,
|
||||
"Limit ABS": value * accuracy * 1000,
|
||||
"Transducer Name": transducerName,
|
||||
"Transducer Type": transducerType,
|
||||
"Gauge Reading": [],
|
||||
"Master Value": [],
|
||||
"Gauge Reading": [],
|
||||
"Verify Date": "",
|
||||
"Verify Time": "",
|
||||
};
|
||||
@ -115,7 +135,8 @@ function parseSection(section, accuracy) {
|
||||
}));
|
||||
|
||||
outOfTolerance(transducerInfo);
|
||||
return transducerInfo;
|
||||
doMerge(transducerInfo);
|
||||
return refactorData(transducerInfo);
|
||||
}
|
||||
|
||||
function parseTransducer(content, accuracy) {
|
||||
|
@ -9,13 +9,7 @@ describe("Test for all files", () => {
|
||||
for (const file of files) {
|
||||
test(`Can parse ${file.name}`, () => {
|
||||
const calibrations = ParseHardwareCalibration(file.content, 0.05);
|
||||
console.log(calibrations.calibration)
|
||||
console.log(calibrations)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
? With hardware - is it still accuracy limits are 0.05% (or w.e specified) of `3LPM`
|
||||
|
||||
*/
|
@ -8,16 +8,14 @@ describe("Test for all files", () => {
|
||||
for (const file of files) {
|
||||
test(`Can parse ${file.name}`, () => {
|
||||
const transducers = ParseTransducer(file.content, 0.05)
|
||||
console.log(transducers[0]["Master Value"])
|
||||
expect(transducers.length).toBeGreaterThan(0)
|
||||
for (const transducer of transducers) {
|
||||
expect(transducer).toHaveProperty("Part Number")
|
||||
expect(transducer).toHaveProperty("Transducer Name")
|
||||
expect(transducer["Instrument"]).toHaveProperty("Part Number")
|
||||
expect(transducer["Instrument"]).toHaveProperty("Transducer Name")
|
||||
expect(transducer).toHaveProperty("Gauge Reading")
|
||||
expect(transducer).toHaveProperty("Master Value")
|
||||
expect(transducer).not.toHaveProperty("Master Value")
|
||||
|
||||
expect(transducer["Gauge Reading"].length).toBeGreaterThan(1);
|
||||
expect(transducer["Master Value"].length).toBe(transducer["Gauge Reading"].length);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -28,14 +26,14 @@ describe("Testing actual calculations", () => {
|
||||
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;
|
||||
let atLeastOneOOT = false;
|
||||
for (const gauge of transducer["Gauge Reading"]) {
|
||||
if (!gauge["In Range"]) {
|
||||
anyOOT = true;
|
||||
atLeastOneOOT = true;
|
||||
expect(gauge["Out Of Tolerance"]).toBeGreaterThan(0)
|
||||
}
|
||||
}
|
||||
expect(anyOOT).toBeTruthy();
|
||||
expect(atLeastOneOOT).toBeTruthy();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user