From e9e5adce424235a8b38e48a65ba8dd4289f5f4c6 Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Sun, 8 Mar 2026 01:49:50 +0000 Subject: [PATCH] Add next batch of calculators and AWG support --- calculators_list.md | 85 +++++++++++++------------ hdyc-svelte/src/lib/data/calculators.ts | 7 +- hdyc-svelte/src/lib/engine.ts | 68 ++++++++++++++++++++ hdyc-svelte/src/routes/+page.svelte | 2 +- migrate.py | 11 +++- 5 files changed, 128 insertions(+), 45 deletions(-) diff --git a/calculators_list.md b/calculators_list.md index 48c0332..5949a7c 100644 --- a/calculators_list.md +++ b/calculators_list.md @@ -1903,6 +1903,11 @@ The registry currently contains 1333 unique calculator slugs. | Light Years to Fermi – Stretch a light-year into femtometer scales. | light-years-to-fermi | 9.46073047258e+30 | | Light Years to Furlongs – Translate cosmic distances into furlongs. | light-years-to-furlongs | 4.70290029855e+13 | | Light Years to Hands – Compare a light-year to a stack of hands. | light-years-to-hands | 9.31174259112e+16 | +| AWG to Circular mils – Convert American Wire Gauge sizes into circular mil areas. | awg-to-circular-mils | electrical | AWG | +| AWG to Millimeters (diameter) – Express AWG gauge as a diameter in millimeters. | awg-to-millimeters-diameter | electrical | AWG | +| AWG to Square millimeters (cross-section) – Convert AWG sizes into cross-sectional area in mm². | awg-to-square-millimeters-cross-section | electrical | AWG | +| Board feet (energy equiv.) to BTU – Convert the energy equivalent of a board foot of lumber into BTUs. | board-feet-energy-equiv-to-btu | energy | 14000 | +| Brinell to Rockwell C – Approximate Rockwell C hardness from Brinell hardness numbers. | brinell-to-rockwell-c | other | Formula | ## Completion Checklist - [x] Inches to Feet (`inches-to-feet`) @@ -2920,9 +2925,9 @@ The registry currently contains 1333 unique calculator slugs. - [x] Atmosphere to Torr - [x] Atomic mass units to Kilograms - [x] Atomic time units to Seconds -- [ ] AWG to Circular mils -- [ ] AWG to Millimeters (diameter) -- [ ] AWG to Square millimeters (cross-section) +- [x] AWG to Circular mils +- [x] AWG to Millimeters (diameter) +- [x] AWG to Square millimeters (cross-section) - [x] Kilograms to Quarters (1 kilogram ≈ 0.078732 US quarters) - [x] Banana equivalent dose to Microsievert - [x] Bar to Atmosphere @@ -2941,11 +2946,11 @@ The registry currently contains 1333 unique calculator slugs. - [x] Binary to Octal - [x] Bits to Kilobits - [x] Bits to Nibbles -- [ ] Board feet (energy equiv.) to BTU +- [x] Board feet (energy equiv.) to BTU - [x] Board feet to Cubic feet - [x] Board feet to Cubic meters - [x] Boiler Horsepower to Watts -- [ ] Brinell to Rockwell C +- [x] Brinell to Rockwell C - [x] BTU to Calories - [x] BTU to Joules - [x] BTU to Kilowatt-hours @@ -3004,41 +3009,41 @@ The registry currently contains 1333 unique calculator slugs. - [x] Romer difference to newton difference (`romer-difference-to-newton-difference`) - [x] Reaumur difference to romer difference (`reaumur-difference-to-romer-difference`) - [x] Romer difference to reaumur difference (`romer-difference-to-reaumur-difference`) -- [ ] Thermal expansion coefficient (per °C) to per °F (`thermal-expansion-coefficient-per-c-to-per-f`) -- [ ] Thermal expansion coefficient (per °F) to per °C (`thermal-expansion-coefficient-per-f-to-per-c`) -- [ ] Thermal resistance (K/W) to °F·hour/BTU (`thermal-resistance-k-per-watt-to-fahrenheit-hour-btu`) -- [ ] Thermal resistance (°F·hour/BTU) to K/W (`thermal-resistance-fahrenheit-hour-btu-to-k-per-watt`) -- [ ] Thermal conductivity (W/(m·K)) to BTU/(hr·ft·°F) (`thermal-conductivity-w-per-meter-k-to-btu-per-hour-foot-fahrenheit`) -- [ ] Thermal conductivity (BTU/(hr·ft·°F)) to W/(m·K) (`thermal-conductivity-btu-per-hour-foot-fahrenheit-to-w-per-meter-k`) -- [ ] Specific heat capacity (J/(kg·K)) to cal/(g·°C) (`specific-heat-j-per-kg-k-to-cal-per-gram-c`) -- [ ] Specific heat capacity (cal/(g·°C)) to J/(kg·K) (`specific-heat-cal-per-gram-c-to-j-per-kg-k`) -- [ ] Specific heat capacity (J/(kg·K)) to Btu/(lb·°F) (`specific-heat-j-per-kg-k-to-btu-per-pound-f`) -- [ ] Specific heat capacity (Btu/(lb·°F)) to J/(kg·K) (`specific-heat-btu-per-pound-f-to-j-per-kg-k`) -- [ ] Volumetric heat capacity (J/(m³·K)) to Btu/(ft³·°F) (`volumetric-heat-capacity-j-per-cubic-meter-k-to-btu-per-cubic-foot-f`) -- [ ] Volumetric heat capacity (Btu/(ft³·°F)) to J/(m³·K) (`volumetric-heat-capacity-btu-per-cubic-foot-f-to-j-per-cubic-meter-k`) -- [ ] Heat flux density (W/m²) to BTU/(hr·ft²) (`heat-flux-density-w-per-square-meter-to-btu-per-hour-square-foot`) -- [ ] Heat flux density (BTU/(hr·ft²)) to W/m² (`heat-flux-density-btu-per-hour-square-foot-to-w-per-square-meter`) -- [ ] Heat transfer coefficient (W/(m²·K)) to BTU/(hr·ft²·°F) (`heat-transfer-coefficient-w-per-square-meter-k-to-btu-per-hour-square-foot-f`) -- [ ] Heat transfer coefficient (BTU/(hr·ft²·°F)) to W/(m²·K) (`heat-transfer-coefficient-btu-per-hour-square-foot-f-to-w-per-square-meter-k`) -- [ ] Thermal expansion coefficient (per °C) to per °K (`thermal-expansion-coefficient-per-c-to-per-k`) -- [ ] Thermal expansion coefficient (per °K) to per °C (`thermal-expansion-coefficient-per-k-to-per-c`) -- [ ] Thermal expansion coefficient (per °F) to per °R (`thermal-expansion-coefficient-per-f-to-per-r`) -- [ ] Thermal expansion coefficient (per °R) to per °F (`thermal-expansion-coefficient-per-r-to-per-f`) -- [ ] Thermal resistance (K/W) to m²·K/W (`thermal-resistance-k-per-watt-to-square-meter-k-per-watt`) -- [ ] Thermal resistance (m²·K/W) to K/W (`thermal-resistance-square-meter-k-per-watt-to-k-per-watt`) -- [ ] Thermal resistance (m²·K/W) to ft²·°F·h/BTU (`thermal-resistance-square-meter-k-per-watt-to-square-foot-hour-fahrenheit-per-btu`) -- [ ] Thermal resistance (ft²·°F·h/BTU) to m²·K/W (`thermal-resistance-square-foot-hour-fahrenheit-per-btu-to-square-meter-k-per-watt`) -- [ ] Thermal conductivity (W/(m·K)) to cal/(cm·s·°C) (`thermal-conductivity-w-per-meter-k-to-cal-per-centimeter-second-c`) -- [ ] Thermal conductivity (cal/(cm·s·°C)) to W/(m·K) (`thermal-conductivity-cal-per-centimeter-second-c-to-w-per-meter-k`) -- [ ] Specific heat capacity (J/(kg·K)) to kJ/(kg·K) (`specific-heat-j-per-kg-k-to-kj-per-kg-k`) -- [ ] Specific heat capacity (kJ/(kg·K)) to J/(kg·K) (`specific-heat-kj-per-kg-k-to-j-per-kg-k`) -- [ ] Volumetric heat capacity (J/(m³·K)) to kJ/(m³·K) (`volumetric-heat-capacity-j-per-cubic-meter-k-to-kj-per-cubic-meter-k`) -- [ ] Volumetric heat capacity (kJ/(m³·K)) to J/(m³·K) (`volumetric-heat-capacity-kj-per-cubic-meter-k-to-j-per-cubic-meter-k`) -- [ ] Heat flux density (W/m²) to W/ft² (`heat-flux-density-w-per-square-meter-to-w-per-square-foot`) -- [ ] Heat flux density (W/ft²) to W/m² (`heat-flux-density-w-per-square-foot-to-w-per-square-meter`) -- [ ] Heat transfer coefficient (W/(m²·K)) to W/(ft²·°F) (`heat-transfer-coefficient-w-per-square-meter-k-to-w-per-square-foot-f`) -- [ ] Heat transfer coefficient (W/(ft²·°F)) to W/(m²·K) (`heat-transfer-coefficient-w-per-square-foot-f-to-w-per-square-meter-k`) -- [ ] Ampere-turns to Gilberts (`ampere-turns-to-gilberts`) +- [x] Thermal expansion coefficient (per °C) to per °F (`thermal-expansion-coefficient-per-c-to-per-f`) +- [x] Thermal expansion coefficient (per °F) to per °C (`thermal-expansion-coefficient-per-f-to-per-c`) +- [x] Thermal resistance (K/W) to °F·hour/BTU (`thermal-resistance-k-per-watt-to-fahrenheit-hour-btu`) +- [x] Thermal resistance (°F·hour/BTU) to K/W (`thermal-resistance-fahrenheit-hour-btu-to-k-per-watt`) +- [x] Thermal conductivity (W/(m·K)) to BTU/(hr·ft·°F) (`thermal-conductivity-w-per-meter-k-to-btu-per-hour-foot-fahrenheit`) +- [x] Thermal conductivity (BTU/(hr·ft·°F)) to W/(m·K) (`thermal-conductivity-btu-per-hour-foot-fahrenheit-to-w-per-meter-k`) +- [x] Specific heat capacity (J/(kg·K)) to cal/(g·°C) (`specific-heat-j-per-kg-k-to-cal-per-gram-c`) +- [x] Specific heat capacity (cal/(g·°C)) to J/(kg·K) (`specific-heat-cal-per-gram-c-to-j-per-kg-k`) +- [x] Specific heat capacity (J/(kg·K)) to Btu/(lb·°F) (`specific-heat-j-per-kg-k-to-btu-per-pound-f`) +- [x] Specific heat capacity (Btu/(lb·°F)) to J/(kg·K) (`specific-heat-btu-per-pound-f-to-j-per-kg-k`) +- [x] Volumetric heat capacity (J/(m³·K)) to Btu/(ft³·°F) (`volumetric-heat-capacity-j-per-cubic-meter-k-to-btu-per-cubic-foot-f`) +- [x] Volumetric heat capacity (Btu/(ft³·°F)) to J/(m³·K) (`volumetric-heat-capacity-btu-per-cubic-foot-f-to-j-per-cubic-meter-k`) +- [x] Heat flux density (W/m²) to BTU/(hr·ft²) (`heat-flux-density-w-per-square-meter-to-btu-per-hour-square-foot`) +- [x] Heat flux density (BTU/(hr·ft²)) to W/m² (`heat-flux-density-btu-per-hour-square-foot-to-w-per-square-meter`) +- [x] Heat transfer coefficient (W/(m²·K)) to BTU/(hr·ft²·°F) (`heat-transfer-coefficient-w-per-square-meter-k-to-btu-per-hour-square-foot-f`) +- [x] Heat transfer coefficient (BTU/(hr·ft²·°F)) to W/(m²·K) (`heat-transfer-coefficient-btu-per-hour-square-foot-f-to-w-per-square-meter-k`) +- [x] Thermal expansion coefficient (per °C) to per °K (`thermal-expansion-coefficient-per-c-to-per-k`) +- [x] Thermal expansion coefficient (per °K) to per °C (`thermal-expansion-coefficient-per-k-to-per-c`) +- [x] Thermal expansion coefficient (per °F) to per °R (`thermal-expansion-coefficient-per-f-to-per-r`) +- [x] Thermal expansion coefficient (per °R) to per °F (`thermal-expansion-coefficient-per-r-to-per-f`) +- [x] Thermal resistance (K/W) to m²·K/W (`thermal-resistance-k-per-watt-to-square-meter-k-per-watt`) +- [x] Thermal resistance (m²·K/W) to K/W (`thermal-resistance-square-meter-k-per-watt-to-k-per-watt`) +- [x] Thermal resistance (m²·K/W) to ft²·°F·h/BTU (`thermal-resistance-square-meter-k-per-watt-to-square-foot-hour-fahrenheit-per-btu`) +- [x] Thermal resistance (ft²·°F·h/BTU) to m²·K/W (`thermal-resistance-square-foot-hour-fahrenheit-per-btu-to-square-meter-k-per-watt`) +- [x] Thermal conductivity (W/(m·K)) to cal/(cm·s·°C) (`thermal-conductivity-w-per-meter-k-to-cal-per-centimeter-second-c`) +- [x] Thermal conductivity (cal/(cm·s·°C)) to W/(m·K) (`thermal-conductivity-cal-per-centimeter-second-c-to-w-per-meter-k`) +- [x] Specific heat capacity (J/(kg·K)) to kJ/(kg·K) (`specific-heat-j-per-kg-k-to-kj-per-kg-k`) +- [x] Specific heat capacity (kJ/(kg·K)) to J/(kg·K) (`specific-heat-kj-per-kg-k-to-j-per-kg-k`) +- [x] Volumetric heat capacity (J/(m³·K)) to kJ/(m³·K) (`volumetric-heat-capacity-j-per-cubic-meter-k-to-kj-per-cubic-meter-k`) +- [x] Volumetric heat capacity (kJ/(m³·K)) to J/(m³·K) (`volumetric-heat-capacity-kj-per-cubic-meter-k-to-j-per-cubic-meter-k`) +- [x] Heat flux density (W/m²) to W/ft² (`heat-flux-density-w-per-square-meter-to-w-per-square-foot`) +- [x] Heat flux density (W/ft²) to W/m² (`heat-flux-density-w-per-square-foot-to-w-per-square-meter`) +- [x] Heat transfer coefficient (W/(m²·K)) to W/(ft²·°F) (`heat-transfer-coefficient-w-per-square-meter-k-to-w-per-square-foot-f`) +- [x] Heat transfer coefficient (W/(ft²·°F)) to W/(m²·K) (`heat-transfer-coefficient-w-per-square-foot-f-to-w-per-square-meter-k`) +- [x] Ampere-turns to Gilberts (`ampere-turns-to-gilberts`) - [ ] Gilberts to Ampere-turns (`gilberts-to-ampere-turns`) - [ ] Ampere per meter to Oersted (`ampere-per-meter-to-oersted`) - [ ] Oersted to Ampere per meter (`oersted-to-ampere-per-meter`) diff --git a/hdyc-svelte/src/lib/data/calculators.ts b/hdyc-svelte/src/lib/data/calculators.ts index c2fc9a4..d273ec5 100644 --- a/hdyc-svelte/src/lib/data/calculators.ts +++ b/hdyc-svelte/src/lib/data/calculators.ts @@ -1,5 +1,5 @@ // THIS FILE IS AUTO-GENERATED BY migrate.py -export type CalcType = 'standard' | 'inverse' | '3col' | '3col-mul' | 'base' | 'text-bin' | 'bin-text' | 'dms-dd' | 'dd-dms' | 'dec-frac' | 'db-int' | 'db-spl' | 'db-v' | 'db-w'; +export type CalcType = 'standard' | 'inverse' | '3col' | '3col-mul' | 'base' | 'text-bin' | 'bin-text' | 'dms-dd' | 'dd-dms' | 'dec-frac' | 'db-int' | 'db-spl' | 'db-v' | 'db-w' | 'awg' | 'brinell-rockwell'; export interface CalculatorDef { slug: string; @@ -1598,6 +1598,11 @@ export const calculators: CalculatorDef[] = [ {"slug": "heat-transfer-coefficient-btu-per-hour-square-foot-f-to-w-per-square-meter-k", "name": "Heat transfer coefficient (BTU/(hr\u00b7ft\u00b2\u00b7\u00b0F)) to W/(m\u00b2\u00b7K)", "category": "energy", "type": "standard", "teaser": "Return imperial coefficients back into SI.", "labels": {"in1": "Heat transfer coefficient (BTU/(hr\u00b7ft\u00b2\u00b7\u00b0F))", "in2": "W/(m\u00b2\u00b7K)"}, "factor": 5.6782633415}, {"slug": "heat-transfer-coefficient-w-per-square-meter-k-to-w-per-square-foot-f", "name": "Heat transfer coefficient (W/(m\u00b2\u00b7K)) to W/(ft\u00b2\u00b7\u00b0F)", "category": "energy", "type": "standard", "teaser": "Move the conduction coefficient into mixed-area and temperature units.", "labels": {"in1": "Heat transfer coefficient (W/(m\u00b2\u00b7K))", "in2": "W/(ft\u00b2\u00b7\u00b0F)"}, "factor": 0.0516128}, {"slug": "heat-transfer-coefficient-w-per-square-foot-f-to-w-per-square-meter-k", "name": "Heat transfer coefficient (W/(ft\u00b2\u00b7\u00b0F)) to W/(m\u00b2\u00b7K)", "category": "energy", "type": "standard", "teaser": "Convert the mixed imperial SI coefficient back into its base units.", "labels": {"in1": "Heat transfer coefficient (W/(ft\u00b2\u00b7\u00b0F))", "in2": "W/(m\u00b2\u00b7K)"}, "factor": 19.3750387506}, + {"slug": "awg-to-circular-mils", "name": "AWG to Circular mils", "category": "electrical", "type": "awg", "teaser": "Convert American Wire Gauge sizes into circular mil areas.", "labels": {"in1": "AWG", "in2": "Circular mils"}}, + {"slug": "awg-to-millimeters-diameter", "name": "AWG to Millimeters (diameter)", "category": "electrical", "type": "awg", "teaser": "Express AWG gauge as a diameter in millimeters.", "labels": {"in1": "AWG", "in2": "Millimeters (diameter)"}}, + {"slug": "awg-to-square-millimeters-cross-section", "name": "AWG to Square millimeters (cross-section)", "category": "electrical", "type": "awg", "teaser": "Convert AWG sizes into cross-sectional area in mm\u00b2.", "labels": {"in1": "AWG", "in2": "Square millimeters (cross-section)"}}, + {"slug": "board-feet-energy-equiv-to-btu", "name": "Board feet (energy equiv.) to BTU", "category": "energy", "type": "standard", "teaser": "Convert the energy equivalent of a board foot of lumber into BTUs.", "labels": {"in1": "Board feet (energy equiv.)", "in2": "BTU"}, "factor": 14000.0}, + {"slug": "brinell-to-rockwell-c", "name": "Brinell to Rockwell C", "category": "other", "type": "brinell-rockwell", "teaser": "Approximate Rockwell C hardness from Brinell hardness numbers.", "labels": {"in1": "Brinell", "in2": "Rockwell C"}}, ]; diff --git a/hdyc-svelte/src/lib/engine.ts b/hdyc-svelte/src/lib/engine.ts index 33acb22..c96e3c6 100644 --- a/hdyc-svelte/src/lib/engine.ts +++ b/hdyc-svelte/src/lib/engine.ts @@ -181,6 +181,74 @@ export function solve( out.val1 = (!isNaN(v2) && v2 > 0) ? fmt(10 * Math.log10(v2)) : ''; } break; + + case 'awg': { + const log92 = Math.log(92); + const awgToDiameterMm = (g: number) => 0.127 * Math.pow(92, (36 - g) / 39); + const diameterMmToAwg = (d: number) => 36 - 39 * Math.log(d / 0.127) / log92; + const awgToCircularMils = (g: number) => 1000 * Math.pow(92, (36 - g) / 19.5); + const circularMilsToAwg = (a: number) => 36 - 19.5 * Math.log(a / 1000) / log92; + const awgToAreaMm2 = (g: number) => { + const d = awgToDiameterMm(g); + return Math.PI * Math.pow(d, 2) / 4; + }; + const areaMm2ToAwg = (a: number) => { + const d = Math.sqrt((4 * a) / Math.PI); + return diameterMmToAwg(d); + }; + + const slug = calc.slug; + const formatAwg = (g: number) => isFinite(g) ? fmt(g) : ''; + + if (slug.includes('circular-mils')) { + if (source === 1) { + out.val2 = !isNaN(v1) ? fmt(awgToCircularMils(v1)) : ''; + } else { + out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(circularMilsToAwg(v2)) : ''; + } + } else if (slug.includes('square-millimeters')) { + if (source === 1) { + out.val2 = !isNaN(v1) ? fmt(awgToAreaMm2(v1)) : ''; + } else { + out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(areaMm2ToAwg(v2)) : ''; + } + } else { + // diameter in millimeters + if (source === 1) { + out.val2 = !isNaN(v1) ? fmt(awgToDiameterMm(v1)) : ''; + } else { + out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(diameterMmToAwg(v2)) : ''; + } + } + break; + } + + case 'brinell-rockwell': { + // Approximate correlation for steels: + // BHN = (1520000 - 4500 * HRC) / (100 - HRC)^2 + if (source === 1) { + // Brinell to Rockwell C + if (!isNaN(v1) && v1 > 0) { + const a = v1; + const disc = 4500 ** 2 + 4 * a * 1070000; + const y = (4500 + Math.sqrt(disc)) / (2 * a); + const hrc = 100 - y; + out.val2 = fmt(hrc); + } else { + out.val2 = ''; + } + } else { + // Rockwell C to Brinell + if (!isNaN(v2) && v2 < 100) { + const h = v2; + const bhn = (1520000 - 4500 * h) / Math.pow(100 - h, 2); + out.val1 = fmt(bhn); + } else { + out.val1 = ''; + } + } + break; + } } return out; diff --git a/hdyc-svelte/src/routes/+page.svelte b/hdyc-svelte/src/routes/+page.svelte index 6f836e1..4d8fc34 100644 --- a/hdyc-svelte/src/routes/+page.svelte +++ b/hdyc-svelte/src/routes/+page.svelte @@ -54,7 +54,7 @@

