import streamlit as st import numpy as np import plotly.figure_factory as ff import plotly.express as px import pandas as pd import plotly.graph_objects as go from streamlit_extras.stylable_container import stylable_container import pickle import ast # Implement AND condition when downloading data st.set_page_config(layout="wide") color = {'Black or African American': '#ff7eb6', 'White':'#be95ff', 'Native American':'#0f62fe', 'Indian':'#82cfff', 'Japanese':'lightyellow', 'Korean':'gray','Chinese':'yellow', 'Hispanic':'#dface6', 'Pacific Islander':'#3ddbd9', 'Unkown/Other':'#c1c7cd','Filipino':'Green', 'Middle Eastern':'#000000','Vietnamese':'coral','Laotian':'cornsilk','Cambodian':'darkcyan','Other Asian':'darkgoldenrod', 'Asian':'#82cfff',} file = open("login_state.pkl",'rb') st.session_state['logged_in'] = pickle.load(file) file.close() #----------------------------NavBar-------------------------# hide_menu_style = """ """ st.markdown(hide_menu_style, unsafe_allow_html=True) if st.session_state.get("logged_in") == False or st.session_state.get("logged_in") == None: st.switch_page("app.py") st.markdown('', unsafe_allow_html=True) st.markdown("""
""", unsafe_allow_html=True) # with open("list_of_charges.pkl", "rb") as fp: # Unpickling # charges = pickle.load(fp) # Page 3 Page3 = stylable_container(key="Page3", css_styles=""" {box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 15px;} """) Page3.header("Download Data", anchor = 'section-3', help = 'Download data relevant to your case. Use the filters to Determine what data do you need.') selected_point = [] #loc = "DA_referrals_2022(1).csv" Charge = Page3.selectbox('Select Type of Charge', ('Booking Charge', 'Filed Charge', 'CDCR')) loc = "Referral_page2.csv" if Charge == 'Booking Charge' else "Court_page2.csv" if Charge == 'Filed Charge' else "Sentence_page2.csv" df = pd.read_csv(loc) df = df.drop(columns='Unnamed: 0') uid = 'UID' if Charge == 'Booking Charge' else 'Case Number' filename = "list_of_charges.pkl" if Charge == 'Booking Charge' else "list_of_charges_detailed.pkl" with open(filename, "rb") as fp: # Unpickling charges = pickle.load(fp) #split_first = False if loc == "Referral_page2.csv" else True cols = Page3.columns(4) Filtera = cols[0].multiselect('Select Charges', tuple(charges), help='Select Charges relevant to your case and client') Filterb = cols[2].multiselect('Select Ethnicity', tuple(color.keys()), help='Select relevant Ethnicity') Filterc = cols[1].selectbox('Select Function - Charges', ("AND", "OR"), help="AND - All Clients charged with all chosen charges \n\n OR - All Clients charged with atleast one of the chosen charges") cols_list = df.columns.tolist() cols_list.remove('Charges') cols_list.remove('Race') cols_list.remove(uid) Filterd = cols[3].multiselect('Select Additional Columns to View', tuple(cols_list), help="1. Incident Number - Unique Incident ID assigned to SF Cases \n\n 2. Gender - Gender of the perpetrator \n\n 3. Booked.Case.Type / Filed.Case.Type - Felony / Misdemeanor \n\n 4. Age.at.Arrest - Age at which the person was arrested \n\n 5. Status.CTNum / Status.CTNum.Agg - Case Status After arrest or filing i.e. new charges filed or discharged \n\n 6. Description - Arrest / Charges Description \n\n 7. Year - Year of Arrest for Booking charge / Year of Charging for Filed Charge or Sentenced For \n\n 8. Case.Dispo - Case Disposition Number \n\n 9. Dispo.Description - Final court decision") if len(Filtera) > 0: filst = "|".join(Filtera) df = df[df['Charges'].str.contains(filst, regex=True, na=False)] if len(Filterb) > 0: filst = "|".join(Filterb) df = df[df['Races'].str.contains(filst, regex=True, na=False)] if Filterc == 'AND' and len(Filtera) > 0: cnos = [df[df['Charges'].str.contains(i)][uid].tolist() for i in Filtera] cm_cnos = list(set.intersection(*map(set, cnos))) df = df[df[uid].isin(cm_cnos)] df = df.drop_duplicates() df[uid] = df[uid].map(str) for i in df.columns[1:]: df[i] = df[i].str.strip('[]').str.split(',') disp_cols = [uid, 'Charges', 'Race'] + Filterd Page3.dataframe(df[disp_cols],width=1300)