ralate2 commited on
Commit
ab044b2
·
verified ·
1 Parent(s): 209ca80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -95
app.py CHANGED
@@ -505,7 +505,7 @@ elif viz_type == "Complaints by Housing Block and Type":
505
  # # Display the plot in Streamlit
506
  # st.pyplot(fig)
507
 
508
- # # Description of the visualization
509
  # st.write("""
510
  # **What this visualization shows:**
511
  # This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the percentage of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks. While the percentages may be challenging to read when data for all blocks is displayed, they become more valuable and easier to interpret when a single block is selected. Selecting a specific block allows for clearer insights into the proportion of each complaint type within that block, providing more actionable information.
@@ -518,93 +518,6 @@ elif viz_type == "Complaints by Housing Block and Type":
518
  # """)
519
  # In the above code , We incorporated all of the professor's suggestions and refined the chart to make it more useful for analysis while ensuring good aesthetics. Given that the data from block 3400 onwards is very sparse, we decided to exclude these records. This adjustment helped focus the visualization on the more relevant data, providing clearer insights and improving its overall effectiveness for analysis.
520
 
521
- # elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)":
522
- # st.subheader("Complaints by Housing Block and Type - Incorporating Suggestions Based on Professor's Feedback")
523
-
524
- # # Define blocks to be excluded
525
- # excluded_blocks = [
526
- # '3400 block', '3500 block', '3600 block', '3700 block', '3800 block', '3900 block',
527
- # '4000 block', '4100 block', '4200 block', '4300 block', '4400 block', '4500 block',
528
- # '4600 block', '4700 block', '4800 block', '4900 block', '5000 block'
529
- # ]
530
-
531
- # # Creating the desired order, excluding unwanted blocks
532
- # desired_order = [
533
- # '1 block', '100 block', '200 block', '300 block', '400 block', '500 block',
534
- # '600 block', '700 block', '800 block', '900 block', '1000 block', '1100 block',
535
- # '1200 block', '1300 block', '1400 block', '1500 block', '1600 block',
536
- # '1700 block', '1800 block', '1900 block', '2000 block', '2100 block',
537
- # '2200 block', '2300 block', '2400 block', '2500 block', '2600 block',
538
- # '2700 block', '2800 block', '2900 block', '3000 block', '3100 block',
539
- # '3200 block', '3300 block'
540
- # ]
541
-
542
- # # Filtering the data based on selected year
543
- # filtered_data_time = data # Use filtered_data if date range is not needed
544
- # if selected_year != 'All Time':
545
- # filtered_data_time = filtered_data_time[filtered_data_time['Year Reported'] == selected_year]
546
-
547
- # # Exclude blocks from the data
548
- # filtered_data_time = filtered_data_time[~filtered_data_time['Housing Block'].isin(excluded_blocks)]
549
-
550
- # # Get the list of blocks excluding the unwanted ones
551
- # available_blocks = sorted(filtered_data_time['Housing Block'].unique().tolist())
552
-
553
- # # Dropdown for Housing Block (excluding unwanted blocks)
554
- # block_options = ['All Blocks'] + available_blocks
555
- # selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
556
-
557
- # # Further filtering by selected Housing Block (if applicable)
558
- # if selected_block != 'All Blocks':
559
- # filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
560
-
561
- # # Pivoting the data
562
- # complaint_pivot = filtered_data_time.pivot_table(
563
- # index='Housing Block',
564
- # columns='Type of Complaint',
565
- # values='Disposition',
566
- # aggfunc='count',
567
- # fill_value=0
568
- # )
569
-
570
- # # Ensure the pivot data is numeric for plotting
571
- # complaint_pivot = complaint_pivot.astype(float)
572
-
573
- # # Reordering the pivot table by the desired order (excluding unwanted blocks)
574
- # complaint_pivot = complaint_pivot.reindex(desired_order)
575
-
576
- # # If a specific block is selected, only show that block on the x-axis
577
- # if selected_block != 'All Blocks':
578
- # complaint_pivot = complaint_pivot.loc[[selected_block]]
579
-
580
- # # Calculating percentages for each complaint type per housing block
581
- # percentages = complaint_pivot.div(complaint_pivot.sum(axis=1), axis=0) * 100
582
-
583
- # # Plotting the data
584
- # fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
585
-
586
- # # Adding percentage labels to the plot
587
- # ax = fig.gca()
588
- # for idx, block in enumerate(complaint_pivot.index):
589
- # cumulative_height = 0
590
- # for i, complaint_type in enumerate(complaint_pivot.columns):
591
- # count = complaint_pivot.iloc[idx, i]
592
- # percent = percentages.iloc[idx, i]
593
- # if count > 0:
594
- # # Compute the position for the percentage label
595
- # x_pos = idx - 0.4 + 0.8 / 2 # Adjusting the position of the label
596
- # y_pos = cumulative_height + count / 2
597
- # ax.text(
598
- # x_pos, y_pos, f"{percent:.1f}%",
599
- # ha='center', va='center',
600
- # fontsize=10, color='black',
601
- # bbox=dict(facecolor='white', alpha=0.7, edgecolor='none')
602
- # )
603
- # cumulative_height += count
604
-
605
- # # Display the plot in Streamlit
606
- # st.pyplot(fig)
607
-
608
  elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)":
