Skip to content

Commit

Permalink
close #70; Add from_config class method to instantiate AllRainfall cl…
Browse files Browse the repository at this point in the history
…ass from configuration
  • Loading branch information
paul-florentin-charles committed Aug 15, 2024
1 parent 3aeece5 commit 5e3bb62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 1 addition & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
from src.api.utils import (
raise_time_mode_error_or_do_nothing,
)
from src.config import Config
from src.core.models.all_rainfall import AllRainfall
from src.core.utils.enums.months import Month
from src.core.utils.enums.seasons import Season
from src.core.utils.enums.time_modes import TimeMode

cfg = Config()
all_rainfall = AllRainfall(
cfg.get_dataset_path(), cfg.get_start_year(), cfg.get_rainfall_precision()
)
all_rainfall = AllRainfall.from_config()

app = FastAPI(
debug=True,
Expand Down
12 changes: 12 additions & 0 deletions src/core/models/all_rainfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pandas as pd

from src.config import Config
from src.core.models.monthly_rainfall import MonthlyRainfall
from src.core.models.seasonal_rainfall import SeasonalRainfall
from src.core.models.yearly_rainfall import YearlyRainfall
Expand All @@ -30,6 +31,7 @@ class AllRainfall:
def __init__(
self,
dataset_url_or_path: str,
*,
start_year=1971,
round_precision=2,
):
Expand All @@ -53,6 +55,16 @@ def __init__(
for season in Season
}

@classmethod
def from_config(cls, from_file=False):
cfg = Config()

return cls(
cfg.get_dataset_path() if from_file else cfg.get_dataset_url(),
start_year=cfg.get_start_year(),
round_precision=cfg.get_rainfall_precision(),
)

def export_all_data_to_csv(self, folder_path="csv_data") -> str:
"""
Export all the different data as CSVs into specified folder path.
Expand Down

0 comments on commit 5e3bb62

Please sign in to comment.