2024-05-31 23:53:30 -06:00
|
|
|
import React from "react";
|
2024-06-25 17:05:41 -06:00
|
|
|
import {Breadcrumbs, useTitle} from "./Common";
|
2026-07-01 18:48:06 -06:00
|
|
|
import {Button, Header, Icon} from "./Theme";
|
2024-05-31 23:53:30 -06:00
|
|
|
import {useCalcQuery} from "../hooks/customHooks";
|
2024-06-20 09:51:29 -06:00
|
|
|
import {TemperatureCalculator} from "./calculators/TemperatureCalculator";
|
2024-06-25 17:05:41 -06:00
|
|
|
import {ElectricalCalculators} from "./calculators/ElectricalCalculators";
|
2024-06-20 09:51:29 -06:00
|
|
|
import {DipoleAntennaCalculator} from "./calculators/HamCalculators";
|
2025-12-07 11:54:20 -07:00
|
|
|
import {Link} from "react-router";
|
2025-01-18 10:08:11 -07:00
|
|
|
import {RatioCalculators} from "./calculators/RatioCalculator";
|
2025-02-07 11:44:17 -07:00
|
|
|
import {QRCodeCalculator} from "./calculators/QRCodeCalculator";
|
Add Drive Ratio calculator (pulleys, gears, sprockets)
A new "Drive Ratio" calculator under /more/calculators for belt, gear, and
chain-sprocket drives, supporting a compound train of 2–6 wheels on a single
shared belt/chain (constant size·rpm across the train).
- Pure, unit-tested math: size·rpm solver, ratio, torque, surface/belt speed,
belt length, sprocket pitch diameter, chain length, gear pitch diameter.
- Mode toggle (Pulley/Gear/Sprocket) with imperial/metric units; torque in
lb·ft or N·m.
- Add/remove wheels (2–6), each with a colorblind-friendly color shared between
its inputs and the schematic SVG diagram (Paul Tol bright palette).
- Dependency-free inline-SVG diagram: colored wheels threaded by one belt/chain,
or meshing gear teeth; auto-fitting viewBox.
- Per-mode details: belt/chain length and center distance (2-wheel only, with an
info popup), per-wheel pitch diameters, and constant train speed.
- Guards against impossible geometry (wheels overlapping) and ideal-torque note.
- Integer teeth enforced in gear/sprocket modes; pulley diameters stay continuous.
Also fix Theme.Header dropping the theme's text color when a caller passes a
`style` prop (now merges {...t.style, ...props.style}).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-28 15:01:34 -06:00
|
|
|
import {DriveCalculator} from "./calculators/DriveCalculator";
|
2026-05-28 17:43:48 -06:00
|
|
|
import {WaterCalculator} from "./calculators/WaterCalculator";
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
import {FoodStorageCalculator} from "./calculators/FoodStorageCalculator";
|
2026-07-01 18:48:06 -06:00
|
|
|
import {OneTimePadCalculator} from "./calculators/OneTimePadCalculator";
|
|
|
|
|
import {VinDecoderCalculator} from "./calculators/VinDecoderCalculator";
|
|
|
|
|
|
|
|
|
|
// Calculators are shown in these titled groups, in this order. Each calculator carries a
|
|
|
|
|
// `group` matching one of these names; any calculator whose group is missing/unknown falls
|
|
|
|
|
// into a trailing "Other" section so a new calculator can never silently disappear.
|
|
|
|
|
//
|
|
|
|
|
// `color` is a Semantic UI named color (colorblind-friendly palette) used to tint the group's
|
|
|
|
|
// buttons. Violet is intentionally avoided — it is the default navbar color and would blend in.
|
|
|
|
|
export const CALCULATOR_GROUPS = [
|
|
|
|
|
{name: 'Preparedness & Storage', color: 'red'},
|
|
|
|
|
{name: 'Radio & Communications', color: 'blue'},
|
|
|
|
|
{name: 'Engineering', color: 'yellow'},
|
|
|
|
|
{name: 'Tools & Reference', color: 'grey'},
|
|
|
|
|
];
|
2024-05-31 23:53:30 -06:00
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
export const useCalculators = () => {
|
|
|
|
|
const [calc, setCalc] = useCalcQuery();
|
2024-05-31 23:53:30 -06:00
|
|
|
|
|
|
|
|
const calculators = [
|
2026-07-01 18:48:06 -06:00
|
|
|
{key: 'ratio', icon: 'th large', button: 'Ratio', group: 'Engineering', contents: <RatioCalculators/>},
|
|
|
|
|
{key: 'electrical', icon: 'lightning', button: 'Electrical', group: 'Engineering', contents: <ElectricalCalculators/>},
|
|
|
|
|
{key: 'drive', icon: 'cogs', button: 'Drive Ratio', group: 'Engineering', contents: <DriveCalculator/>},
|
|
|
|
|
{key: 'water', icon: 'tint', button: 'Water Storage', group: 'Preparedness & Storage', contents: <WaterCalculator/>},
|
|
|
|
|
{key: 'ration', icon: 'food', button: 'Food Storage', group: 'Preparedness & Storage', contents: <FoodStorageCalculator/>},
|
|
|
|
|
{key: 'antenna', icon: 'signal', button: 'Antenna', group: 'Radio & Communications', contents: <DipoleAntennaCalculator/>},
|
|
|
|
|
{key: 'temperature', icon: 'thermometer', button: 'Temperature', group: 'Tools & Reference', contents: <TemperatureCalculator/>},
|
|
|
|
|
{key: 'qrCode', icon: 'qrcode', button: 'QR Code', group: 'Tools & Reference', contents: <QRCodeCalculator/>},
|
|
|
|
|
{key: 'otp', icon: 'lock', button: 'One Time Pad', title: 'One Time Pad', group: 'Radio & Communications', contents: <OneTimePadCalculator/>},
|
|
|
|
|
{key: 'vin', icon: 'car', button: 'VIN Decoder', title: 'VIN Decoder', group: 'Tools & Reference', contents: <VinDecoderCalculator/>},
|
2024-05-31 23:53:30 -06:00
|
|
|
];
|
|
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
const activeCalculator = calc ? calculators.find(i => i.key === calc) : null;
|
2024-05-31 23:53:30 -06:00
|
|
|
|
2026-07-01 18:48:06 -06:00
|
|
|
const calculatorButton = ({button, icon, key}, color) =>
|
|
|
|
|
<Link key={key} to={`/more/calculators?calc=${key}`}>
|
|
|
|
|
<Button color={color} style={{margin: '0.5em'}}>
|
2024-06-25 17:05:41 -06:00
|
|
|
{icon && <Icon name={icon}/>}
|
|
|
|
|
{button}
|
|
|
|
|
</Button>
|
2026-07-01 18:48:06 -06:00
|
|
|
</Link>;
|
|
|
|
|
|
|
|
|
|
// Render each defined group as a titled section, then any leftovers under "Other".
|
|
|
|
|
const groupNames = CALCULATOR_GROUPS.map(g => g.name);
|
|
|
|
|
const grouped = CALCULATOR_GROUPS.map(g => [g.name, g.color, calculators.filter(c => c.group === g.name)]);
|
|
|
|
|
const leftovers = calculators.filter(c => !groupNames.includes(c.group));
|
|
|
|
|
if (leftovers.length > 0) {
|
|
|
|
|
grouped.push(['Other', undefined, leftovers]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const calculatorLinks = grouped
|
|
|
|
|
.filter(([, , items]) => items.length > 0)
|
|
|
|
|
.map(([name, color, items]) =>
|
|
|
|
|
<div key={name} style={{marginBottom: '1.5em'}}>
|
|
|
|
|
<Header as='h3'>{name}</Header>
|
|
|
|
|
{items.map(c => calculatorButton(c, color))}
|
|
|
|
|
</div>);
|
2024-05-31 23:53:30 -06:00
|
|
|
|
2025-01-19 11:58:43 -07:00
|
|
|
return {calc, calculators, activeCalculator, calculatorLinks}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function CalculatorsPage() {
|
|
|
|
|
const {activeCalculator, calculatorLinks} = useCalculators();
|
|
|
|
|
|
|
|
|
|
const {icon, button, title, contents} = activeCalculator || {};
|
|
|
|
|
const name = activeCalculator ? title || button + ' Calculator' : 'Calculators';
|
|
|
|
|
useTitle(name);
|
|
|
|
|
|
|
|
|
|
const body = activeCalculator ? <span>{contents}</span> : calculatorLinks;
|
2024-06-25 17:05:41 -06:00
|
|
|
|
|
|
|
|
// Make first breadcrumb a link back to Calculators only when a calculator is active.
|
|
|
|
|
const crumbs = activeCalculator
|
|
|
|
|
? [{text: 'Calculators', link: '/more/calculators'}, {text: name, icon: icon}]
|
|
|
|
|
: [{text: 'Calculators'}];
|
2024-05-31 23:53:30 -06:00
|
|
|
|
|
|
|
|
return <>
|
2024-06-25 17:05:41 -06:00
|
|
|
<Breadcrumbs crumbs={crumbs} size='huge'/>
|
|
|
|
|
|
|
|
|
|
<div style={{marginTop: '1em'}}>
|
|
|
|
|
{body}
|
|
|
|
|
</div>
|
2024-05-31 23:53:30 -06:00
|
|
|
</>
|
|
|
|
|
}
|