#%% uses the latest version of aggregated inputs to create the dictionary of costs import json import sys import pandas as pd from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent)) from utils.data_utils import strip_unit_suffix def build_method_groups(df): """Build the method_groups dict from the CSV Method group and Implementation columns. Group and method order follows first appearance in inputs.csv.""" method_groups = {} for _, row in df.drop_duplicates(subset=["Implementation"]).iterrows(): m, g = row["Implementation"], row["Method group"] method_groups.setdefault(g, []) if m not in method_groups[g]: method_groups[g].append(m) return method_groups def build_secondary_resources(df): """Build the full set of (method, resource) secondary pairs from the CSV 'Is secondary' column.""" secondary = set() for _, row in df[df["Is secondary"] == True].iterrows(): secondary.add((row["Implementation"], row["Resource"])) return secondary def create_sliders_inputs(): df = pd.read_csv("data/inputs.csv") cost_sliders = {} for _, row in df.iterrows(): method = row["Implementation"] resource = row["Resource"] + " (" + row["Unit"] + ")" if row["min"] == row["max"] and row["Resource"] != "Geologic storage": row["min"] = row["min"] * .5 entry = { "min": float(row["min"]), "median": float(row["median"]), "max": float(row["max"]) } cost_sliders.setdefault(method, {})[resource] = entry with open("data/cost_sliders.json", "w") as f: json.dump(cost_sliders, f, indent=2) print("Saved cost_sliders.json") method_groups = build_method_groups(df) with open("data/method_groups.json", "w") as f: json.dump(method_groups, f, indent=2) print("Saved method_groups.json") secondary_resources = build_secondary_resources(df) with open("data/secondary_resources.json", "w") as f: json.dump(sorted(secondary_resources), f, indent=2) print(f"Saved secondary_resources.json ({len(secondary_resources)} pairs)") if __name__ == "__main__": create_sliders_inputs() print("Script executed successfully.") # %%