feat: Add batch processing scripts for complex calculator creation and verification, and update the calculator list.

This commit is contained in:
Ben
2026-02-21 00:29:54 -08:00
parent ad0660adba
commit 569b11d2ea
12 changed files with 1988 additions and 48 deletions

77
verify_batch_4.py Normal file
View File

@@ -0,0 +1,77 @@
import urllib.request
import re
import json
import time
# Batch 4 Registry for Verification
batch_4_registry = [
{"url": "https://howdoyouconvert.com/calculator/days-to-weeks/?ao_noptimize=1", "f": 1/7, "b": 0, "v1": 14, "ev2": 2},
{"url": "https://howdoyouconvert.com/calculator/days-to-years/?ao_noptimize=1", "f": 1/365.25, "b": 0, "v1": 365.25, "ev2": 1},
{"url": "https://howdoyouconvert.com/calculator/degrees-to-mils/?ao_noptimize=1", "f": 17.777777778, "b": 0, "v1": 1, "ev2": 17.777777778},
{"url": "https://howdoyouconvert.com/calculator/degrees-to-radians/?ao_noptimize=1", "f": 0.0174532925, "b": 0, "v1": 180, "ev2": 3.14159265},
{"url": "https://howdoyouconvert.com/calculator/dynes-to-newtons/?ao_noptimize=1", "f": 1e-5, "b": 0, "v1": 100000, "ev2": 1},
{"url": "https://howdoyouconvert.com/calculator/ergs-to-joules/?ao_noptimize=1", "f": 1e-7, "b": 0, "v1": 10000000, "ev2": 1},
{"url": "https://howdoyouconvert.com/calculator/feet-to-meters/?ao_noptimize=1", "f": 0.3048, "b": 0, "v1": 1, "ev2": 0.3048},
{"url": "https://howdoyouconvert.com/calculator/foot-pounds-to-newton-meters/?ao_noptimize=1", "f": 1.35581795, "b": 0, "v1": 1, "ev2": 1.35581795},
{"url": "https://howdoyouconvert.com/calculator/gallons-to-liters/?ao_noptimize=1", "f": 3.78541178, "b": 0, "v1": 1, "ev2": 3.78541178},
{"url": "https://howdoyouconvert.com/calculator/gigabytes-to-megabytes/?ao_noptimize=1", "f": 1000.0, "b": 0, "v1": 1, "ev2": 1000},
]
def verify_math(calc):
print(f"\n--- Verifying {calc['url']} ---")
headers = {"User-Agent": "Mozilla/5.0"}
try:
req = urllib.request.Request(calc['url'], headers=headers)
resp = urllib.request.urlopen(req).read().decode('utf-8')
scripts = re.findall(r'<script.*?>\s*(.*?)\s*</script>', resp, re.DOTALL)
logic_script = ""
for s in scripts:
if "calculate1" in s and "document.getElementById" in s:
logic_script = s
break
if not logic_script:
print("FAILED: Logic script not found.")
return False
# Extract formula: val2 = val1 * factor + offset;
# Matches: let val2 = val1 * 0.14285714285714285 + 0;
fwd_match = re.search(r'let val2 = val1 \* (.*?) \+ (.*?);', logic_script)
rev_match = re.search(r'let val1 = \(val2 - (.*?)\) \/ (.*?);', logic_script)
if not fwd_match or not rev_match:
print("FAILED: Could not parse m/b components.")
return False
m_actual = float(fwd_match.group(1))
b_actual = float(fwd_match.group(2))
print(f"Detected Formula: y = {m_actual}x + {b_actual}")
# Test math locally
v2 = calc['v1'] * m_actual + b_actual
v1 = (v2 - b_actual) / m_actual
print(f"Test v1={calc['v1']} -> v2={v2} (Expected {calc['ev2']})")
print(f"Test v2={v2} -> v1={v1} (Expected {calc['v1']})")
# Allow small floating point difference
if abs(v2 - calc['ev2']) < max(1e-7, calc['ev2'] * 1e-7) and abs(v1 - calc['v1']) < 1e-7:
print("SUCCESS")
return True
else:
print("FAILED math check")
return False
except Exception as e:
print(f"ERROR: {e}")
return False
all_ok = True
for c in batch_4_registry:
if not verify_math(c): all_ok = False
time.sleep(1)
if all_ok: print("\nALL BATCH 4 VERIFIED.")
else: print("\nBATCH 4 FAILED.")