working with Isaac on what's required

This commit is contained in:
Tyrel Souza 2024-07-10 22:49:06 -04:00
parent 814ee9f653
commit 5acec3e7e6
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
15 changed files with 248 additions and 187 deletions

View File

@ -11,8 +11,10 @@
"dependencies": { "dependencies": {
"@mdi/font": "^7.2.96", "@mdi/font": "^7.2.96",
"@vuepic/vue-datepicker": "^7.0.0", "@vuepic/vue-datepicker": "^7.0.0",
"concat-stream": "^2.0.0",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"html2pdf.js": "^0.10.1", "html2pdf.js": "^0.10.1",
"toml": "^3.0.0",
"vls": "^0.8.5", "vls": "^0.8.5",
"volar-service-vetur": "^0.0.13", "volar-service-vetur": "^0.0.13",
"vue": "^3.3.4", "vue": "^3.3.4",

View File

@ -0,0 +1,30 @@
[Settings]
tolerance = 0.05
[[CalibrationDevices]]
name = "Menzer1"
model = "CPC 4000"
serial = "12345"
certid = "1234, 3454, 5555"
caldate = "5/8/24"
[[CalibrationDevices]]
name = "Blackbelt"
model = "CPC 4000"
serial = "12345"
certid = "1234, 3454, 5555"
caldate = "5/8/24"
[[CalibrationDevices]]
name = "Alicat"
model = "CPC 4000"
serial = "12345"
certid = "1234, 3454, 5555"
caldate = "5/8/24"
[[CalibrationDevices]]
name = "Alicat2"
model = "CPC 4000"
serial = "12345"
certid = "1234, 3454, 5555"
caldate = "5/8/24"

View File

@ -5,8 +5,7 @@
<h3>Primary Device</h3> <h3>Primary Device</h3>
<select name="primary_device" v-model="primary_device" required id="id_report_type"> <select name="primary_device" v-model="primary_device" required id="id_report_type">
<option value="-" selected>----Primary-----</option> <option value="-" selected>----Primary-----</option>
<option value="Menzer1">Menzer1</option> <option v-for="option in calibrationDevices" :value="option.name" :key="option.name">{{option.name}}</option>
<option value="Blackbelt">Blackbelt</option>
</select> </select>
<h3>Calibration Date</h3> <h3>Calibration Date</h3>
<div class="date-picker"> <div class="date-picker">
@ -17,8 +16,7 @@
<select name="secondary_device" v-model="secondary_device" required id="id_report_type"> <select name="secondary_device" v-model="secondary_device" required id="id_report_type">
<option value="-" selected>----Secondary-----</option> <option value="-" selected>----Secondary-----</option>
<option value="Menzer1">Menzer1</option> <option v-for="option in calibrationDevices" :value="option.name" :key="option.name">{{option.name}}</option>
<option value="Blackbelt">Blackbelt</option>
</select> </select>
<h3>Calibration Date</h3> <h3>Calibration Date</h3>
@ -29,13 +27,27 @@
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, defineEmits, watchEffect } from "vue"; import {ref, defineEmits, watchEffect, computed, onMounted} from "vue";
import VueDatePicker from "@vuepic/vue-datepicker"; import VueDatePicker from "@vuepic/vue-datepicker";
import "@vuepic/vue-datepicker/dist/main.css"; import "@vuepic/vue-datepicker/dist/main.css";
import {parse} from "toml";
const setCalibrationDevices = async () => {
const tomlContent = (await import(`../../SETTINGS.toml?raw`)).default;
const parsed = parse(tomlContent);
calibrationDevices.value = [];
for (const [name, settings] of Object.entries(parsed.CalibrationDevices)) {
calibrationDevices.value.push({name, ...settings});
}
console.log(calibrationDevices);
return calibrationDevices;
}
const primary_device = ref(""), const primary_device = ref(""),
secondary_device = ref(""), secondary_device = ref(""),
calibrationDevices = ref(null),
primary_calibration_date = ref(new Date()), primary_calibration_date = ref(new Date()),
secondary_calibration_date = ref(new Date()); secondary_calibration_date = ref(new Date());
@ -50,4 +62,11 @@ watchEffect(() => {
secondary_calibration_date, secondary_calibration_date,
}); });
}); });
onMounted (async () => {
console.log("SETTING")
await setCalibrationDevices()
console.log("SETTED")
})
</script> </script>

