Skip to content

Instantly share code, notes, and snippets.

@rajeshpv
Last active May 15, 2021 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeshpv/bbba48670bd8fa8c6266a5bb5eff1837 to your computer and use it in GitHub Desktop.
Save rajeshpv/bbba48670bd8fa8c6266a5bb5eff1837 to your computer and use it in GitHub Desktop.
PSI Conversions SA-5015 jira has details
function calcPsi(read, loc) {
const readVal = read.v * read.mul;
const h = loc.elevation + loc.elevationOffset;
return calcPsiDirect(read.m, h, readVal);
}
function calcPsiDirect(uom, h, readVal){
let newVal = -1;
switch (uom) {
case "PSIA":
newVal = readVal - (PsiPascElev(h) * 0.000145033);
break;
case "PSI":
newVal = readVal;
break;
case "BARA":
newVal = readVal - (PsiPascElev(h) * Math.pow(10, -5));
break;
case "BAR":
newVal = readVal * 14.5038;
break;
} //end-switch
return newVal;
}
function PsiPascElev(h) {
let beforeExp = (1 - (2.25577 * Math.pow(10, -5) * h));
return Math.pow(beforeExp, 5.25588) * 101325;
}
let readRec = {
"v": 207.6,
"inputId": 2,
"mul": 1,
"m": "PSIA"
};
let loc = {
"lat": 35.86583,
"lng": -78.85754,
"elevation": 108,
"elevationOffset": -1.2192
};
let psi = calcPsi(readRec, loc);
console.log(psi);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment