-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathyear_summary.py
175 lines (148 loc) · 5.51 KB
/
year_summary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import pandas as pd
import streamlit as st
import plotly.graph_objs as go
@st.cache()
def plot_year_summary():
# plot year-end summary on top of each page
# load data
df_summary = pd.read_csv('data/cleaned/app_year_summary.csv', index_col = (0,1))
##### get summary data for 2020, 2020 YTM, 2021 YTM #####
# get most recent month in 2021 YTD
last_month = df_summary.loc[2021].index.max()
# get summary information
summary_2020 = df_summary.loc[(2020,)].sum()
summary_2021 = df_summary.loc[(2021,)].sum()
idx = pd.IndexSlice
summary_2020_YTM = df_summary.loc[idx[2020, range(last_month + 1)], idx[:]].sum()
# add monetary bail percentage for all summaries
summary_2020["monetary_bail_perct"] = summary_2020["monetary_bail"]/summary_2020["count"]
summary_2020_YTM["monetary_bail_perct"] = summary_2020_YTM["monetary_bail"] / summary_2020_YTM["count"]
summary_2021["monetary_bail_perct"] = summary_2021["monetary_bail"]/summary_2021["count"]
##### plot yearly summary on top #####
fig = go.Figure()
# find string corresponding to last month
month = {1: "Jan",
2: "Feb",
3: "Mar",
4: "Apr",
5: "May",
6: "Jun",
7: "Jul",
8: "Aug",
9: "Sep",
10: "Oct",
11: "Nov",
12: "Dec"}
month_str = month[last_month]
# assign heights of rows
y1_2020 = 0.5
y2_2020 = 0.75
y1_2020_YTM = 0.25
y2_2020_YTM = 0.5
y1_2021 = 0
y2_2021 = 0.25
# assign columns
c0 = 0.12
c1 = 0.34
c2 = 0.56
c3 = 0.78
# 2020 data
fig.add_trace(go.Indicator(
mode = "number",
value = 2020,
number={"font":{"size": 12}},
domain = {'x': [0, c0], 'y': [y1_2020, y2_2020]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020["bail_amount"],
title = {"text": "<span style='font-size:1.4em'>Amount of bail set</span>"},
number = {"prefix": "$",
"font":{"size": 30}},
domain = {'x': [c0, c1], 'y': [y1_2020, y2_2020]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020["bail_paid"],
title = {"text": "<span style='font-size:1.4em'>Amount of bail paid</span>"},
number = {"prefix": "$",
"font":{"size":30}},
domain = {'x': [c1, c2], 'y': [y1_2020, y2_2020]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020["monetary_bail_perct"]*100,
title = {"text": "<span style='font-size:1.4em'>Percentage of bail set</span>"},
number = {"suffix": "%",
"font":{"size":30}},
domain = {'x': [c2, c3], 'y': [y1_2020, y2_2020]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020["monetary_bail"],
title = {"text": "<span style='font-size:1.4em'>Number of people impacted</span>"},
number = {
"font":{"size": 30}},
domain = {'x': [c3, 1], 'y': [y1_2020, y2_2020]}))
# 2020 YTM data
fig.add_trace(go.Indicator(
mode = "number",
value = 2020,
number={"font":{"size": 12},
"suffix": " Jan-"+month_str},
domain = {'x': [0, c0], 'y': [y1_2020_YTM, y2_2020_YTM]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020_YTM["bail_amount"],
number = {"prefix": "$",
"font":{"size": 30}},
domain = {'x': [c0, c1], 'y': [y1_2020_YTM, y2_2020_YTM]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020_YTM["bail_paid"],
number = {"prefix": "$",
"font":{"size":30}},
domain = {'x': [c1, c2], 'y': [y1_2020_YTM, y2_2020_YTM]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020_YTM["monetary_bail_perct"]*100,
number = {"suffix": "%",
"font":{"size":30}},
domain = {'x': [c2, c3], 'y': [y1_2020_YTM, y2_2020_YTM]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2020_YTM["monetary_bail"],
number = {
"font":{"size": 30}},
domain = {'x': [c3, 1], 'y': [y1_2020_YTM, y2_2020_YTM]}))
# 2021 data
fig.add_trace(go.Indicator(
mode = "number",
value = 2021,
number={"font":{"size": 12},
"suffix": " Jan-"+month_str},
domain = {'x': [0, c0], 'y': [y1_2021, y2_2021]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2021["bail_amount"],
number = {"prefix": "$",
"font":{"size":30}},
domain = {'x': [c0, c1], 'y': [y1_2021, y2_2021]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2021["bail_paid"],
number = {"prefix": "$",
"font": {"size":30}},
domain = {'x': [c1, c2], 'y': [y1_2021, y2_2021]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2021["monetary_bail_perct"]*100,
number = {"font": {"size":30},
"suffix": "%"},
domain = {'x': [c2, c3], 'y': [y1_2021, y2_2021]}))
fig.add_trace(go.Indicator(
mode = "number",
value = summary_2021["monetary_bail"],
number = {"font": {"size":30}},
domain = {'x': [c3, 1], 'y': [y1_2021, y2_2021]}))
fig.update_layout(
height = 160,
margin = dict(t = 0, b = 0, l = 0, r = 0)
)
return fig