Skip to content

Commit

Permalink
Minor refactor to accommodate sample weighting csv generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolny committed Dec 12, 2024
1 parent 0c4e7c1 commit 452f144
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from utils.forecast import fetch_and_clean_data
from utils.weights import apply_weights
from utils.weights import apply_weights_simple
from utils.zones import get_ventilation_index_zones


def main():
forecast_data = fetch_and_clean_data()
weighted_forecast_data = apply_weights(forecast_data)
weighted_forecast_data = apply_weights_simple(forecast_data)
ventilation_index_zones = get_ventilation_index_zones()


Expand Down
4 changes: 2 additions & 2 deletions tests/test_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from numpy.testing import assert_equal
from pandas import DataFrame

from utils.weights import _create_weight_column, _get_weights
from utils.weights import _create_weight_column, _apply_weight_of_1


def test_create_weights_column():
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_get_weights():
"024": test_geo_data_frame_2,
}

result = _get_weights(test_data)
result = _apply_weight_of_1(test_data)

assert "012" in result
geo_data_frame_with_weights_1 = result["012"]
Expand Down
18 changes: 18 additions & 0 deletions utils/csv_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from forecast import fetch_and_clean_data
from weights import apply_weights_simple


OUTPUT_FILEPATH = "./tmp/sample.csv"


def generate_csv_sample() -> None:
# Generate a sample csv file that can be ingested by the weighting algorithm.
forecasts = fetch_and_clean_data()
single_forecast = {"012": forecasts["012"]}
weighted_forecast = apply_weights_simple(single_forecast)

weighted_forecast["012"].to_csv(OUTPUT_FILEPATH, columns=["y", "x", "latitude", "longitude", "weight"], index=False)


if __name__ == "__main__":
generate_csv_sample()
6 changes: 3 additions & 3 deletions utils/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _create_weight_column(forecast_data: dict[str, GeoDataFrame]) -> dict[str, G
return forecasts_with_weight_column


def _get_weights(forecast_data: dict[str, GeoDataFrame]) -> dict[str, GeoDataFrame]:
def _apply_weight_of_1(forecast_data: dict[str, GeoDataFrame]) -> dict[str, GeoDataFrame]:
# For now, fill the weights with 1. At some point in the future we will have
# a weights configuration file generated by data scientists.
forecasts_with_weights = {}
Expand All @@ -21,7 +21,7 @@ def _get_weights(forecast_data: dict[str, GeoDataFrame]) -> dict[str, GeoDataFra
return forecasts_with_weights


def apply_weights(forecast_data: dict[str, GeoDataFrame]) -> dict[str, GeoDataFrame]:
def apply_weights_simple(forecast_data: dict[str, GeoDataFrame]) -> dict[str, GeoDataFrame]:
forecast_data_with_column = _create_weight_column(forecast_data)
weighted_data = _get_weights(forecast_data_with_column)
weighted_data = _apply_weight_of_1(forecast_data_with_column)
return weighted_data

0 comments on commit 452f144

Please sign in to comment.