# Data-generating model shared by make_data.py and simulation.py. Python 3.13, NumPy.
# Viability signal in wells: control, drug A alone, drug B alone, A + B, on one plate per independent experiment.
import numpy as np
GROUPS = ("control", "A", "B", "A+B")
WELLS = 3                        # technical replicate wells per condition and plate

def experiment(rng, sf_a=0.6, sf_b=0.5, sf_ab=0.30, sd_day=0.20, sd_plate_effect=0.10, sd_well=0.08):
    """One independent experiment (one plate, one day). Surviving fractions on the log scale get a plate-specific
    deviation for each treated condition; wells scatter around the plate means. Under Bliss independence sf_ab = sf_a * sf_b."""
    base = np.log(1000) + rng.normal(0, sd_day)                    # plate-wide signal level for this day
    logsf = {"control": 0.0, "A": np.log(sf_a), "B": np.log(sf_b), "A+B": np.log(sf_ab)}
    rows = []
    for g in GROUPS:
        dev = 0.0 if g == "control" else rng.normal(0, sd_plate_effect)   # this plate's response differs a little
        for w in range(WELLS):
            rows.append((g, w + 1, np.exp(base + logsf[g] + dev + rng.normal(0, sd_well))))
    return rows
