Beispiel #1
0
def update_capacity_results_table(
    db, c, results_directory, scenario_id, subproblem, stage, results_file
):
    results = []
    with open(os.path.join(results_directory, results_file), "r") as capacity_file:
        reader = csv.reader(capacity_file)

        header = next(reader)

        for row in reader:
            project = row[0]
            period = row[1]
            new_build_mw = get_column_row_value(header, "new_build_mw", row)
            new_build_mwh = get_column_row_value(header, "new_build_mwh", row)
            new_build_binary = get_column_row_value(header, "new_build_binary", row)
            retired_mw = get_column_row_value(header, "retired_mw", row)
            retired_binary = get_column_row_value(header, "retired_binary", row)

            results.append(
                (
                    new_build_mw,
                    new_build_mwh,
                    new_build_binary,
                    retired_mw,
                    retired_binary,
                    scenario_id,
                    project,
                    period,
                    subproblem,
                    stage,
                )
            )

    # Update the results table with the module-specific results
    update_sql = """
        UPDATE results_project_capacity
        SET new_build_mw = ?,
        new_build_mwh = ?,
        new_build_binary = ?,
        retired_mw = ?,
        retired_binary = ?
        WHERE scenario_id = ?
        AND project = ?
        AND period = ?
        AND subproblem_id = ?
        AND stage_id = ?;
        """

    spin_on_database_lock(conn=db, cursor=c, sql=update_sql, data=results)
Beispiel #2
0
def update_dispatch_results_table(db, c, results_directory, scenario_id,
                                  subproblem, stage, results_file):
    results = []
    with open(os.path.join(results_directory, results_file), "r") as \
            dispatch_file:
        reader = csv.reader(dispatch_file)

        header = next(reader)

        for row in reader:
            project = row[0]
            period = row[1]
            balancing_type = row[2]
            horizon = row[3]
            timepoint = row[4]
            timepoint_weight = row[5]
            n_hours_in_tmp = row[6]
            technology = row[7]
            load_zone = row[8]
            power = row[9]
            scheduled_curtailment_mw = get_column_row_value(
                header, "scheduled_curtailment_mw", row)
            subhourly_curtailment_mw = get_column_row_value(
                header, "subhourly_curtailment_mw", row)
            subhourly_energy_delivered_mw = get_column_row_value(
                header, "subhourly_energy_delivered_mw", row)
            total_curtailment_mw = get_column_row_value(
                header, "total_curtailment_mw", row)
            committed_mw = get_column_row_value(header, "committed_mw", row)
            committed_units = get_column_row_value(header, "committed_units",
                                                   row)
            started_units = get_column_row_value(header, "started_units", row)
            stopped_units = get_column_row_value(header, "stopped_units", row)
            synced_units = get_column_row_value(header, "synced_units", row)
            auxiliary_consumption = get_column_row_value(
                header, "auxiliary_consumption_mw", row)
            gross_power = get_column_row_value(header, "gross_power_mw", row)
            ramp_up_violation = get_column_row_value(header,
                                                     "ramp_up_violation", row)
            ramp_down_violation = get_column_row_value(header,
                                                       "ramp_down_violation",
                                                       row)
            min_up_time_violation = get_column_row_value(
                header, "min_up_time_violation", row)
            min_down_time_violation = get_column_row_value(
                header, "min_down_time_violation", row)

            results.append(
                (scheduled_curtailment_mw, subhourly_curtailment_mw,
                 subhourly_energy_delivered_mw, total_curtailment_mw,
                 committed_mw, committed_units, started_units, stopped_units,
                 synced_units, auxiliary_consumption, gross_power,
                 ramp_up_violation, ramp_down_violation, min_up_time_violation,
                 min_down_time_violation, scenario_id, project, period,
                 subproblem, stage, timepoint))

    # Update the results table with the module-specific results
    update_sql = """
        UPDATE results_project_dispatch
        SET scheduled_curtailment_mw = ?,
        subhourly_curtailment_mw = ?,
        subhourly_energy_delivered_mw = ?,
        total_curtailment_mw = ?,
        committed_mw = ?,
        committed_units = ?,
        started_units = ?,
        stopped_units = ?,
        synced_units = ?,
        auxiliary_consumption_mw = ?,
        gross_power_mw = ?,
        ramp_up_violation = ?,
        ramp_down_violation = ?,
        min_up_time_violation = ?,
        min_down_time_violation = ?
        WHERE scenario_id = ?
        AND project = ?
        AND period = ?
        AND subproblem_id = ?
        AND stage_id = ?
        AND timepoint = ?;
        """

    spin_on_database_lock(conn=db, cursor=c, sql=update_sql, data=results)