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