feat: Add Acres to Hectares calculator and update the calculator backlog list.

This commit is contained in:
Ben
2026-02-20 23:49:12 -08:00
parent e679e20912
commit abd504ed3f
3 changed files with 322 additions and 0 deletions

View File

@@ -40,6 +40,13 @@ Whenever a new calculator is created:
- `_kad_element_hook`: `kadence_after_header`
- `_kad_element_show_conditionals`: `'[{"rule":"singular|calculator","select":"ids","ids":[<CALCULATOR_POST_ID>],"mustMatch":false}]'`
## 4. Required Mathematical Verification
After the Kadence Element is injected and the calculator is live, **you must verify the math works in both directions** using the live WordPress post.
1. Determine a known "Unit A to Unit B" conversion (e.g., 1 inch = 2.54 cm).
2. Execute an HTTP/URL request simulating the Unit A input (e.g., `?v1=1`) and verify the output accurately reflects Unit B.
3. Reverse the test: simulate the Unit B input (e.g., `?v2=2.54`) and verify the output accurately reflects Unit A.
4. If either math direction fails or produces precision floating-point inaccuracies, you must correct the Kadence Element JavaScript block.
## 4. Calculator Registry
To avoid unnecessary scraping of the REST API, immediately update the `calculators_list.md` file located in the workspace directory with the details (Title, Post ID, Kadence Element ID) upon successful deployment.

View File

@@ -8,3 +8,204 @@ Whenever a new calculator is published via the REST API, it must be appended her
| Inches to Feet | 16 | 57 | inches-to-feet | 12 |
| Kilograms to Pounds | 54 | 28 | kilograms-to-pounds | 0.453592 |
| Miles to Kilometers | 102 | 103 | miles-to-kilometers | 0.62137119 |
| Acres to Hectares | 107 | 108 | acres-to-hectares | 0.404686 |
## Backlog / To-Do
- [ ] Acres to square feet
- [ ] Amps to volts
- [ ] Amps to watts
- [ ] Angstroms to nanometers
- [ ] Apothecary ounces to grams
- [ ] ASCII to binary
- [ ] Astronomical units to light years
- [ ] Atmosphere to mmHg
- [ ] Attograms to femtograms
- [ ] Bar to Pascal
- [ ] Bar to PSI
- [ ] Becquerel to curie
- [ ] Becquerel to rutherford
- [ ] Binary to ASCII
- [ ] Binary to decimal
- [ ] Binary to hex
- [ ] Bits to bytes
- [ ] BTU to kilojoules
- [ ] BTU/hour to watts
- [ ] Bytes to bits
- [ ] Calories to joules
- [ ] Calories to kilojoules
- [ ] Candela to lumens
- [ ] Carats to grams
- [ ] Celsius to Fahrenheit
- [ ] Centimeters to inches
- [ ] CFS to CMS
- [ ] CMS to CFS
- [ ] Coulomb per kilogram to roentgen
- [ ] Cups to milliliters
- [ ] Curie to becquerel
- [ ] Daltons to atomic mass units
- [ ] Days to hours
- [ ] Days to weeks
- [ ] Days to years
- [ ] Decimal degrees to degrees, minutes, and seconds
- [ ] Decimal to binary
- [ ] Decimal to fraction
- [ ] Decimal to hex
- [ ] Decimal to octal
- [ ] Decibels to intensity
- [ ] Decibels to sound pressure level
- [ ] Decibels to volts
- [ ] Decibels to watts
- [ ] Degrees to mils
- [ ] Degrees to radians
- [ ] Degrees, minutes, and seconds to decimal degrees
- [ ] Dynes to newtons
- [ ] Ergs to joules
- [ ] Fahrenheit to Celsius
- [ ] Feet to meters
- [ ] Feet per second to meters per second
- [ ] Femtograms to attograms
- [ ] Fluid ounces to milliliters
- [ ] Foot-pounds to newton-meters
- [ ] Fractions to decimals
- [ ] Gallons per minute to liters per second
- [ ] Gallons to liters
- [ ] Gigabytes to megabytes
- [ ] Gigabytes to terabytes
- [ ] Grains to grams
- [ ] Grams to apothecary ounces
- [ ] Grams to carats
- [ ] Grams to grains
- [ ] Grams to milligrams
- [ ] Grams to moles (requires molar mass — see list 2 if chemical context unknown)
- [ ] Grams to ounces
- [ ] Grams to pennyweights
- [ ] Grams to troy ounces
- [ ] Gray to rad
- [ ] Hectares to acres
- [ ] Hex to binary
- [ ] Hex to decimal
- [ ] Horsepower to kilowatts
- [ ] Hours to days
- [ ] Hours to minutes
- [ ] Inches of mercury to pascals
- [ ] Inches of water to pascals
- [ ] Inches to centimeters
- [ ] Inches to millimeters
- [ ] Joules to calories
- [ ] Joules to ergs
- [ ] Kilocalories to kilojoules
- [ ] Kilograms to pounds
- [ ] Kilograms to slugs
- [ ] Kilojoules to BTU
- [ ] Kilojoules to kilocalories
- [ ] Kilometers per hour to miles per hour
- [ ] Kilometers to miles
- [ ] Kilometers to nautical miles
- [ ] Kilowatts to horsepower
- [ ] Kilowatts to tons of refrigeration
- [ ] Kilowatt-hours to megajoules
- [ ] Knots to miles per hour
- [ ] Light years to astronomical units
- [ ] Light years to parsecs
- [ ] Liters per second to gallons per minute
- [ ] Liters to gallons
- [ ] Liters to pints
- [ ] Liters to quarts
- [ ] Long tons to metric tons
- [ ] Lumens to candela
- [ ] Lumens to lux
- [ ] Lux to lumens
- [ ] Megabytes to gigabytes
- [ ] Megajoules to kilowatt-hours
- [ ] Megapascals to PSI
- [ ] Megapixels to resolution (geometric math only)
- [ ] Meters per second to feet per second
- [ ] Meters per second to miles per hour
- [ ] Meters per second to yards per second
- [ ] Meters to feet
- [ ] Meters to yards
- [ ] Metric tons to long tons
- [ ] Metric tons to short tons
- [ ] Micrograms to milligrams
- [ ] Micrometers to millimeters
- [ ] Micrometers to nanometers
- [ ] Microns to angstroms
- [ ] Miles per gallon to kilometers per liter
- [ ] Miles per gallon to liters per 100 km
- [ ] Miles per hour to kilometers per hour
- [ ] Miles per hour to knots
- [ ] Miles per hour to meters per second
- [ ] Miles to kilometers
- [ ] Milligrams to grams
- [ ] Milligrams to micrograms
- [ ] Milliliters to cups
- [ ] Milliliters to fluid ounces
- [ ] Milliliters to tablespoons
- [ ] Milliliters to teaspoons
- [ ] Millimeters to inches
- [ ] Millimeters to microns
- [ ] Minutes to hours
- [ ] Minutes to seconds
- [ ] Nanograms to picograms
- [ ] Nanometers to micrometers
- [ ] Nautical miles to kilometers
- [ ] Newton-meters to foot-pounds
- [ ] Newtons to dynes
- [ ] Ohms to siemens
- [ ] Ounces to grams
- [ ] Ounces to pounds
- [ ] Pascal to atmosphere
- [ ] Pascals to inches of mercury
- [ ] Pascals to inches of water
- [ ] Pennyweights to grams
- [ ] Percent to PPM
- [ ] Pints to liters
- [ ] Pounds to kilograms
- [ ] Pounds to ounces
- [ ] Pounds to stones
- [ ] Pounds to tons
- [ ] PPI to DPI
- [ ] PSI to bar
- [ ] PSI to megapascals
- [ ] Rad to gray
- [ ] Rad/s to RPM
- [ ] Radians to degrees
- [ ] Rem to sievert
- [ ] Roentgen to coulomb per kilogram
- [ ] RPM to rad/s
- [ ] Rutherford to becquerel
- [ ] Seconds to milliseconds
- [ ] Seconds to minutes
- [ ] Siemens to ohms
- [ ] Sievert to rem
- [ ] Slugs to kilograms
- [ ] Sound pressure level to decibels
- [ ] Square centimeters to square inches
- [ ] Square feet to acres
- [ ] Square feet to square meters
- [ ] Square inches to square centimeters
- [ ] Square kilometers to square meters
- [ ] Square meters to square feet
- [ ] Square meters to square kilometers
- [ ] Square miles to square yards
- [ ] Square yards to square miles
- [ ] Stones to pounds
- [ ] Tablespoons to milliliters
- [ ] Teaspoons to milliliters
- [ ] Terabytes to gigabytes
- [ ] Terabytes to petabytes
- [ ] Tons of refrigeration to kilowatts
- [ ] Tons to pounds
- [ ] Torr to Pascal
- [ ] Troy ounces to grams
- [ ] Volts to amps
- [ ] Volts to decibels
- [ ] Watts to amps
- [ ] Watts to BTU/hour
- [ ] Watts to decibels
- [ ] Watts to horsepower
- [ ] Weeks to months
- [ ] Yards per second to meters per second
- [ ] Yards to meters
- [ ] Yoctograms to zeptograms
- [ ] Zeptograms to yoctograms

