feat: Add batch processing scripts for complex calculator creation and verification, and update the calculator list.
This commit is contained in:
75
verify_batch_3.py
Normal file
75
verify_batch_3.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import urllib.request
|
||||
import re
|
||||
import json
|
||||
import time
|
||||
|
||||
# Batch 3 Registry for Verification
|
||||
batch_3_registry = [
|
||||
{"url": "https://howdoyouconvert.com/calculator/carats-to-grams/?ao_noptimize=1", "f": 0.2, "b": 0, "v1": 5, "ev2": 1},
|
||||
{"url": "https://howdoyouconvert.com/calculator/celsius-to-fahrenheit/?ao_noptimize=1", "f": 1.8, "b": 32, "v1": 0, "ev2": 32},
|
||||
{"url": "https://howdoyouconvert.com/calculator/centimeters-to-inches/?ao_noptimize=1", "f": 0.393700787, "b": 0, "v1": 2.54, "ev2": 1},
|
||||
{"url": "https://howdoyouconvert.com/calculator/cfs-to-cms/?ao_noptimize=1", "f": 0.0283168466, "b": 0, "v1": 100, "ev2": 2.83168466},
|
||||
{"url": "https://howdoyouconvert.com/calculator/cms-to-cfs/?ao_noptimize=1", "f": 35.3146667, "b": 0, "v1": 1, "ev2": 35.3146667},
|
||||
{"url": "https://howdoyouconvert.com/calculator/coulomb-per-kilogram-to-roentgen/?ao_noptimize=1", "f": 3875.96899, "b": 0, "v1": 1, "ev2": 3875.96899},
|
||||
{"url": "https://howdoyouconvert.com/calculator/cups-to-milliliters/?ao_noptimize=1", "f": 236.588237, "b": 0, "v1": 1, "ev2": 236.588237},
|
||||
{"url": "https://howdoyouconvert.com/calculator/curie-to-becquerel/?ao_noptimize=1", "f": 3.7e10, "b": 0, "v1": 1, "ev2": 37000000000},
|
||||
{"url": "https://howdoyouconvert.com/calculator/daltons-to-amu/?ao_noptimize=1", "f": 1.0, "b": 0, "v1": 1, "ev2": 1},
|
||||
{"url": "https://howdoyouconvert.com/calculator/days-to-hours/?ao_noptimize=1", "f": 24.0, "b": 0, "v1": 1, "ev2": 24},
|
||||
]
|
||||
|
||||
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: let val2 = val1 * factor + offset;
|
||||
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']})")
|
||||
|
||||
if abs(v2 - 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_3_registry:
|
||||
if not verify_math(c): all_ok = False
|
||||
time.sleep(1)
|
||||
|
||||
if all_ok: print("\nALL BATCH 3 VERIFIED.")
|
||||
else: print("\nBATCH 3 FAILED.")
|
||||
Reference in New Issue
Block a user