mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-26 01:19:33 +02:00
Wire gauge calc
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import ohmslaw from './ohms_law';
|
||||
import voltagedropinwire from './wire_voltage_drop';
|
||||
|
||||
export default [ohmslaw];
|
||||
export default [ohmslaw, voltagedropinwire];
|
||||
|
@@ -0,0 +1,59 @@
|
||||
import type { GenericCalcType } from './types';
|
||||
const voltagedropinwire: GenericCalcType = {
|
||||
title: 'Round trip voltage drop in cable',
|
||||
name: 'cable-voltage-drop',
|
||||
formula: 'x = (((p * L) / (A/10**6) ) *2) * I**2',
|
||||
selections: [
|
||||
{
|
||||
title: 'Material',
|
||||
source: 'material-electrical-properties',
|
||||
default: 'Copper',
|
||||
bind: {
|
||||
p: 'resistivity_20c'
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
title: 'Wire Gauge',
|
||||
source: 'wire-gauge',
|
||||
default: '24 AWG',
|
||||
bind: {
|
||||
A: 'area'
|
||||
}
|
||||
}
|
||||
],
|
||||
variables: [
|
||||
{
|
||||
name: 'L',
|
||||
title: 'Length',
|
||||
unit: 'm',
|
||||
default: 1
|
||||
},
|
||||
{
|
||||
name: 'A',
|
||||
title: 'Wire Area',
|
||||
unit: 'mm',
|
||||
default: 1
|
||||
},
|
||||
|
||||
{
|
||||
name: 'I',
|
||||
title: 'Current',
|
||||
unit: 'A',
|
||||
default: 1
|
||||
},
|
||||
{
|
||||
name: 'p',
|
||||
title: 'Resistivity',
|
||||
unit: 'Ω/m3',
|
||||
default: 1
|
||||
},
|
||||
{
|
||||
name: 'x',
|
||||
title: 'Voltage Drop',
|
||||
unit: 'V'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default voltagedropinwire;
|
||||
|
@@ -18,7 +18,7 @@ import { UpdateField } from '@components/options/ToolOptions';
|
||||
import { InitialValuesType } from './types';
|
||||
import type { GenericCalcType } from './data/types';
|
||||
import type { DataTable } from 'datatables';
|
||||
import { getDataTable } from 'datatables';
|
||||
import { getDataTable, dataTableLookup } from 'datatables';
|
||||
|
||||
import nerdamer from 'nerdamer';
|
||||
import 'nerdamer/Algebra';
|
||||
@@ -77,8 +77,6 @@ export default async function makeTool(
|
||||
currentValues: InitialValuesType,
|
||||
updateFieldFunc: UpdateField<InitialValuesType>
|
||||
) => {
|
||||
const newValsBoundToPreset = { ...valsBoundToPreset };
|
||||
|
||||
const newPresets = { ...currentValues.presets };
|
||||
newPresets[selection] = preset;
|
||||
updateFieldFunc('presets', newPresets);
|
||||
@@ -86,7 +84,7 @@ export default async function makeTool(
|
||||
// Clear old selection
|
||||
for (const key in valsBoundToPreset) {
|
||||
if (valsBoundToPreset[key] === selection) {
|
||||
delete newValsBoundToPreset[key];
|
||||
delete valsBoundToPreset[key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,13 +92,19 @@ export default async function makeTool(
|
||||
(sel) => sel.title === selection
|
||||
);
|
||||
|
||||
if (preset != '<custom>') {
|
||||
if (preset && preset != '<custom>') {
|
||||
if (selectionData) {
|
||||
for (const key in selectionData.bind) {
|
||||
newValsBoundToPreset[key] = selection;
|
||||
valsBoundToPreset[key] = selection;
|
||||
|
||||
if (currentValues.outputVariable === key) {
|
||||
handleSelectedTargetChange('', updateFieldFunc);
|
||||
}
|
||||
|
||||
updateVarField(
|
||||
key,
|
||||
dataTables[selectionData.source].data[preset][
|
||||
|
||||
dataTableLookup(dataTables[selectionData.source], preset)[
|
||||
selectionData.bind[key]
|
||||
],
|
||||
currentValues,
|
||||
@@ -108,14 +112,11 @@ export default async function makeTool(
|
||||
);
|
||||
}
|
||||
} else {
|
||||
setValsBoundToPreset(newValsBoundToPreset);
|
||||
throw new Error(
|
||||
`Preset "${preset}" is not valid for selection "${selection}"`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
setValsBoundToPreset(newValsBoundToPreset);
|
||||
};
|
||||
|
||||
calcData.variables.forEach((variable) => {
|
||||
@@ -138,13 +139,16 @@ export default async function makeTool(
|
||||
if (selection.default == '<custom>') return;
|
||||
for (const key in selection.bind) {
|
||||
initialValues.vars[key] = {
|
||||
value:
|
||||
dataTables[selection.source].data[selection.default][
|
||||
selection.bind[key]
|
||||
],
|
||||
unit: dataTables[selection.source].cols[selection.bind[key]].unit
|
||||
value: dataTableLookup(
|
||||
dataTables[selection.source],
|
||||
selection.default
|
||||
)[selection.bind[key]],
|
||||
|
||||
unit:
|
||||
dataTables[selection.source].columns[selection.bind[key]]?.unit ||
|
||||
''
|
||||
};
|
||||
valsBoundToPreset[key] = selection.default;
|
||||
valsBoundToPreset[key] = selection.title;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -182,9 +186,12 @@ export default async function makeTool(
|
||||
disablePortal
|
||||
id="combo-box-demo"
|
||||
value={values.presets[preset.title]}
|
||||
options={Object.keys(
|
||||
dataTables[preset.source].data
|
||||
).sort()}
|
||||
options={[
|
||||
'<custom>',
|
||||
...Object.keys(
|
||||
dataTables[preset.source].data
|
||||
).sort()
|
||||
]}
|
||||
sx={{ width: 300 }}
|
||||
onChange={(event, newValue) => {
|
||||
handleSelectedPresetChange(
|
||||
@@ -207,7 +214,7 @@ export default async function makeTool(
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Input Variables',
|
||||
title: 'Variables',
|
||||
component: (
|
||||
<Table>
|
||||
<TableHead>
|
||||
@@ -221,7 +228,7 @@ export default async function makeTool(
|
||||
<TableBody>
|
||||
{calcData.variables.map((variable) => (
|
||||
<TableRow key={variable.name}>
|
||||
<TableCell>{variable.name}</TableCell>
|
||||
<TableCell>{variable.title}</TableCell>
|
||||
<TableCell>
|
||||
<TextFieldWithDesc
|
||||
title={variable.title}
|
||||
@@ -253,6 +260,9 @@ export default async function makeTool(
|
||||
<Radio
|
||||
value={variable.name}
|
||||
checked={values.outputVariable === variable.name}
|
||||
disabled={
|
||||
valsBoundToPreset[variable.name] !== undefined
|
||||
}
|
||||
onClick={() =>
|
||||
handleSelectedTargetChange(
|
||||
variable.name,
|
||||
|
@@ -18,7 +18,7 @@ allGenericCalcs.forEach((x) => {
|
||||
tools.push(
|
||||
defineTool('number', {
|
||||
name: x.title,
|
||||
path: 'generic-calc/x.name',
|
||||
path: 'generic-calc/' + x.name,
|
||||
icon: '',
|
||||
description: '',
|
||||
shortDescription: '',
|
||||
|
Reference in New Issue
Block a user