Esempio n. 1
0
def run_energy_calc(
    date_min: datetime,
    date_max: datetime,
    network: NetworkSchema,
    region: Optional[str] = None,
    fueltech_id: Optional[str] = None,
    facility_codes: Optional[List[str]] = None,
    run_clear: bool = False,
) -> int:
    """Runs the actual energy calc - believe it or not"""
    generated_results: List[Dict] = []

    flow = None

    if fueltech_id:
        flow = fueltech_to_flow(fueltech_id)

    # @TODO get rid of the hard-coded networknem part
    if flow and region and network == NetworkNEM:
        generated_results = get_flows(date_min,
                                      date_max,
                                      network_region=region,
                                      network=network,
                                      flow=flow)
    else:
        generated_results = get_generated(
            date_min,
            date_max,
            network_region=region,
            network=network,
            fueltech_id=fueltech_id,
            run_clear=run_clear,
            facility_codes=facility_codes,
        )

    num_records = 0

    try:
        if len(generated_results) < 1:
            logger.warning(
                "No results from get_generated query for {} {} {}".format(
                    region, date_max, fueltech_id))
            return 0

        generated_frame = shape_energy_dataframe(generated_results,
                                                 network=network)

        num_records = insert_energies(generated_frame, network=network)

        logger.info("Done {} for {} => {}".format(region, date_min, date_max))
    except Exception as e:
        error_traceback = e.with_traceback()

        if error_traceback:
            logger.error(error_traceback)
        else:
            logger.error(e)

    return num_records
Esempio n. 2
0
def test_energy_sum_average_fixture() -> None:
    records = load_energy_fixture_csv("power_nem_nsw1_coal_black_1_week.csv")

    power_results_bw01 = list(
        filter(lambda x: x["facility_code"] == "BW01", records))

    power_df = shape_energy_dataframe(power_results_bw01)

    energy_sum(power_df, NetworkNEM)

    assert len(records) == 32288, "Right length of records"
Esempio n. 3
0
def _test_energy_sum_outputs() -> None:
    records = load_energy_fixture_csv("nem_generated_coal_black.csv")

    assert len(records) == 50, "Has the correct number of records"

    power_df = shape_energy_dataframe(records)

    assert len(power_df) == 50, "Has the correct number of records"

    es = energy_sum(power_df, NetworkNEM)

    # should be 50 records
    assert len(es) == 1536, "Has the correct number of records"

    assert es.eoi_quantity.sum() > 1000, "Has energy value"

    return es
Esempio n. 4
0
def run_energy_calc(
    region: str,
    date_min: datetime,
    date_max: datetime,
    network: NetworkSchema,
    fueltech_id: Optional[str] = None,
) -> int:
    generated_results: List[Dict] = []

    flow = None

    if fueltech_id:
        flow = fueltech_to_flow(fueltech_id)

    if flow:
        generated_results = get_flows(region,
                                      date_min,
                                      date_max,
                                      network=network,
                                      flow=flow)
    else:
        generated_results = get_generated(region,
                                          date_min,
                                          date_max,
                                          network=network,
                                          fueltech_id=fueltech_id)

    num_records = 0

    try:
        if len(generated_results) < 1:
            logger.warning(
                "No results from get_generated query for {} {} {}".format(
                    region, date_max, fueltech_id))
            return 0

        generated_frame = shape_energy_dataframe(generated_results)

        num_records = insert_energies(generated_frame, network=network)

        logger.info("Done {} for {} => {}".format(region, date_min, date_max))
    except Exception as e:
        logger.error(e)
        slack_message("Energy archive error: {}".format(e))

    return num_records