# Every computed number of the guide that is not a calculator case. All inputs are constructed examples, not channel data.
import subprocess, sys
from decimal import Decimal, getcontext
getcontext().prec = 40
def run(*a):
    r = subprocess.run([sys.executable, "ctr.py", *a], capture_output=True, text=True)
    return r.stdout.strip() or r.stderr.strip()
print("== 1. pooled CTR against the plain average of row CTRs (videos.csv, constructed)")
print(run("file", "videos.csv"))
print("== 2. the views-over-impressions trap (constructed: 10,000 counted impressions, 450 views from them, 300 other views)")
imps, from_imps, other = Decimal(10000), Decimal(450), Decimal(300)
print("CTR from counted impressions  =", from_imps / imps * 100, "%")
print("total views / impressions     =", (from_imps + other) / imps * 100, "%")
print("== 3. same CTR, different amount of data (constructed 4.5%)")
print("9 clicks in 200 impressions:      ", run("range", "9", "200"))
print("900 clicks in 20,000 impressions: ", run("range", "900", "20000"))
print("== 4. control for the interval: 50 of 100 is 50% and the hand calculation gives about 40.38% to 59.62%")
print(run("range", "50", "100"))
print("== 5. two constructed thumbnails, same share, 200 impressions each")
print("A 8 clicks:  ", run("range", "8", "200"))
print("B 10 clicks: ", run("range", "10", "200"))
