Skip to content

Commit

Permalink
update report and environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodi Yang committed Mar 5, 2024
1 parent 254c210 commit eda2c01
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 248 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
- python-chromedriver-binary
- tabulate
- pre-commit
- taxcalc>=3.0.0
- taxcalc>=3.5.0
- pip
- pip:
- requests-html
Expand Down
108 changes: 12 additions & 96 deletions history/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import argparse
import pandas as pd
import taxcalc as tc
import altair as alt
from report_utils import (
run_calc,
distplot,
Expand Down Expand Up @@ -135,7 +134,7 @@ def report():
continue
chart = cbo_bar_chart(cbo_data, col, CBO_LABELS[col])
img_path = Path(CUR_PATH, f"{col}.png")
chart.save(str(img_path))
chart.write_image(str(img_path))
plot_paths.append(img_path)
cbo_projections.append(f"![]({str(img_path)})" + "{.center}")
template_args["cbo_projections"] = cbo_projections
Expand Down Expand Up @@ -166,25 +165,16 @@ def report():
new_grow["Growth Factors"] = "New"
cur_grow["Growth Factors"] = "Current"
growth_data = pd.concat([new_grow, cur_grow])
rows = list(growth_data.columns)
rows.remove("YEAR"),
rows.remove("Growth Factors")
n = len(rows) // 3
chart1 = growth_scatter_plot(growth_data, rows[:n])
img_path = Path(CUR_PATH, "growth_factors1.png")
chart1.save(str(img_path))
plot_paths.append(img_path)
growth_rate_projections.append(f"![]({str(img_path)})" + "{.center}")
chart2 = growth_scatter_plot(growth_data, rows[n : 2 * n])
img_path = Path(CUR_PATH, "growth_factors2.png")
chart2.save(str(img_path))
plot_paths.append(img_path)
growth_rate_projections.append(f"![]({str(img_path)})" + "{.center}")
chart3 = growth_scatter_plot(growth_data, rows[2 * n :])
img_path = Path(CUR_PATH, "growth_factors3.png")
chart3.save(str(img_path))
plot_paths.append(img_path)
growth_rate_projections.append(f"![]({str(img_path)})" + "{.center}")
growth_list = list(cur_grow.columns)
growth_list.remove("YEAR")
growth_list.remove("Growth Factors")
for var in growth_list:
plot = growth_scatter_plot(growth_data, var)
img_path = Path(CUR_PATH, f"{var}.png")
plot.write_image(str(img_path))
plot_paths.append(img_path)
growth_rate_projections.append(f"![]({str(img_path)})" + "{.center}")

template_args["growth_rate_projections"] = growth_rate_projections

# read CBO data
Expand All @@ -207,10 +197,8 @@ def report():
rev_url,
sheet_name="3.Individual Income Tax Details",
skiprows=8,
index_col=[0, 1],
index_col=[0, 1]
)
rev_proj = rev_proj.dropna(axis=0)

cbo_df = CBO_projections(rev_proj)

# compare tax calculator projections
Expand Down Expand Up @@ -349,78 +337,6 @@ def report():
template_args["puf_tot_cdt_table"] = None
template_args["puf_inctax_af_credit_table"] = None

# # distribution plots
# dist_vars = [
# ("c00100", "AGI Distribution"),
# ("combined", "Tax Liability Distribution"),
# ]
# dist_plots = []
# for var, title in dist_vars:
# plot = distplot(calcs, calc_labels, var, title=title)
# img_path = Path(CUR_PATH, f"{var}_dist.png")
# plot.save(str(img_path))
# plot_paths.append(img_path)
# dist_plots.append(f"![]({str(img_path)})" + "{.center}")
# template_args["cps_dist_plots"] = dist_plots

# # aggregate totals
# aggs = defaultdict(list)
# var_list = ["payrolltax", "iitax", "combined", "standard", "c04470"]
# for year in range(first_year, tc.Policy.LAST_BUDGET_YEAR + 1):
# base_aggs = run_calc(base_cps, year, var_list)
# new_aggs = run_calc(new_cps, year, var_list)
# aggs["Tax Liability"].append(base_aggs["payrolltax"])
# aggs["Tax"].append("Current Payroll")
# aggs["Year"].append(year)
# aggs["Tax Liability"].append(new_aggs["payrolltax"])
# aggs["Tax"].append("New Payroll")
# aggs["Year"].append(year)
# aggs["Tax Liability"].append(base_aggs["iitax"])
# aggs["Tax"].append("Current Income")
# aggs["Year"].append(year)
# aggs["Tax Liability"].append(new_aggs["iitax"])
# aggs["Tax"].append("New Income")
# aggs["Year"].append(year)
# aggs["Tax Liability"].append(base_aggs["combined"])
# aggs["Tax"].append("Current Combined")
# aggs["Year"].append(year)
# aggs["Tax Liability"].append(new_aggs["combined"])
# aggs["Tax"].append("New Combined")
# aggs["Year"].append(year)
# agg_df = pd.DataFrame(aggs)

# title = "Aggregate Tax Liability by Year"
# agg_chart = (
# alt.Chart(agg_df, title=title)
# .mark_line()
# .encode(
# x=alt.X(
# "Year:O",
# axis=alt.Axis(labelAngle=0, titleFontSize=20, labelFontSize=15),
# ),
# y=alt.Y(
# "Tax Liability",
# title="Tax Liability (Billions)",
# axis=alt.Axis(titleFontSize=20, labelFontSize=15),
# ),
# color=alt.Color(
# "Tax",
# legend=alt.Legend(symbolSize=150, labelFontSize=15, titleFontSize=20),
# ),
# )
# .properties(width=800, height=350)
# .configure_title(fontSize=24)
# )
# img_path = Path(CUR_PATH, "agg_plot.png")
# agg_chart.save(str(img_path))
# plot_paths.append(img_path)
# template_args["agg_plot"] = f"![]({str(img_path)})" + "{.center}"

# # create tax liability tables
# template_args["combined_table"] = agg_liability_table(agg_df, "Combined")
# template_args["payroll_table"] = agg_liability_table(agg_df, "Payroll")
# template_args["income_table"] = agg_liability_table(agg_df, "Income")

# write report and delete images used
output_path = Path(CUR_PATH, "reports", f"taxdata_report_{date}.pdf")
write_page(output_path, TEMPLATE_PATH, **template_args)
Expand Down
Loading

0 comments on commit eda2c01

Please sign in to comment.