Skip to content

Commit

Permalink
move output file names to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed Sep 24, 2024
1 parent 503165e commit 256e697
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/acquisition/rvdss/rvdss_historic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Script to fetch historical data, before data reporting moved to the dashboard
format. This covers dates from the 2014-2015 season to tne 2023-2024 season.
format. This covers dates from the 2014-2015 season to the 2023-2024 season.
This script should not be run in production; it will not fetch newly-posted
data.
Expand All @@ -16,7 +16,8 @@

from delphi.epidata.acquisition.rvdss.constants import (
DASHBOARD_BASE_URLS_2023, HISTORIC_SEASON_URL,
ALTERNATIVE_SEASON_BASE_URL, SEASON_BASE_URL, LAST_WEEK_OF_YEAR
ALTERNATIVE_SEASON_BASE_URL, SEASON_BASE_URL, LAST_WEEK_OF_YEAR,
RESP_COUNTS_OUTPUT_FILE, POSITIVE_TESTS_OUTPUT_FILE
)
from delphi.epidata.acquisition.rvdss.utils import (
abbreviate_virus, abbreviate_geo, create_geo_types, check_date_format,
Expand Down Expand Up @@ -454,8 +455,8 @@ def get_season_reports(url):
all_number_tables=pd.concat([all_number_tables,number_detections_table])

# write files to csvs
all_respiratory_detection_table.to_csv(path+"/respiratory_detections.csv", index=True)
all_positive_tables.to_csv(path+"/positive_tests.csv", index=True)
all_respiratory_detection_table.to_csv(path+"/" + RESP_COUNTS_OUTPUT_FILE, index=True)
all_positive_tables.to_csv(path+"/" + POSITIVE_TESTS_OUTPUT_FILE, index=True)

# Write the number of detections table to csv if it exists (i.e has rows)
if len(all_number_tables) != 0:
Expand All @@ -468,8 +469,8 @@ def main():
# Update the end of the 2023-2024 season with the dashboard data

# Load old csvs
old_detection_data = pd.read_csv('season_2023_2024/respiratory_detections.csv').set_index(['epiweek', 'time_value', 'issue', 'geo_type', 'geo_value'])
old_positive_data = pd.read_csv('season_2023_2024/positive_tests.csv').set_index(['epiweek', 'time_value', 'issue', 'geo_type', 'geo_value'])
old_detection_data = pd.read_csv('season_2023_2024/' + RESP_COUNTS_OUTPUT_FILE).set_index(['epiweek', 'time_value', 'issue', 'geo_type', 'geo_value'])
old_positive_data = pd.read_csv('season_2023_2024/' + POSITIVE_TESTS_OUTPUT_FILE).set_index(['epiweek', 'time_value', 'issue', 'geo_type', 'geo_value'])

for base_url in DASHBOARD_BASE_URLS_2023:
# Get weekly dashboard data
Expand All @@ -485,8 +486,8 @@ def main():
old_positive_data= pd.concat([old_positive_data,positive_data],axis=0)

# Overwrite/update csvs
old_detection_data.to_csv('season_2023_2024/respiratory_detections.csv',index=True)
old_positive_data.to_csv('season_2023_2024/positive_tests.csv',index=True)
old_detection_data.to_csv('season_2023_2024/' + RESP_COUNTS_OUTPUT_FILE,index=True)
old_positive_data.to_csv('season_2023_2024/' + POSITIVE_TESTS_OUTPUT_FILE,index=True)

if __name__ == '__main__':
main()
11 changes: 8 additions & 3 deletions src/acquisition/rvdss/rvdss_update.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""
Script to fetch new data, after data reporting moved to the dashboard
format. This covers dates following the 2023-2024 season (exclusive).
"""

import pandas as pd
import os

from delphi.epidata.acquisition.rvdss.utils import get_weekly_data, get_revised_data
from delphi.epidata.acquisition.rvdss.constants import DASHBOARD_BASE_URL
from delphi.epidata.acquisition.rvdss.constants import DASHBOARD_BASE_URL, RESP_COUNTS_OUTPUT_FILE, POSITIVE_TESTS_OUTPUT_FILE


def main():
weekly_data = get_weekly_data(DASHBOARD_BASE_URL,2024).set_index(['epiweek', 'time_value', 'issue', 'geo_type', 'geo_value'])
positive_data = get_revised_data(DASHBOARD_BASE_URL)

path1 = './respiratory_detections.csv'
path2 = './positive_tests.csv'
path1 = './' + RESP_COUNTS_OUTPUT_FILE
path2 = './' + POSITIVE_TESTS_OUTPUT_FILE

if os.path.exists(path1)==False:
weekly_data.to_csv(path1,index=True)
Expand Down

0 comments on commit 256e697

Please sign in to comment.