Skip to content

Commit

Permalink
CI bugfixes
Browse files Browse the repository at this point in the history
Fix linting error
Move code to separate function
Scientific output only on small/large _absolute_ value
  • Loading branch information
mducle committed Nov 19, 2024
1 parent 0cc5f24 commit 4715184
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions app/components/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import React, { useState } from "react";
const grafana_stub =
"https://shadow.nd.rl.ac.uk/grafana/d/wMlwwaHMk/block-history?viewPanel=2&orgId=1&var-block=";

function numberFormatter(value: string | number | undefined) {
var nValue: number = value == undefined ? NaN : +value
if (isNaN(nValue)) {
return value
} else {
if (nValue != 0 && (Math.abs(nValue) < 0.001 || Math.abs(nValue) > 10000)) {
return nValue.toExponential()
} else {
return nValue.toPrecision()
}
}
}

export default function Block({
pv,
instName,
Expand Down Expand Up @@ -36,19 +49,6 @@ export default function Block({
pvChangedIndicator.classList.add("text-transparent");
}, 2000);
}
var formattedValue = currentValue
if (typeof currentValue === 'string') {
var formattedValue: number = +currentValue
}
if (isNaN(formattedValue)) {
var formattedValue = currentValue
} else {
if (pv.units != null && formattedValue != 0 && (formattedValue < 0.001 || formattedValue > 10000)) {
var formattedValue = formattedValue.toExponential()
} else {
var formattedValue = formattedValue.toPrecision()
}
}

const minimum_date_to_be_shown = 631152000; // This is what PVWS thinks epoch time is for some reason. don't bother showing it as the instrument wasn't running EPICS on 01/01/1990
return (
Expand Down Expand Up @@ -82,7 +82,7 @@ export default function Block({
className={pv.severity != "NONE" ? "text-red-400" : ""}
>
{showAdvanced && "Readback: "}
{formattedValue} {pv.units != null && pv.units}
{numberFormatter(pv.value)} {pv.units != null && pv.units}
</span>
<svg
id={pv.human_readable_name + "_CIRCLE"}
Expand Down

0 comments on commit 4715184

Please sign in to comment.