from typing import Dict
from typing import Tuple
import re


def parse_ps() -> Dict[float, Tuple[float, float]]:
    """
    Parses output from job-threePN-est-p.sh.

    Returns
        Dict mapping `mm` to an MC estimate of the covering probability `p` and
        associated error `p_err`.
    """
    with open("../scripts/threePN-p.txt", "r") as f:
        lines = f.readlines()

    ps = {}
    for i in range(len(lines) // 2):
        mm = float(re.search("mm=(\d\.\d*)", lines[2 * i]).group(1))  # type: ignore

        match = re.search("p = (\d\.\d*) \+\/\- (\d\.\d*)", lines[2 * i + 1])  # type: ignore
        p = float(match.group(1))  # type: ignore
        p_err = float(match.group(2))  # type: ignore

        ps[mm] = (p, p_err)

    return ps