Datasets:
Download source/tests/solvers/cmp_rainfall.py from Syndicate604/skills-desk: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/solvers/cmp_rainfall.py
- Command line
-
hf download hf://datasets/Syndicate604/skills-desk/source/tests/solvers/cmp_rainfall.py
-
curl -L -o cmp_rainfall.py https://huggingface.co/datasets/Syndicate604/skills-desk/resolve/main/source/tests/solvers/cmp_rainfall.py
1.03 kB
| import csv, os | |
| f = {"mm": 1, "cm": 10, "in": 25.4} | |
| latest = {} | |
| for r in csv.DictReader(open("readings.csv")): | |
| latest[(r["station"], r["date"])] = float(r["amount"]) * f[r["unit"]] | |
| gauges = list(csv.DictReader(open("gauges.csv"))) if os.path.exists("gauges.csv") else [] | |
| rejected = {(r["station"], r["date"]) for r in csv.DictReader(open("qc.csv")) if r["decision"] == "reject"} if os.path.exists("qc.csv") else set() | |
| def scale(s, d): | |
| rows = sorted((g["installed"], float(g["scale"])) for g in gauges if g["station"] == s and g["installed"] <= d) | |
| return rows[-1][1] if rows else 1.0 | |
| st = {} | |
| for (s, d), v in latest.items(): | |
| if (s, d) in rejected: | |
| st.setdefault(s, []) | |
| continue | |
| st.setdefault(s, []).append(v * scale(s, d)) | |
| w = csv.writer(open("rainfall.csv", "w", newline="")) | |
| w.writerow(["station", "total_mm", "wet_days", "mean_mm_per_wet_day"]) | |
| for s, vals in st.items(): | |
| wet = [v for v in vals if v > 0] | |
| w.writerow([s, f"{sum(vals):.1f}", len(wet), f"{sum(vals) / len(wet):.2f}"]) | |