Import('*')
import pandas as pd
import numpy as np

papers = ['Reimers_Waldfogel_2021', 'Finkelstein_Gentzkow_Williams_2021',
               'Goodman-Bacon_2021', 'Abebe_Caria_Ortiz-Ospina_2021',
	           'Mueller_Spinnewijn_Topa_2021', 'Kostol_Myhre_2021',
               'Bailey_Sun_Timpe_2021', 'Seibold_2021', 'Dinerstein_Smith_2021',
               'Adermon_Lindahl_Palme_2021', 'Bourreau_Sun_Verboven_2021', 'Weaver_2021',
               'Braguinsky_Ohyama_Okazaki_Syverson_2021', 'Kanzig_2021']

target = ['#output/figures/pp_plot_some.lyx',
	  '#output/figures/pp_plot_all.lyx']
source = ['#source/figures/compile_pp_plots.py',
	'#source/figures/pp_plot_all.lyx',
	'#source/figures/pp_plot_some.lyx',
	'#output/analysis/bootstrap_census/bootstrap_census.csv',
	'#source/figures/LyxBuilder.py']

df_objects = pd.read_csv('../../source/raw/bootstrap_census/source/raw/orig/objects_of_interest.csv')
df_objects = df_objects[np.invert((df_objects['can_produce_replicates'] != 'X').values ^ (df_objects['can_produce_replicates'] != 'N').values)]

for paper in papers:
    df_paper = df_objects[df_objects['citation'] == paper]
    objects = df_paper['shortname_object'].values
    
    for object in objects:
        source += [f'#output/analysis/pp_plots/{paper}/{object}.png']

env.Python(target, source)


max_objects_both = ['QALYsSaved', 'AdopteesExtendedFam', 'IRRfemale', 'CPIResponse',
                     'FractionNonoptimizers', 'ReductionInVarianceEqualizingHealthCapital', 
                     'MeanCostPerGrade', 'PriceTotalSurplus', 'UpgradesCum', 'ShareExplainedBySelection',
                     'GvmntEndogAppUB', 'EarlyRetirementAge', 'ATETcompletedCollege']
#max_tv_objects = max_objects_both + ['AmazonStarElasticity']
max_sk_objects = max_objects_both + ['AnnualPercentageIncreaseFollowingNYT']


target = ['#source/figures/distance_sk.lyx']
source = ['#output/analysis/bootstrap_census/distance_sk.eps']
env.Depends(target = target, dependency = source)


target = ['#source/figures/bayes_scatter.lyx']
source = ['#output/analysis/bayes_bootstrap/bayes_scatter.eps']
env.Depends(target = target, dependency = source)


target = ['#source/figures/example_bb.lyx']
source = [
     '#output/analysis/example/example_bb_effect.png',
     '#output/analysis/example/example_bb_costpervote.png',
]
env.Depends(target = target, dependency = source)

target = ['#source/figures/example_bvm.lyx']
source = [
    '#output/analysis/example/posterior_density.eps',
    '#output/analysis/example/posterior_density.eps',
]
env.Depends(target = target, dependency = source)

target = ['#source/figures/example_posterior.lyx']
prior_types = ['more_pessimistic','less_pessimistic','central','less_optimistic','more_optimistic']
source = [
    f'#output/analysis/example/{type}_prior.eps' for type in prior_types] + [
    f'#output/analysis/example/{type}_posterior.eps' for type in prior_types] + [
    f'#output/analysis/example/{type}_posterior_cost_per_vote.eps' for type in prior_types] + [
    f'#output/analysis/example/{type}_prior_risk.eps' for type in prior_types]
env.Depends(target = target, dependency = source)

target = ['#source/figures/example_sk.lyx']
source = [
    '#output/analysis/example/example_sk_effect.png',
    '#output/analysis/example/example_sk_costpervote.png',
]
env.Depends(target = target, dependency = source)
