File size: 2,306 Bytes
c5e9b7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#%% 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_aggregated.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_aggregated.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.")
# %%