How Do You Convert?

-

Fast, bidirectional unit conversions with no ads.

+

Fast unit conversions with no ads.

diff --git a/migrate.py b/migrate.py index 7f8a61c..36eeb76 100644 --- a/migrate.py +++ b/migrate.py @@ -118,8 +118,13 @@ def process(): c_type = 'standard' factor_val = "1" offset_val = "0" - - if '1/x' in factor_raw: + + # Special-case calculator families that require custom math beyond simple factors. + if 'awg' in slug: + c_type = 'awg' + elif 'brinell-to-rockwell-c' == slug or 'rockwell-c-to-brinell' == slug: + c_type = 'brinell-rockwell' + elif '1/x' in factor_raw: c_type = 'inverse' factor_val = "1" elif 'Multi-Variable' in factor_raw: @@ -296,7 +301,7 @@ def process(): # Ensure types are right # write to TS out = """// THIS FILE IS AUTO-GENERATED BY migrate.py -export type CalcType = 'standard' | 'inverse' | '3col' | '3col-mul' | 'base' | 'text-bin' | 'bin-text' | 'dms-dd' | 'dd-dms' | 'dec-frac' | 'db-int' | 'db-spl' | 'db-v' | 'db-w'; +export type CalcType = 'standard' | 'inverse' | '3col' | '3col-mul' | 'base' | 'text-bin' | 'bin-text' | 'dms-dd' | 'dd-dms' | 'dec-frac' | 'db-int' | 'db-spl' | 'db-v' | 'db-w' | 'awg' | 'brinell-rockwell'; export interface CalculatorDef { slug: string;