Import('*')

# =============================================================================
# FRED raw data download
#
# This step is NOT part of the default build.  It reaches out to FRED and
# overwrites the raw vintage the published paper was built on; FRED revises its
# series, so refreshing will move the published numbers.  Run it deliberately:
#
#     scons refresh_raw=1
# =============================================================================

# Code paths
FRED_CODE = '#source/raw/fred'

# Data paths
FRED_ORIG = '#datastore/raw/fred/orig'
FRED_DATA = '#datastore/raw/fred/data'

# Series downloaded by the script, grouped as it groups them
CONS_GDP_VARS = ['PCE', 'A794RX0Q048SBEA', 'GDPC1',
                 'DPCERAM1M225NBEA', 'A939RX0Q048SBEA']
IR_VARS = ['FEDFUNDS', 'DGS1', 'DGS5', 'DGS10', 'DGS30',
           'DFII5', 'DFII10', 'AAA10Y']
INFLATION_VARS = ['CPIAUCSL', 'MICH', 'T10YIE', 'FPCPITOTLZGUSA', 'GDPDEF']
OTHER_VARS = ['GFDEGDQ188S', 'MZM', 'M2SL']

ALL_VARS = CONS_GDP_VARS + IR_VARS + INFLATION_VARS + OTHER_VARS

# 01: Download FRED series
# Every file the script writes is declared here, so the build system knows the
# raw files come from this step rather than appearing from nowhere.
target = ([f'{FRED_ORIG}/annual/{series}.dta' for series in ALL_VARS] +
          [f'{FRED_ORIG}/default/{series}.dta' for series in ALL_VARS] +
          [f'{FRED_DATA}/fred_gdp_consumption.dta',
           f'{FRED_DATA}/fred_interest_rates.dta',
           f'{FRED_DATA}/fred_inflation.dta'])
source = [f'{FRED_CODE}/01_download_series_from_fred.do']
env.Stata(target, source)