View File

@ -35,6 +35,12 @@
<input type="text" name="technician" maxlength="256" v-model="technician" required id="id_technician"> <input type="text" name="technician" maxlength="256" v-model="technician" required id="id_technician">
</td> </td>
</tr> </tr>
<tr>
<td>Issuer</td>
<td>
<input type="text" name="issuer" maxlength="256" v-model="issuer" required id="id_issuer">
</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -48,7 +54,8 @@ const
customer_name = ref(""), customer_name = ref(""),
onsite_cal = ref(false), onsite_cal = ref(false),
control_doc = ref(""), control_doc = ref(""),
technician = ref("") technician = ref(""),
issuer = ref("")
const emit = defineEmits(); const emit = defineEmits();
watchEffect(() => { watchEffect(() => {
@ -57,6 +64,7 @@ watchEffect(() => {
onsite_cal, onsite_cal,
control_doc, control_doc,
technician, technician,
issuer,
}); });
}); });
</script> </script>

View File

@ -5,9 +5,9 @@
<table class="table"> <table class="table">
<tbody> <tbody>
<tr> <tr>
<td>Accuracy</td> <td>Tolerance</td>
<td> <td>
<input type="number" name="accuracy" step="0.001" v-model="accuracy" required id="id_accuracy"> <input type="number" name="tolerance" step="0.001" v-model="tolerance" required id="id_tolerance">
</td> </td>
</tr> </tr>
<tr> <tr>
@ -40,7 +40,7 @@
import { ref, defineEmits, watchEffect } from 'vue' import { ref, defineEmits, watchEffect } from 'vue'
const const
accuracy = ref(0.05), tolerance = ref(0.05),
pressure = ref(14.7), pressure = ref(14.7),
temperature = ref(50.0), temperature = ref(50.0),
humidity = ref(50.0) humidity = ref(50.0)
@ -48,7 +48,7 @@ const
const emit = defineEmits(); const emit = defineEmits();
watchEffect(() => { watchEffect(() => {
emit("environment-form", { emit("environment-form", {
accuracy, tolerance,
pressure, pressure,
temperature, temperature,
humidity, humidity,

View File

@ -8,7 +8,7 @@
<br> <br>
<div :class="{ hide: hide }" class="px666 scroll-pdf"> <div :class="{ hide: hide }" class="px666 scroll-pdf">
<div id="pdf" ref="document"> <div id="pdf" ref="document">
<div v-for="(table, index) in tables" :key="index"> <div v-for="(table, index) in pages" ref="page" :key="index">
<div class="header"> <div class="header">
<div class="flex-container"> <div class="flex-container">
<div class="column pct-25"> <div class="column pct-25">
@ -16,8 +16,9 @@
</div> </div>
<div class="column pct-50"> <div class="column pct-50">
<div>Customer: {{ props.customer?.customer_name }}</div> <div>Customer: {{ props.customer?.customer_name }}</div>
<div>Onsite cal (yes/no): {{ onsite() }}</div> <div>Onsite cal (yes/no): {{ onsite }}</div>
<div>Control Doc#: {{ props.customer?.control_doc }}</div> <div>Control Doc#: {{ props.customer?.control_doc }}</div>
<div>Issuer: {{ props.customer?.issuer }}</div>
<div>Technician: {{ props.customer?.technician }}</div> <div>Technician: {{ props.customer?.technician }}</div>
</div> </div>
<div class="column pct-25"> <div class="column pct-25">
@ -62,9 +63,9 @@
<span class="label">Serial# :</span <span class="label">Serial# :</span
>{{ props.calibration?.serial }} >{{ props.calibration?.serial }}
</div> </div>
<div><span class="label">Cal Date :</span>{{ c_date() }}</div> <div><span class="label">Cal Date :</span>{{ calibrationDate }}</div>
<div> <div>
<span class="label">Cal Due Date :</span>{{ c_due_date() }} <span class="label">Cal Due Date :</span>{{ calibrationDueDate }}
</div> </div>
<div> <div>
<span class="label">Cert ID :</span <span class="label">Cert ID :</span
@ -72,9 +73,10 @@
</div> </div>
</div> </div>
<div class="column pct-33"> <div class="column pct-33">
<div><span class="label">Cal Date :</span>{{ i_date() }}</div> <div><span class="label">Issue Date :</span>{{ issueDate }}</div>
<div><span class="label">Cal Date :</span>{{ instrumentDate }}</div>
<div> <div>
<span class="label">Cal Due Date :</span>{{ i_due_date() }} <span class="label">Cal Due Date :</span>{{ instrumentDueDate }}
</div> </div>
<div><span class="ul">Environmental Data</span></div> <div><span class="ul">Environmental Data</span></div>
<div> <div>
@ -95,18 +97,19 @@
<br/> <br/>
<!-- End InstrumentInfo --> <!-- End InstrumentInfo -->
<!-- As Found --> <!-- As Found -->
<ReadingTable :as_found="table.as_found" /> <ReadingTable :table="table.asFound" :asFound=true />
<br/> <br/>
<!-- As Left --> <!-- As Left -->
<ReadingTable :as_left="table.as_left" /> <ReadingTable :table="table.asLeft" :asLeft=true />
<!-- End Instruments--> <!-- End Instruments-->
<div class="box"> <hr class=".hide" />
<div class="box" ref="page" >
<p> <p>
Secondary Cal Device (For Environmental Data): EXTECH S/N A23050006 Secondary Cal Device (For Environmental Data): EXTECH S/N A23050006
Cert # 1535483 07/24/23 (Cal Date) (Precision Psychrometer) Cert # 1535483 07/24/23 (Cal Date) (Precision Psychrometer)
</p> </p>
<p> <p>
Uncertainty Statement: The accuracy of measurement is determined by Uncertainty Statement: The tolerance of measurement is determined by
the standards uncertainty, with a coverage factor of k=2 (confidence the standards uncertainty, with a coverage factor of k=2 (confidence
of roughly 95%). of roughly 95%).
</p> </p>
@ -138,11 +141,11 @@ const props = defineProps({
calibration: Object, calibration: Object,
}); });
const onsite = () => { const onsite = computed(() => {
return props.customer?.onsite_cal ? "Yes" : "No"; return props.customer?.onsite_cal ? "Yes" : "No";
}; });
const i_date = () => { const instrumentDate = computed(() => {
if (!props.instrument?.date) { if (!props.instrument?.date) {
return return
} }
@ -151,10 +154,18 @@ const i_date = () => {
const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1 const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1
const day = d.getDate().toString().padStart(2, "0"); const day = d.getDate().toString().padStart(2, "0");
return `${year}-${month}-${day}`; return `${year}-${month}-${day}`;
}; });
const issueDate = computed(() => {
const d = new Date();
const year = d.getFullYear();
const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1
const day = d.getDate().toString().padStart(2, "0");
return `${year}-${month}-${day}`;
});
const i_due_date = () => { const instrumentDueDate = computed(() => {
if (!props.instrument?.due_date) { if (!props.instrument?.due_date) {
return; return;
} }
@ -163,9 +174,9 @@ const i_due_date = () => {
const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1 const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1
const day = d.getDate().toString().padStart(2, "0"); const day = d.getDate().toString().padStart(2, "0");
return `${year}-${month}-${day}`; return `${year}-${month}-${day}`;
}; });
const c_date = () => { const calibrationDate = computed(() => {
if (!props.calibration?.date) { if (!props.calibration?.date) {
return; return;
} }
@ -174,8 +185,9 @@ const c_date = () => {
const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1 const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1
const day = d.getDate().toString().padStart(2, "0"); const day = d.getDate().toString().padStart(2, "0");
return `${year}-${month}-${day}`; return `${year}-${month}-${day}`;
}; });
const c_due_date = () => {
const calibrationDueDate = computed(() => {
if (!props.calibration?.due_date) { if (!props.calibration?.due_date) {
return; return;
} }
@ -184,7 +196,49 @@ const c_due_date = () => {
const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1 const month = (d.getMonth() + 1).toString().padStart(2, "0"); // Month is zero-based, so we add 1
const day = d.getDate().toString().padStart(2, "0"); const day = d.getDate().toString().padStart(2, "0");
return `${year}-${month}-${day}`; return `${year}-${month}-${day}`;
}; });
const pages = computed(() => {
let pages = []
const actions = {
"Transducer Verify": ParseTransducer,
"Hardware Calibration": ParseHardwareCalibration,
}
// debugger
if (props.upload?.files?.length > 0) {
const acc = props.environment.tolerance
const parse = actions[props.upload.report_type]
for (const idx in props.upload.files) {
const page = {
asFound: [],
asLeft: []
}
const file = props.upload.files[idx]
const content = parse(file["value"], acc)
console.log("content", content)
// if first file is both, put as found as left
// if first file is as found
// next file is as left
if (file.kind === "found") {
page.asFound = [...page.asFound, ...content]
} else if (file.kind === "left") {
page.asLeft = [...page.asLeft, ...content]
} else if (file.kind === "both") {
page.asFound = [...page.asFound, ...content]
page.asLeft = [...page.asLeft, ...content]
}
pages.push(page)
console.log(pages)
}
}
return pages;
});
const exportToPDF = () => { const exportToPDF = () => {
if (props.upload.files.length > 0) { if (props.upload.files.length > 0) {
@ -192,36 +246,16 @@ const exportToPDF = () => {
var opt = { var opt = {
margin: 0.4, margin: 0.4,
filename: `${props.instrument.model}_${i_date()}.pdf`, filename: `${props.instrument.model}_${instrumentDate}.pdf`,
image: {type: "jpeg", quality: 0.98}, image: {type: "jpeg", quality: 0.98},
html2canvas: {scale: 2}, html2canvas: {scale: 2},
pagebreak: { after: ['hr']},
jsPDF: {unit: "in", format: "letter", orientation: "portrait"}, jsPDF: {unit: "in", format: "letter", orientation: "portrait"},
}; };
html2pdf().from(element).set(opt).save(); html2pdf().from(element).set(opt).save();
} }
}; };
const tables = computed(() => {
let content = ""
let tables = []
if (props.upload?.files?.length > 0) {
const acc = props.environment.accuracy
if (props.upload.report_type === "Transducer Verify") {
for (const idx in props.upload.files) {
content = ParseTransducer(props.upload.files[idx]["value"], acc)
tables = [...tables, ...content]
}
} else if (props.upload.report_type === "Hardware Calibration") {
for (const idx in props.upload.files) {
content = ParseHardwareCalibration(props.upload.files[idx]["value"], acc)
tables = [...tables, ...[content]]
}
}
}
return tables;
})
</script> </script>

View File

@ -5,93 +5,22 @@
<thead> <thead>
<tr> <tr>
<th>Gauge Reading</th> <th>Gauge Reading</th>
<th>Accuracy (+/- FS)</th> <th>Tolerance (+/- FS)</th>
<th>Low Limit</th> <th>Low Limit</th>
<th>High Limit</th> <th>High Limit</th>
<th>As Found (units)</th> <th>{{as_header}}</th>
<th>OOT</th> <th>OOT</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <!-- {"Value":0,"In Range":true,"Delta":57.5,"Out Of Tolerance":0,"Low Limit":-57.5,"Master Value":0,"High Limit":57.5} -->
<td>HI?</td> <tr v-for="row in table">
<td>TBD</td> <td>{{row["Value"]}}</td>
<td>TBD</td> <td>{{row["Tolerance"]}}</td>
<td>TBD</td> <td>{{row["Low Limit"]}}</td>
<td>TBD</td> <td>{{row["High Limit"]}}</td>
<td>TBD</td> <td>{{row["As"]}}</td>
</tr> <td>{{row["Out of Tolerance"]}}</td>
<tr>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
</tr>
<tr>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
</tr>
<tr>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
<td>TBD</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -102,9 +31,20 @@
import {defineProps, ref} from "vue"; import {defineProps, ref} from "vue";
const props = defineProps({ const props = defineProps({
as_found: Object, table: Array,
as_left: Object, asFound: Boolean,
asLeft: Boolean
}); });
const as_header = computed(()=> {
if (asFound) {
return "As Found (units)"
}
if (asLeft) {
return "As Left (units)"
}
})
</script> </script>
<style scoped> <style scoped>
@media print { @media print {

View File

@ -2,15 +2,14 @@
<div class="flextainer"> <div class="flextainer">
<div class="left"> <div class="left">
<div class="grid"> <div class="grid">
<div class="grid-item item card">
<UploadForm @uploadForm="uploadForm" />
</div>
<div class="grid-item item card"> <div class="grid-item item card">
<CustomerForm @customerForm="customerForm" /> <CustomerForm @customerForm="customerForm" />
<EnvironmentForm @environmentForm="environmentForm" /> <EnvironmentForm @environmentForm="environmentForm" />
</div> </div>
<div class="grid-item item card">
<UploadForm @uploadForm="uploadForm" />
</div>
</div>
<div class="grid">
<div class="grid-item item card"> <div class="grid-item item card">
<InstrumentForm <InstrumentForm
v-if="!show_new_instrument" v-if="!show_new_instrument"

View File

@ -1,7 +0,0 @@
module.exports = {
// ... other Jest configurations ...
transform: {
'^.+\\.js$': 'babel-jest',
},
};

View File

@ -31,7 +31,7 @@ const parseInstrumentInfo = (text) => {
return instrumentInfo; return instrumentInfo;
} }
const parsePorts = (text, accuracy) => { const parsePorts = (text, tolerance) => {
text += "\n\n"; // Ensure extra newline to match on text += "\n\n"; // Ensure extra newline to match on
const pattern = /(Test Port \d)/g; const pattern = /(Test Port \d)/g;
const matches = text.split(pattern).slice(1); const matches = text.split(pattern).slice(1);
@ -40,7 +40,7 @@ const parsePorts = (text, accuracy) => {
for (let i = 0; i < matches.length; i += 2) { for (let i = 0; i < matches.length; i += 2) {
const port = matches[i]; const port = matches[i];
const calibration = matches[i + 1]; const calibration = matches[i + 1];
portData[port] = parseCalibrationData(calibration, accuracy); portData[port] = parseCalibrationData(calibration, tolerance);
} }
return portData; return portData;
@ -94,18 +94,18 @@ function deviceDataToObj(lines, name, kind) {
return deviceData; return deviceData;
} }
function calculateLimitsAndTolerances(calibrationDatum, accuracy) { function calculateLimitsAndTolerances(calibrationDatum, tolerance) {
let unit = null; let unit = null;
let value = null; let span = null;
const match = calibrationDatum["Name"].match(/([0-9]+)([A-Z]+)/i); const match = calibrationDatum["Name"].match(/([0-9]+)([A-Z]+)/i);
if (match) { if (match) {
[, value, unit] = match; [, span, unit] = match;
value = parseInt(value); span = parseInt(span);
} }
let limit = accuracy * value * 1000 let limit = tolerance * span * 1000
for (const gr of calibrationDatum["Gauge Reading"]) { for (const gr of calibrationDatum["Gauge Reading"]) {
const master_value = parseInt(gr["Master Value"].split(" ")[0]) * 1000; const master_span = parseInt(gr["Master Value"].split(" ")[0]) * 1000;
gr["Low Limit"] = master_value - limit gr["Low Limit"] = master_value - limit
gr["Master Value"] = master_value gr["Master Value"] = master_value
gr["High Limit"] = master_value + limit gr["High Limit"] = master_value + limit
@ -122,7 +122,7 @@ function calculateLimitsAndTolerances(calibrationDatum, accuracy) {
outOfTolerance(calibrationDatum["Gauge Reading"]) outOfTolerance(calibrationDatum["Gauge Reading"])
} }
const parseCalibrationData = (text, accuracy) => { const parseCalibrationData = (text, tolerance) => {
const pattern = /(Mass Flow Trans|Pressure Transducer)\r([\s\S]+?)\r\r/g; const pattern = /(Mass Flow Trans|Pressure Transducer)\r([\s\S]+?)\r\r/g;
const matches = [...text.matchAll(pattern)]; const matches = [...text.matchAll(pattern)];
const calibrationData = {}; const calibrationData = {};
@ -140,13 +140,13 @@ const parseCalibrationData = (text, accuracy) => {
} }
for (const bt of blockTitles) { for (const bt of blockTitles) {
calculateLimitsAndTolerances(calibrationData[bt], accuracy) calculateLimitsAndTolerances(calibrationData[bt], tolerance)
} }
return calibrationData; return calibrationData;
} }
function parseHardwareCalibration(content, accuracy) { function parseHardwareCalibration(content, tolerance) {
// hack because we can't be sure that the file will end in two newlines, so might as well force it to add two // hack because we can't be sure that the file will end in two newlines, so might as well force it to add two
// this way if there's only zero or one, we can still regex match on that // this way if there's only zero or one, we can still regex match on that
content += "\r\n\r\n" content += "\r\n\r\n"
@ -155,12 +155,12 @@ function parseHardwareCalibration(content, accuracy) {
content = content.replace(/\r\n/g, "\r").replace(/\n/g, "\r") content = content.replace(/\r\n/g, "\r").replace(/\n/g, "\r")
const [instrument, ports] = content.split("|| Hardware Calibration Report ||"); const [instrument, ports] = content.split("|| Hardware Calibration Report ||");
const instrumentInfo = parseInstrumentInfo(instrument); const instrumentInfo = parseInstrumentInfo(instrument);
const portData = parsePorts(ports, accuracy); const portData = parsePorts(ports, tolerance);
return {"Instrument": instrumentInfo, "Calibration": portData}; return {"Instrument": instrumentInfo, "Calibration": portData};
} }
export default function ParseHardwareCalibration(content, accuracy) { export default function ParseHardwareCalibration(content, tolerance) {
return parseHardwareCalibration(content, accuracy); return parseHardwareCalibration(content, tolerance);
} }

View File

@ -74,7 +74,7 @@ function refactorData(transducerInfo) {
} }
} }
function parseSection(section, accuracy) { function parseSection(section, tolerance) {
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 ||");
filteredLines.shift(); filteredLines.shift();
@ -84,17 +84,17 @@ function parseSection(section, accuracy) {
let [transducerName, partNumber] = transducerLine.split(/\s\s+/); let [transducerName, partNumber] = transducerLine.split(/\s\s+/);
// Get part number and values // Get part number and values
let value = null; let span = null;
let unit = null; let unit = null;
let transducerType = null; let transducerType = null;
if (partNumber !== "Custom") { if (partNumber !== "Custom") {
partNumber = partNumber.split(" ") partNumber = partNumber.split(" ")
value = partNumber.pop(); span = partNumber.pop();
partNumber = partNumber.join(" "); partNumber = partNumber.join(" ");
const match = value.match(/([0-9]+)([A-Z]+)/i); const match = span.match(/([0-9]+)([A-Z]+)/i);
if (match) { if (match) {
[, value, unit] = match; [, span, unit] = match;
value = parseInt(value); span = parseInt(span);
} }
unit = unit.toUpperCase() unit = unit.toUpperCase()
if (unit === "SCCM" || unit === "LPM") { if (unit === "SCCM" || unit === "LPM") {
@ -111,11 +111,11 @@ 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, "Tolerance": tolerance,
"Value": value, "Span": span,
"Unit": unit, "Unit": unit,
"Part Number": partNumber, "Part Number": partNumber,
"Limit ABS": value * accuracy * 1000, "Limit ABS": span * tolerance * 1000,
"Transducer Name": transducerName, "Transducer Name": transducerName,
"Transducer Type": transducerType, "Transducer Type": transducerType,
"Master Value": [], "Master Value": [],
@ -139,11 +139,11 @@ function parseSection(section, accuracy) {
return refactorData(transducerInfo); return refactorData(transducerInfo);
} }
function parseTransducer(content, accuracy) { function parseTransducer(content, tolerance) {
if (!content.includes("Transducer Verify Report")) { if (!content.includes("Transducer Verify Report")) {
throw new Error("Not a Transducer Verify Report") throw new Error("Not a Transducer Verify Report")
} }
accuracy = accuracy / 100.0; // Comes in as Percent tolerance = tolerance / 100.0; // Comes in as Percent
const transducerData = []; const transducerData = [];
// Split the content into sections based on the blank line // Split the content into sections based on the blank line
@ -151,7 +151,7 @@ function parseTransducer(content, accuracy) {
for (const section of sections) { for (const section of sections) {
// Split each section into lines // Split each section into lines
const transducerInfo = parseSection(section, accuracy); const transducerInfo = parseSection(section, tolerance);
transducerData.push(transducerInfo); transducerData.push(transducerInfo);
} }
@ -159,6 +159,6 @@ function parseTransducer(content, accuracy) {
return transducerData; return transducerData;
} }
export default function ParseTransducer(content, accuracy) { export default function ParseTransducer(content, tolerance) {
return parseTransducer(content, accuracy); return parseTransducer(content, tolerance);
} }

View File

@ -3,10 +3,10 @@ import {readFiles} from "../utils/file_utils.js";
import ParseHardwareCalibration from "../Hardware" import ParseHardwareCalibration from "../Hardware"
// const file = fs.readFileSync("src/parsers/__tests__/hardware_calibration/hardware_calibration.txt", 'utf8') // const file = fs.readFileSync("parsers/__tests__/hardware_calibration/hardware_calibration.txt", 'utf8')
describe("Test for all files", () => { describe("Test for all files", () => {
let files = readFiles("src/parsers/__tests__/hardware_calibration/"); let files = readFiles("parsers/__tests__/hardware_calibration/");
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);
@ -17,7 +17,7 @@ describe("Test for all files", () => {
describe("Testing proper shape", () => { describe("Testing proper shape", () => {
test("It outputs an array of arrays", () => { test("It outputs an array of arrays", () => {
const content = fs.readFileSync("src/parsers/__tests__/hardware_calibration/smallest.txt", 'utf8'); const content = fs.readFileSync("parsers/__tests__/hardware_calibration/smallest.txt", 'utf8');
const calibrations = ParseHardwareCalibration(content, 0.05); const calibrations = ParseHardwareCalibration(content, 0.05);
expect(calibrations).toEqual( expect(calibrations).toEqual(
{ {

View File

@ -4,7 +4,7 @@ import {readFiles} from "../utils/file_utils.js";
describe("Test for all files", () => { describe("Test for all files", () => {
let files = readFiles("src/parsers/__tests__/transducer_verify/"); let files = readFiles("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.content, 0.05) const transducers = ParseTransducer(file.content, 0.05)
@ -23,7 +23,7 @@ describe("Test for all files", () => {
describe("Testing actual calculations", () => { describe("Testing actual calculations", () => {
test("It can detect if out of tolerance", () => { 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 content = fs.readFileSync("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 atLeastOneOOT = false; let atLeastOneOOT = false;
@ -55,13 +55,13 @@ describe("Testing Errors", () => {
describe("Testing proper shape", () => { describe("Testing proper shape", () => {
test("It outputs an array of arrays", () => { test("It outputs an array of arrays", () => {
const content = fs.readFileSync("src/parsers/__tests__/transducer_verify/smallest.txt.txt", 'utf8'); const content = fs.readFileSync("parsers/__tests__/transducer_verify/smallest.txt", 'utf8');
const transducers = ParseTransducer(content, 0.05); const transducers = ParseTransducer(content, 0.05);
expect(transducers).toEqual( expect(transducers).toEqual(
[ [
{ {
Instrument: { Instrument: {
Accuracy: 0.0005, Tolerance: 0.0005,
Value: 115, Value: 115,
Unit: 'PSIA', Unit: 'PSIA',
'Part Number': 'CTS D34-442', 'Part Number': 'CTS D34-442',
@ -85,7 +85,7 @@ describe("Testing proper shape", () => {
}, },
{ {
Instrument: { Instrument: {
Accuracy: 0.0005, Tolerance: 0.0005,
Value: 250, Value: 250,
Unit: 'SCCM', Unit: 'SCCM',
'Part Number': 'CTS A12-221', 'Part Number': 'CTS A12-221',

View File

@ -2147,6 +2147,16 @@ concat-map@0.0.1:
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg== integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==
concat-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-2.0.0.tgz#414cf5af790a48c60ab9be4527d56d5e41133cb1"
integrity sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==
dependencies:
buffer-from "^1.0.0"
inherits "^2.0.3"
readable-stream "^3.0.2"
typedarray "^0.0.6"
config-chain@^1.1.13: config-chain@^1.1.13:
version "1.1.13" version "1.1.13"
resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.13.tgz#fad0795aa6a6cdaff9ed1b68e9dff94372c232f4" resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.13.tgz#fad0795aa6a6cdaff9ed1b68e9dff94372c232f4"
@ -2978,7 +2988,7 @@ inflight@^1.0.4:
once "^1.3.0" once "^1.3.0"
wrappy "1" wrappy "1"
inherits@2: inherits@2, inherits@^2.0.3:
version "2.0.4" version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
@ -4135,6 +4145,15 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==
readable-stream@^3.0.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967"
integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==
dependencies:
inherits "^2.0.3"
string_decoder "^1.1.1"
util-deprecate "^1.0.1"
regenerate-unicode-properties@^10.1.0: regenerate-unicode-properties@^10.1.0:
version "10.1.1" version "10.1.1"
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-10.1.1.tgz#6b0e05489d9076b04c436f318d9b067bba459480" resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-10.1.1.tgz#6b0e05489d9076b04c436f318d9b067bba459480"
@ -4276,7 +4295,7 @@ run-parallel@^1.1.9:
dependencies: dependencies:
queue-microtask "^1.2.2" queue-microtask "^1.2.2"
safe-buffer@^5.0.1, safe-buffer@^5.1.2: safe-buffer@^5.0.1, safe-buffer@^5.1.2, safe-buffer@~5.2.0:
version "5.2.1" version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
@ -4450,6 +4469,13 @@ string-width@^5.0.1, string-width@^5.1.2:
emoji-regex "^9.2.2" emoji-regex "^9.2.2"
strip-ansi "^7.0.1" strip-ansi "^7.0.1"
string_decoder@^1.1.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
dependencies:
safe-buffer "~5.2.0"
"strip-ansi-cjs@npm:strip-ansi@^6.0.1": "strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1" version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
@ -4570,6 +4596,11 @@ to-regex-range@^5.0.1:
dependencies: dependencies:
is-number "^7.0.0" is-number "^7.0.0"
toml@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/toml/-/toml-3.0.0.tgz#342160f1af1904ec9d204d03a5d61222d762c5ee"
integrity sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==
tough-cookie@^2.2.0, tough-cookie@~2.5.0: tough-cookie@^2.2.0, tough-cookie@~2.5.0:
version "2.5.0" version "2.5.0"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2"
@ -4665,6 +4696,11 @@ type-fest@^0.21.3:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37"
integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==
typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==
typescript@^4.9.5: typescript@^4.9.5:
version "4.9.5" version "4.9.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
@ -4713,7 +4749,7 @@ uri-js@^4.2.2:
dependencies: dependencies:
punycode "^2.1.0" punycode "^2.1.0"
util-deprecate@^1.0.2: util-deprecate@^1.0.1, util-deprecate@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==