Now with unit conversions

This commit is contained in:
Daniel Dunn
2025-04-03 05:32:47 -06:00
parent 6b27595a89
commit 70480d0920
4 changed files with 88 additions and 15 deletions

View File

@@ -7,6 +7,8 @@ export interface GenericCalcType {
title: string;
formula: string;
unit: string;
// Si prefix default
defaultPrefix?: string;
}[];
selections?: {
title: string;
@@ -20,7 +22,7 @@ export interface GenericCalcType {
name: string;
title: string;
unit: string;
defaultPrefix?: string;
// If absence, assume it's the default target var
default?: number;
}[];

View File

@@ -59,7 +59,8 @@ const voltagedropinwire: GenericCalcType = {
name: 'p',
title: 'Resistivity',
unit: 'Ω/m3',
default: 1
default: 1,
defaultPrefix: 'n'
},
{
name: 'x',

View File

@@ -13,7 +13,6 @@ import React, { useState } from 'react';
import ToolContent from '@components/ToolContent';
import { ToolComponentProps } from '@tools/defineTool';
import ToolTextResult from '@components/result/ToolTextResult';
import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
import NumericInputWithUnit from '@components/input/NumericInputWithUnit';
import { UpdateField } from '@components/options/ToolOptions';
import { InitialValuesType } from './types';
@@ -51,7 +50,7 @@ export default async function makeTool(
}>({});
const [extraOutputs, setExtraOutputs] = useState<{
[key: string]: string;
[key: string]: number;
}>({});
const updateVarField = (
@@ -240,8 +239,8 @@ export default async function makeTool(
<TableCell>
<NumericInputWithUnit
title={variable.title}
sx={{ width: '25ch' }}
description={valsBoundToPreset[variable.name] || ''}
defaultPrefix={variable.defaultPrefix}
value={{
value:
values.outputVariable === variable.name
@@ -287,7 +286,17 @@ export default async function makeTool(
{calcData.extraOutputs?.map((extraOutput) => (
<TableRow key={extraOutput.title}>
<TableCell>{extraOutput.title}</TableCell>
<TableCell>{extraOutputs[extraOutput.title]}</TableCell>
<TableCell>
<NumericInputWithUnit
title={extraOutput.title}
disabled={true}
defaultPrefix={extraOutput.defaultPrefix}
value={{
value: extraOutputs[extraOutput.title],
unit: extraOutput.unit
}}
></NumericInputWithUnit>
</TableCell>
<TableCell>{extraOutput.unit}</TableCell>
<TableCell></TableCell>
</TableRow>
@@ -345,7 +354,9 @@ export default async function makeTool(
const result: nerdamer.Expression = expr.evaluate();
if (result) {
extraOutputs[extraOutput.title] = result.toDecimal();
extraOutputs[extraOutput.title] = parseFloat(
result.toDecimal()
);
}
}
}