Mark Febrizio
commited on
Commit
•
e6cbeaa
1
Parent(s):
e36a0a8
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from modules.get_rules_in_window import (
|
|
9 |
START_DATE,
|
10 |
GET_SIGNIFICANT,
|
11 |
METADATA,
|
|
|
12 |
groupby_agency,
|
13 |
groupby_ym,
|
14 |
plot_agency,
|
@@ -32,6 +33,9 @@ with ui.sidebar(title="Settings"):
|
|
32 |
ui.input_date("start_date", "Start of window", value=START_DATE, min=START_DATE, max=date.today())
|
33 |
|
34 |
ui.input_switch("switch", "Show significant rules in plots", False)
|
|
|
|
|
|
|
35 |
#ui.input_checkbox_group(
|
36 |
# "significant",
|
37 |
# "EO 12866 Significance",
|
@@ -41,42 +45,42 @@ with ui.sidebar(title="Settings"):
|
|
41 |
with ui.layout_column_wrap():
|
42 |
with ui.value_box(showcase=icon_svg("book")):
|
43 |
"All final rules"
|
44 |
-
|
45 |
@render.text
|
46 |
def count_rules():
|
47 |
return f"{filtered_df()['document_number'].count()}"
|
|
|
48 |
|
49 |
with ui.value_box(showcase=icon_svg("book")):
|
50 |
-
"
|
51 |
-
|
52 |
@render.text
|
53 |
-
def
|
54 |
output = "Not available"
|
55 |
if GET_SIGNIFICANT:
|
56 |
-
output = f"{filtered_df()['
|
57 |
return output
|
|
|
58 |
|
59 |
with ui.value_box(showcase=icon_svg("book")):
|
60 |
-
"
|
61 |
-
|
62 |
@render.text
|
63 |
-
def
|
64 |
output = "Not available"
|
65 |
if GET_SIGNIFICANT:
|
66 |
-
output = f"{filtered_df()['
|
67 |
return output
|
|
|
68 |
|
69 |
with ui.navset_card_underline(title=""):
|
70 |
|
71 |
with ui.nav_panel("Rules in detail"):
|
72 |
@render.data_frame
|
73 |
def table_rule_detail():
|
74 |
-
df =
|
75 |
#print(df.columns)
|
76 |
#df.loc[:, "date"] = df.apply(lambda x: f"{x['publication_year']}-{x['publication_month']}-{x['publication_day']}", axis=1)
|
77 |
-
df.loc[:, "date"] = df.apply(lambda x: f"{x
|
78 |
-
char = " "
|
79 |
-
df.loc[:, "title"] = df["title"].apply(lambda x: f"{char.join(x.split(char)[:
|
80 |
df.loc[:, "agencies"] = df["parent_slug"].apply(lambda x: "; ".join(x))
|
81 |
cols = [
|
82 |
"date",
|
@@ -85,7 +89,7 @@ with ui.navset_card_underline(title=""):
|
|
85 |
"3f1_significant",
|
86 |
"other_significant",
|
87 |
]
|
88 |
-
return render.
|
89 |
|
90 |
with ui.nav_panel("By month"):
|
91 |
|
@@ -116,10 +120,15 @@ with ui.navset_card_underline(title=""):
|
|
116 |
|
117 |
@render.plot
|
118 |
def plot_by_agency():
|
119 |
-
grouped = grouped_df_agency()
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
@render.data_frame
|
125 |
def table_by_agency():
|
@@ -170,21 +179,67 @@ ui.markdown(
|
|
170 |
@reactive.calc
|
171 |
def filtered_df():
|
172 |
filt_df = DF
|
173 |
-
|
|
|
174 |
try:
|
175 |
filt_df = filt_df.loc[filt_df["publication_date"] >= input.start_date()]
|
176 |
except TypeError:
|
177 |
filt_df = filt_df.loc[filt_df["publication_date"] >= datetime.combine(input.start_date(), time(0, 0))]
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
return filt_df
|
179 |
|
180 |
@reactive.calc
|
181 |
-
def
|
182 |
filt_df = filtered_df()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
grouped = groupby_ym(filt_df, significant=GET_SIGNIFICANT)
|
184 |
return grouped
|
185 |
|
|
|
186 |
@reactive.calc
|
187 |
def grouped_df_agency():
|
188 |
-
filt_df =
|
189 |
grouped = groupby_agency(filt_df, metadata=METADATA, significant=GET_SIGNIFICANT)
|
190 |
return grouped
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
START_DATE,
|
10 |
GET_SIGNIFICANT,
|
11 |
METADATA,
|
12 |
+
AGENCIES,
|
13 |
groupby_agency,
|
14 |
groupby_ym,
|
15 |
plot_agency,
|
|
|
33 |
ui.input_date("start_date", "Start of window", value=START_DATE, min=START_DATE, max=date.today())
|
34 |
|
35 |
ui.input_switch("switch", "Show significant rules in plots", False)
|
36 |
+
|
37 |
+
ui.input_select("menu_agency", "Select agencies", choices=["all"] + AGENCIES, selected="all")
|
38 |
+
|
39 |
#ui.input_checkbox_group(
|
40 |
# "significant",
|
41 |
# "EO 12866 Significance",
|
|
|
45 |
with ui.layout_column_wrap():
|
46 |
with ui.value_box(showcase=icon_svg("book")):
|
47 |
"All final rules"
|
|
|
48 |
@render.text
|
49 |
def count_rules():
|
50 |
return f"{filtered_df()['document_number'].count()}"
|
51 |
+
ui.input_action_button("filter_all", "View", ) #class_="btn-success")
|
52 |
|
53 |
with ui.value_box(showcase=icon_svg("book")):
|
54 |
+
"Section 3(f)(1) Significant rules"
|
|
|
55 |
@render.text
|
56 |
+
def count_3f1_significant():
|
57 |
output = "Not available"
|
58 |
if GET_SIGNIFICANT:
|
59 |
+
output = f"{filtered_df()['3f1_significant'].sum()}"
|
60 |
return output
|
61 |
+
ui.input_action_button("filter_3f1", "View", ) #class_="btn-success")
|
62 |
|
63 |
with ui.value_box(showcase=icon_svg("book")):
|
64 |
+
"Other Significant rules"
|
|
|
65 |
@render.text
|
66 |
+
def count_other_significant():
|
67 |
output = "Not available"
|
68 |
if GET_SIGNIFICANT:
|
69 |
+
output = f"{filtered_df()['other_significant'].sum()}"
|
70 |
return output
|
71 |
+
ui.input_action_button("filter_other", "View", )
|
72 |
|
73 |
with ui.navset_card_underline(title=""):
|
74 |
|
75 |
with ui.nav_panel("Rules in detail"):
|
76 |
@render.data_frame
|
77 |
def table_rule_detail():
|
78 |
+
df = filtered_sig()
|
79 |
#print(df.columns)
|
80 |
#df.loc[:, "date"] = df.apply(lambda x: f"{x['publication_year']}-{x['publication_month']}-{x['publication_day']}", axis=1)
|
81 |
+
df.loc[:, "date"] = df.loc[:, "publication_date"].apply(lambda x: f"{x.date()}")
|
82 |
+
char, limit = " ", 10
|
83 |
+
df.loc[:, "title"] = df["title"].apply(lambda x: x if len(x.split(char)) < (limit + 1) else f"{char.join(x.split(char)[:limit])}...")
|
84 |
df.loc[:, "agencies"] = df["parent_slug"].apply(lambda x: "; ".join(x))
|
85 |
cols = [
|
86 |
"date",
|
|
|
89 |
"3f1_significant",
|
90 |
"other_significant",
|
91 |
]
|
92 |
+
return render.DataGrid(df.loc[:, [c for c in cols if c in df.columns]], width="100%") #filters=True)
|
93 |
|
94 |
with ui.nav_panel("By month"):
|
95 |
|
|
|
120 |
|
121 |
@render.plot
|
122 |
def plot_by_agency():
|
123 |
+
grouped = grouped_df_agency()
|
124 |
+
if input.switch():
|
125 |
+
pass
|
126 |
+
# placeholder for stacked bar chart
|
127 |
+
else:
|
128 |
+
plot = plot_agency(
|
129 |
+
grouped.head(10),
|
130 |
+
)
|
131 |
+
return plot
|
132 |
|
133 |
@render.data_frame
|
134 |
def table_by_agency():
|
|
|
179 |
@reactive.calc
|
180 |
def filtered_df():
|
181 |
filt_df = DF
|
182 |
+
|
183 |
+
# filter dates
|
184 |
try:
|
185 |
filt_df = filt_df.loc[filt_df["publication_date"] >= input.start_date()]
|
186 |
except TypeError:
|
187 |
filt_df = filt_df.loc[filt_df["publication_date"] >= datetime.combine(input.start_date(), time(0, 0))]
|
188 |
+
|
189 |
+
# filter agencies
|
190 |
+
if input.menu_agency() != "all":
|
191 |
+
bool_agency = [True if input.menu_agency() in agency else False for agency in filt_df["parent_slug"]]
|
192 |
+
filt_df = filt_df.loc[bool_agency]
|
193 |
+
|
194 |
return filt_df
|
195 |
|
196 |
@reactive.calc
|
197 |
+
def filtered_sig():
|
198 |
filt_df = filtered_df()
|
199 |
+
|
200 |
+
# filter significance
|
201 |
+
if filter_value.get() == "all":
|
202 |
+
pass
|
203 |
+
elif filter_value.get() == "3f1":
|
204 |
+
filt_df = filt_df.loc[filt_df["3f1_significant"] == 1]
|
205 |
+
elif filter_value.get() == "other":
|
206 |
+
filt_df = filt_df.loc[filt_df["other_significant"] == 1]
|
207 |
+
|
208 |
+
return filt_df
|
209 |
+
|
210 |
+
@reactive.calc
|
211 |
+
def grouped_df_month():
|
212 |
+
filt_df = filtered_sig()
|
213 |
grouped = groupby_ym(filt_df, significant=GET_SIGNIFICANT)
|
214 |
return grouped
|
215 |
|
216 |
+
|
217 |
@reactive.calc
|
218 |
def grouped_df_agency():
|
219 |
+
filt_df = filtered_sig()
|
220 |
grouped = groupby_agency(filt_df, metadata=METADATA, significant=GET_SIGNIFICANT)
|
221 |
return grouped
|
222 |
+
|
223 |
+
|
224 |
+
# ----- REACTIVE VALUES ----- #
|
225 |
+
|
226 |
+
|
227 |
+
filter_value = reactive.value("all")
|
228 |
+
|
229 |
+
@reactive.effect
|
230 |
+
@reactive.event(input.filter_all)
|
231 |
+
def _():
|
232 |
+
filter_value.set("all")
|
233 |
+
filtered_df()
|
234 |
+
|
235 |
+
@reactive.effect
|
236 |
+
@reactive.event(input.filter_3f1)
|
237 |
+
def _():
|
238 |
+
filter_value.set("3f1")
|
239 |
+
filtered_df()
|
240 |
+
|
241 |
+
@reactive.effect
|
242 |
+
@reactive.event(input.filter_other)
|
243 |
+
def _():
|
244 |
+
filter_value.set("other")
|
245 |
+
filtered_df()
|