def setUpTestData(cls): cls.project = Project.objects.create() make_cdc_units_and_targets(cls.project) cls.forecast_model = ForecastModel.objects.create( project=cls.project, name='name', abbreviation='abbrev') time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2017, 1))) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW1-KoTstable-2017-01-17.csv' ) # EW01 2017 cls.forecast1 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2017, 2))) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW2-KoTstable-2017-01-23.csv' ) # EW02 2017 cls.forecast2 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2016, 51))) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW51-KoTstable-2017-01-03.csv' ) # EW51 2016 cls.forecast3 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2016, 52))) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW52-KoTstable-2017-01-09.csv' ) # EW52 2016 cls.forecast4 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) # 'mini' season for testing. from: # model_error_calculations.txt -> model_error_calculations.py -> model_error_calculations.xlsx: cls.exp_target_to_mae = { '1 wk ahead': 0.215904853, '2 wk ahead': 0.458186984, '3 wk ahead': 0.950515864, '4 wk ahead': 1.482010693 } load_truth_data( cls.project, Path('forecast_app/tests/truth_data/mean-abs-error-truths.csv')) # score needed for MAE calculation Score.ensure_all_scores_exist() cls.score = Score.objects.filter( abbreviation='abs_error').first() # hard-coded official abbrev cls.score.update_score_for_model(cls.forecast_model)
def _monday_date_from_ew_and_season_start_year(ew_week, season_start_year): """ :param ew_week: an epi week from within a cdc csv forecast file. e.g., 1, 30, 52 :param season_start_year :return: a datetime.date that is the Monday of the EW corresponding to the args """ if ew_week < SEASON_START_EW_NUMBER: sunday_date = pymmwr.mmwr_week_to_date(season_start_year + 1, ew_week) else: sunday_date = pymmwr.mmwr_week_to_date(season_start_year, ew_week) return sunday_date + datetime.timedelta(days=1)
def setUpTestData(cls): cls.project = Project.objects.create() make_cdc_units_and_targets(cls.project) cls.forecast_model = ForecastModel.objects.create( project=cls.project, name='name', abbreviation='abbrev') csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW1-KoTstable-2017-01-17.csv' ) # EW01 2017 time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2017, 1))) cls.forecast1 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW2-KoTstable-2017-01-23.csv' ) # EW02 2017 time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2017, 2))) cls.forecast2 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW51-KoTstable-2017-01-03.csv' ) # EW51 2016 time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2016, 51))) cls.forecast3 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero) csv_file_path = Path( 'forecast_app/tests/model_error/ensemble/EW52-KoTstable-2017-01-09.csv' ) # EW52 2016 time_zero = TimeZero.objects.create( project=cls.project, timezero_date=(pymmwr.mmwr_week_to_date(2016, 52))) cls.forecast4 = load_cdc_csv_forecast_file(2016, cls.forecast_model, csv_file_path, time_zero)