609
  st.subheader("Complaints by Housing Block and Type - Incorporating Suggestions Based on Professor's Feedback")
610
 
@@ -639,11 +552,7 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
639
 
640
  # Dropdown for Housing Block (excluding unwanted blocks)
641
  block_options = ['All Blocks'] + available_blocks
642
- selected_block = st.sidebar.selectbox(
643
- "Select Housing Block",
644
- options=block_options,
645
- key=f"block_select_{viz_type}" # Unique key for each visualization type
646
- )
647
 
648
  # Further filtering by selected Housing Block (if applicable)
649
  if selected_block != 'All Blocks':
@@ -696,8 +605,7 @@ elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestion
696
  # Display the plot in Streamlit
697
  st.pyplot(fig)
698
 
699
-
700
- # Description of the visualization
701
  st.write("""
702
  **What this visualization shows:**
703
  This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the percentage distribution of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks. While the percentages may be challenging to read when data for all blocks is displayed, they become more valuable and easier to interpret when a single block is selected. Selecting a specific block allows for clearer insights into the proportion of each complaint type within that block, providing more actionable information.
 
505
  # # Display the plot in Streamlit
506
  # st.pyplot(fig)
507
 
508
+ # # writeup
509
  # st.write("""
510
  # **What this visualization shows:**
511
  # This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the percentage of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks. While the percentages may be challenging to read when data for all blocks is displayed, they become more valuable and easier to interpret when a single block is selected. Selecting a specific block allows for clearer insights into the proportion of each complaint type within that block, providing more actionable information.
 
518
  # """)
519
  # In the above code , We incorporated all of the professor's suggestions and refined the chart to make it more useful for analysis while ensuring good aesthetics. Given that the data from block 3400 onwards is very sparse, we decided to exclude these records. This adjustment helped focus the visualization on the more relevant data, providing clearer insights and improving its overall effectiveness for analysis.
520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  elif viz_type == "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)":
522
  st.subheader("Complaints by Housing Block and Type - Incorporating Suggestions Based on Professor's Feedback")
523
 
 
552
 
553
  # Dropdown for Housing Block (excluding unwanted blocks)
554
  block_options = ['All Blocks'] + available_blocks
555
+ selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
 
 
 
 
556
 
557
  # Further filtering by selected Housing Block (if applicable)
558
  if selected_block != 'All Blocks':
 
605
  # Display the plot in Streamlit
606
  st.pyplot(fig)
607
 
608
+ # writeup
 
609
  st.write("""
610
  **What this visualization shows:**
611
  This bar chart displays the distribution of complaints by Housing Block and Complaint Type. The data is stacked to show the percentage distribution of complaints per block, categorized by type. This allows for a quick comparison of the most common complaint types across different housing blocks. While the percentages may be challenging to read when data for all blocks is displayed, they become more valuable and easier to interpret when a single block is selected. Selecting a specific block allows for clearer insights into the proportion of each complaint type within that block, providing more actionable information.