Skip to content

Commit

Permalink
feat: define options for base unit settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreminger committed Nov 26, 2023
1 parent b1c115d commit 83204dc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
14 changes: 7 additions & 7 deletions public/dimensional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,16 @@ def get_base_units(custom_base_units: CustomBaseUnits | None= None) -> dict[tupl
(1, 2, -2, 0, 0, 0, 0, 0, 0): "J",
(1, 2, -3, 0, 0, 0, 0, 0, 0): "W",
(1, -1, -2, 0, 0, 0, 0, 0, 0): "Pa",
(0, 0, 1, 1, 0, 0, 0, 0, 0): "coulomb",
(-1, -2, 4, 2, 0, 0, 0, 0, 0): "farad",
(0, 0, 1, 1, 0, 0, 0, 0, 0): "C",
(-1, -2, 4, 2, 0, 0, 0, 0, 0): "F",
(1, 2, -3, -1, 0, 0, 0, 0, 0): "V",
(1, 2, -3, -2, 0, 0, 0, 0, 0): "ohm",
(1, 2, -2, -2, 0, 0, 0, 0, 0): "henry",
(-1, -2, 3, 2, 0, 0, 0, 0, 0): "siemens",
(1, 2, -2, -1, 0, 0, 0, 0, 0): "weber",
(1, 0, -2, -1, 0, 0, 0, 0, 0): "tesla",
(1, 2, -2, -2, 0, 0, 0, 0, 0): "H",
(-1, -2, 3, 2, 0, 0, 0, 0, 0): "S",
(1, 2, -2, -1, 0, 0, 0, 0, 0): "Wb",
(1, 0, -2, -1, 0, 0, 0, 0, 0): "T",
(0, 0, 0, 0, 0, 0, 0, 1, 0): "rad",
(0, 0, 0, 0, 0, 0, 0, 0, 1): "bits",
(0, 0, 0, 0, 0, 0, 0, 0, 1): "b",
}
else:
return {
Expand Down
55 changes: 54 additions & 1 deletion src/sheet/Sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,57 @@ export function getSafeMathConfig(config: MathCellConfig): MathCellConfig {
}

return safeConfig;
}
}

export type CustomBaseUnits = {
mass: string;
length: string;
time: string;
current: string;
temperature: string;
luminous_intensity: string;
amount_of_substance: string;
force: string;
area: string;
volume: string;
energy: string;
power: string;
pressure: string;
charge: string;
capacitance: string;
electric_potential: string;
resistance: string;
inductance: string;
conductance: string;
magnetic_flux: string;
magnetic_flux_density: string;
angle: string;
information: string;
}

// the first choice in each list of choices will be used as the default
export const baseUnitChoices: {name: string, label: string, choices: string[]}[] = [
{name: 'mass', label: 'Mass', choices: ['kg', 'g', 'mg', 'tonne', 'lbm', 'ton', 'oz'] },
{name: 'length', label: 'Length', choices: ['m', 'mm', 'cm', 'km', 'um', 'nm', 'angstrom', 'in', 'feet', 'yard', 'mile']},
{name: 'time', label: 'Time', choices: ['s', 'ms', 'us', 'ns', 'min', 'hour', 'day', 'week', 'month', 'year']},
{name: 'current', label: 'Electric Current', choices: ['A', 'mA', 'uA', 'kA', 'MA']},
{name: 'temperature', label: 'Temperature', choices: ['K', 'degC', 'degF', 'degR']},
{name: 'luminous_intensity', label: 'Luminous Intensity', choices: ['cd', 'mcd', 'kcd']},
{name: 'amount_of_substance', label: 'Amount of Substance', choices: ['mol', 'kmol', 'mmol']},
{name: 'force', label: 'Force', choices: ['N', 'mN', 'kN', 'lbf', 'kip', 'dyne']},
{name: 'area', label: 'Area', choices: ['m^2', 'cm^2', 'mm^2', 'km^2', 'hectare', 'in^2', 'feet^2', 'yard^2', 'mile^2', 'acre']},
{name: 'volume', label: 'Volume', choices: ['m^3', 'cm^3', 'mm^3', 'km^3', 'liter', 'ml', 'in^3', 'feet^3', 'yard^3', 'mile^3', 'gallon', 'floz']},
{name: 'energy', label: 'Energy', choices: ['J', 'mJ', 'kJ', 'MJ', 'Wh', 'kWh', 'eV', 'BTU', 'hp*hr', 'N*m', 'in*lbf', 'foot*lbf', 'erg']},
{name: 'power', label: 'Power', choices: ['w', 'mW', 'kW', 'MW', 'hp', 'BTU/min', 'BTU/sec', 'erg/sec', 'dyne*cm/sec']},
{name: 'pressure', label: 'Pressure', choices: ['Pa', 'kPa', 'MPa', 'psi', 'atm', 'torr', 'bar', 'mmHg', 'mmH2O', 'cmH2O']},
{name: 'charge', label: 'Electric Charge', choices: ['C', 'mC', 'uC', 'nC', 'pC']},
{name: 'capacitance', label: 'Capacitance', choices: ['F', 'mF', 'uF', 'nF', 'pF']},
{name: 'electric_potential', label: 'Electric Potential', choices: ['V', 'mV', 'kV', 'uV', 'MV']},
{name: 'resistance', label: 'Resistance', choices: ['ohm', 'mohm', 'kohm', 'Mohm', 'Gohm']},
{name: 'inductance', label: 'Inductance', choices: ['H', 'mH', 'uH', 'nH', 'pH']},
{name: 'conductance', label: 'Conductance', choices: ['S', 'mS', 'kS', 'uS', 'MS']},
{name: 'magnetic_flux', label: 'Magnetic Flux', choices: ['Wb', 'mWb', 'uWb', 'nWb']},
{name: 'magnetic_flux_density', label: 'Magnetic Flux Density', choices: ['T', 'mT', 'uT', 'nT','pT']},
{name: 'angle', label: 'Angle', choices: ['rad', 'deg', 'grad', 'cycle', 'arcsec', 'arcmin']},
{name: 'information', label: 'Information', choices: ['b', 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'kb', 'mb', 'Gb', 'Tb', 'Pb']},
];
27 changes: 1 addition & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type MathCellElement from "./MathCell.svelte";
import type { SystemDefinition } from "./cells/SystemCell";
import type { Statement } from "./parser/types";
import type { MathField } from "./cells/MathField";
import type { CustomBaseUnits } from "./sheet/Sheet";

export type ModalInfo = {
state: "uploadSheet" | "uploadPending" | "success" | "error" | "requestPersistentStorage" |
Expand Down Expand Up @@ -35,32 +36,6 @@ export type RecentSheetFile = {

export type RecentSheets = Map<string, RecentSheetUrl | RecentSheetFile>;

export type CustomBaseUnits = {
mass: string;
length: string;
time: string;
current: string;
temperature: string;
luminous_intensity: string;
amount_of_substance: string;
force: string;
area: string;
volume: string;
energy: string;
power: string;
pressure: string;
charge: string;
capacitance: string;
electric_potential: string;
resistance: string;
inductance: string;
conductance: string;
magnetic_flux: string;
magnetic_flux_density: string;
angle: string;
information: string;
}

export type StatementsAndSystems = {
statements: Statement[];
systemDefinitions: SystemDefinition[];
Expand Down

0 comments on commit 83204dc

Please sign in to comment.