Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,19 +93,60 @@ if viz_type == "Complaints Over Time":
|
|
| 93 |
start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"), key="start_date")
|
| 94 |
end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"), key="end_date")
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
# Dropdown for Housing Block (only show when Complaints by Housing Block and Type or the updated version is selected)
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
#
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# Filtering data based on selected year
|
| 110 |
if selected_year != 'All Time':
|
| 111 |
filtered_data = data[data['Year Reported'] == selected_year]
|
|
|
|
| 93 |
start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"), key="start_date")
|
| 94 |
end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"), key="end_date")
|
| 95 |
|
| 96 |
+
# # Dropdown for Housing Block (only show when Complaints by Housing Block and Type or the updated version is selected)
|
| 97 |
+
# if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"]:
|
| 98 |
+
# block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
|
| 99 |
+
# selected_block = st.sidebar.selectbox(
|
| 100 |
+
# "Select Housing Block",
|
| 101 |
+
# options=block_options,
|
| 102 |
+
# key=f"block_select_{viz_type}" # Unique key for each visualization
|
| 103 |
+
# )
|
| 104 |
+
|
| 105 |
+
# # Ensuring selected_block is only used if defined
|
| 106 |
+
# if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"] and 'selected_block' not in locals():
|
| 107 |
+
# selected_block = 'All Blocks' # Default to 'All Blocks' if no selection made
|
| 108 |
+
|
| 109 |
# Dropdown for Housing Block (only show when Complaints by Housing Block and Type or the updated version is selected)
|
| 110 |
+
housing_block_viz_types = ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"]
|
| 111 |
+
|
| 112 |
+
if viz_type in housing_block_viz_types:
|
| 113 |
+
# Define blocks to be excluded for the specific version
|
| 114 |
+
excluded_blocks = [
|
| 115 |
+
'3400 block', '3500 block', '3600 block', '3700 block', '3800 block', '3900 block',
|
| 116 |
+
'4000 block', '4100 block', '4200 block', '4300 block', '4400 block', '4500 block',
|
| 117 |
+
'4600 block', '4700 block', '4800 block', '4900 block', '5000 block'
|
| 118 |
+
]
|
| 119 |
+
|
| 120 |
+
# Creating the desired order, excluding unwanted blocks
|
| 121 |
+
desired_order = [
|
| 122 |
+
'1 block', '100 block', '200 block', '300 block', '400 block', '500 block',
|
| 123 |
+
'600 block', '700 block', '800 block', '900 block', '1000 block', '1100 block',
|
| 124 |
+
'1200 block', '1300 block', '1400 block', '1500 block', '1600 block',
|
| 125 |
+
'1700 block', '1800 block', '1900 block', '2000 block', '2100 block',
|
| 126 |
+
'2200 block', '2300 block', '2400 block', '2500 block', '2600 block',
|
| 127 |
+
'2700 block', '2800 block', '2900 block', '3000 block', '3100 block',
|
| 128 |
+
'3200 block', '3300 block'
|
| 129 |
+
]
|
| 130 |
+
|
| 131 |
+
# Filtering the data based on selected year
|
| 132 |
+
filtered_data_time = data # Use filtered_data if date range is not needed
|
| 133 |
+
if selected_year != 'All Time':
|
| 134 |
+
filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
|
| 135 |
+
|
| 136 |
+
# Exclude blocks from the data
|
| 137 |
+
filtered_data_time = filtered_data_time[~filtered_data_time['Housing Block'].isin(excluded_blocks)]
|
| 138 |
|
| 139 |
+
# Get the list of blocks excluding the unwanted ones
|
| 140 |
+
available_blocks = sorted(filtered_data_time['Housing Block'].unique().tolist())
|
| 141 |
+
|
| 142 |
+
# Dropdown for Housing Block (excluding unwanted blocks)
|
| 143 |
+
block_options = ['All Blocks'] + available_blocks
|
| 144 |
+
selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
|
| 145 |
|
| 146 |
+
# Further filtering by selected Housing Block (if applicable)
|
| 147 |
+
if selected_block != 'All Blocks':
|
| 148 |
+
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 149 |
+
|
| 150 |
# Filtering data based on selected year
|
| 151 |
if selected_year != 'All Time':
|
| 152 |
filtered_data = data[data['Year Reported'] == selected_year]
|