114
verify_batch_1.py Normal file
View File

@@ -0,0 +1,114 @@
import urllib.request
import re
import math
import time
calculators = [
{
"url": "acres-to-square-feet",
"factor": 43560,
"method1": "multiply"
},
{
"url": "angstroms-to-nanometers",
"factor": 0.1,
"method1": "multiply"
},
{
"url": "apothecary-ounces-to-grams",
"factor": 31.1034768,
"method1": "multiply"
},
{
"url": "astronomical-units-to-light-years",
"factor": 0.0000158125074,
"method1": "multiply"
},
{
"url": "atmosphere-to-mmhg",
"factor": 760,
"method1": "multiply"
}
]
def extract_values_from_js(html_content):
# Added [eE\-\+] support for scientific notation (e.g., 1.5812e-05)
match1 = re.search(r'let val2.*?val1\s*([*\/\&#0-9;x]+)\s*([0-9.eE\-\+]+);', html_content)
match2 = re.search(r'let val1.*?val2\s*([*\/\&#0-9;x]+)\s*([0-9.eE\-\+]+);', html_content)
return match1, match2
def clean_op(op_str):
if "*" in op_str or "&#42;" in op_str or "x" in op_str.lower():
return "*"
elif "/" in op_str or "&#47;" in op_str:
return "/"
return op_str
def test_math(val_in, target_factor, op):
if op == "*":
return val_in * target_factor
else:
return val_in / target_factor
all_passed = True
print("Starting Bidirectional Verification Process...\n")
for calc in calculators:
base_url = f"https://howdoyouconvert.com/calculator/{calc['url']}/?ao_noptimize=1" # Bypass Autoptimize cache
print(f"Testing: {base_url}")
req = urllib.request.Request(base_url, headers={'User-Agent': 'Mozilla/5.0'})
try:
resp = urllib.request.urlopen(req)
html = resp.read().decode('utf-8')
except Exception as e:
print(" [FAIL] Could not load page:", e)
all_passed = False
continue
m1, m2 = extract_values_from_js(html)
if not m1 or not m2:
print(" [FAIL] Could not locate the injected JavaScript formulas.")
all_passed = False
continue
op1, factor1 = m1.groups()
op2, factor2 = m2.groups()
op1 = clean_op(op1)
op2 = clean_op(op2)
factor1 = float(factor1)
factor2 = float(factor2)
# 1. Forward Test
test_val1 = 10.0
expected_v2 = test_math(test_val1, calc["factor"], "*" if calc["method1"] == "multiply" else "/")
actual_v2 = test_math(test_val1, factor1, op1)
if not math.isclose(expected_v2, actual_v2, rel_tol=1e-5):
print(f" [FAIL] Forward Test mismatch! Expected {expected_v2}, got {actual_v2}")
all_passed = False
else:
print(f" [PASS] Forward Test: 10 {op1} {factor1} = {actual_v2}")
# 2. Reverse Test
test_val2 = actual_v2
expected_v1 = test_val1
actual_v1 = test_math(test_val2, factor2, op2)
if not math.isclose(expected_v1, actual_v1, rel_tol=1e-5):
print(f" [FAIL] Reverse Test mismatch! Expected {expected_v1}, got {actual_v1}")
all_passed = False
else:
print(f" [PASS] Reverse Test: {test_val2} {op2} {factor2} = {actual_v1}")
print("")
time.sleep(0.5)
if all_passed:
print("✅ Verification Complete: All 5 calculators passed bidirectional testing accurately.")
else:
print("❌ Verification Failed: One or more calculators failed math tolerances.")