File size: 6,984 Bytes
3ddfd7a
 
5cad389
3ddfd7a
 
 
51d9500
5c1b396
3ddfd7a
 
 
70fbb60
3ddfd7a
873a08b
3ddfd7a
70fbb60
 
dafe181
 
70fbb60
 
142290e
70fbb60
 
 
 
 
 
ed6fcd3
 
 
 
70fbb60
 
 
 
dafe181
70fbb60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dafe181
70fbb60
 
 
 
 
 
 
 
dafe181
 
bbcf0ce
 
2dc5104
 
 
 
 
b5e214b
2dc5104
b5e214b
 
 
 
 
 
 
 
 
 
b8aa2c3
 
 
 
d7e8a4c
b5e214b
 
 
ae2c00e
bbcf0ce
 
afa52d3
bbcf0ce
 
2f8aee4
bbcf0ce
a3c77e0
bbcf0ce
 
7f3f7f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bbcf0ce
c7fdc0b
 
 
 
 
13cb305
c7fdc0b
 
 
 
 
 
 
 
13cb305
 
 
 
ae2c00e
13cb305
 
 
2dc5104
13cb305
 
9a38b1e
13cb305
 
 
 
 
7f3f7f3
 
39577d4
 
 
 
 
 
 
 
 
 
 
920bede
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dc5104
920bede
2f8aee4
920bede
 
e7181a2
920bede
21792ef
920bede
 
 
 
 
 
39577d4
920bede
 
 
 
2f8aee4
920bede
2f8aee4
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# INSTRUCTIONS:
# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu
# 2. run in terminal with: streamlit run app.py
# 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL
# 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show
# 5. use the URL from prior steps as intput into this simple browser

import re
import streamlit as st
import altair as alt
from vega_datasets import data
import pandas as pd
 
st.title('Final Project')

st.text("The URL for this app is: https://huggingface.co/spaces/445final/final2.moved")



df = pd.read_csv('State_Employee_Pay.csv')

df_copy = df.copy()
df['Period Pay Rate'] = df['Period Pay Rate'].str.replace(",", "")
df['YTD Gross'] = df['YTD Gross'].str.replace(",", "")
df['Period Pay Rate'] = df['Period Pay Rate'].astype(int)
df['YTD Gross'] = df['YTD Gross'].astype(int)
df = df.dropna()
df = df[df['YTD Gross']!= 0]
df['Agency'] = df['Agency'].str.lower()
df['Agency Division'] = df['Agency Division'].str.lower()
df['Employee Name'] = df['Employee Name'].str.lower()
df['Position Title'] = df['Position Title'].str.lower()

df_c = df[df['Agency'] == 'corrections']
df_t = df[df['Agency'] == 'transportation']

df1 = df_t

#agency_division_list = df1['Agency Division'].value_counts().tolist()
agency_division_list = df1['Agency Division'].unique().tolist()

selected_division = st.selectbox('Agency Division:',
                                 options=agency_division_list,
                                 index=0)

# horizontal bar chart

def division_positions(selected_division):
    df_db = df1[df1['Agency Division'] == selected_division]
    
    bar_chart_data = df_db.groupby('Position Title').agg(
        employeeCount=('Employee Name', 'count'),
        meanYTDGross=('YTD Gross', 'mean')).reset_index()

    bar_chart_data = bar_chart_data.sort_values('meanYTDGross', ascending=False)

    chart_bar = alt.Chart(bar_chart_data).mark_bar().encode(
        x=alt.X('employeeCount', title = '# of Employees'),
        y=alt.Y('Position Title:O'),
        tooltip=['Position Title', 'employeeCount', alt.Tooltip(
            'meanYTDGross:Q', format='$,.0f', title='Avg YTD Gross')]
               ).properties(title=f'Employee Count by Position in: {selected_division}', 
                 height=alt.Step(20)).interactive()
    return chart_bar


if selected_division:
    final_chart = division_positions(selected_division)
    st.altair_chart(final_chart, use_container_width=True)

st.text('Overall Future Edits: Figure out what to do with positions with 1 employee (if anything), Decide whether to use transportation or corrections data, Re-capitalize agency departments')
st.text('Chart A Future Edits: Order bars by mean YTD Gross, Make all position titles readable, add title')




#im just going to relaod the data frame in to clean up the text on the bottomo charts
df_j = pd.read_csv('State_Employee_Pay.csv')


df_jcopy = df_j.copy()


df_jcopy['Period Pay Rate'] = df_jcopy['Period Pay Rate'].str.replace(",", "").astype(int)
df_jcopy['YTD Gross'] = df_jcopy['YTD Gross'].str.replace(",", "").astype(int)


df_jcopy = df_jcopy.dropna()
df_jcopy = df_jcopy[df_jcopy['YTD Gross'] != 0]


# df_jcopy['Agency'] = df_jcopy['Agency'].str.lower()
# df_jcopy['Agency Division'] = df_jcopy['Agency Division'].str.lower()
# df_jcopy['Employee Name'] = df_jcopy['Employee Name'].str.lower()
# df_jcopy['Position Title'] = df_jcopy['Position Title'].str.lower()
df_jcopy['Agency'] = df_jcopy['Agency'].str.replace(r'^(il |ill |illinois )', '', flags=re.IGNORECASE, regex=True)

df_jcopy.columns = df_jcopy.columns.str.strip()

df_top25=df_jcopy.sort_values("YTD Gross", ascending=False.head(50))

alt.data_transformers.disable_max_rows()
df_small=df[['Agency','YTD Gross']].copy()

select_bar = alt.selection_point(
    fields=["Agency"],
    on="click",
    clear="true"
)

#summing the barchart but the human services and transit departments are so large you cannot click on the other agencies
# bar_chart = (
#     alt.Chart(df_small)
#     .mark_bar()
#     .encode(
#         y=alt.Y("Agency:N", sort="-x"),
#         x=alt.X("sum(YTD Gross):Q", title="Total Personale Expense"),  # <-- take the mean
#         tooltip=[
#             "Agency:N",
#             alt.Tooltip("mean(YTD Gross):Q", title="Avg YTD Gross", format="$,.0f")
#         ],
#         color=alt.condition(select_bar, alt.value("#4C78A8"), alt.value("#CCCCCC"))
#     )
#     .add_params(select_bar)
#     .properties(width=500, height=800)
# )

# bar_chart = (
#     alt.Chart(df_small)
#     .mark_bar()
#     .encode(
#         y=alt.Y("Agency:N", sort="-x"),
#         x=alt.X("mean(YTD Gross):Q", title="Average Personale Expense"),  # <-- take the mean
#         tooltip=[
#             "Agency:N",
#             alt.Tooltip("mean(YTD Gross):Q", title="Avg YTD Gross", format="$,.0f")
#         ],
#         color=alt.condition(select_bar, alt.value("#4C78A8"), alt.value("#CCCCCC"))
#     )
#     .add_params(select_bar)
#     .properties(width=500, height=800)
# )


bar_chart = (
    alt.Chart(df_top25)
    .mark_bar()
    .encode(
        y=alt.Y("Agency:N", sort="-x"),
        x=alt.X("mean(YTD Gross):Q", title="Total Personale Expense"), 
        tooltip=[
            "Agency:N",
            alt.Tooltip("mean(YTD Gross):Q", title="Avg YTD Gross", format="$,.00f")
        ],
        color=alt.condition(select_bar, alt.value("#4C78A8"), alt.value("#CCCCCC"))
    )
    .add_params(select_bar)
    .properties(width=500, height=800)
)

# box = (
#     alt.Chart(df_small)
#     .mark_boxplot(size=40)
#     .encode(
#         x=alt.X("Agency:N", title=""),
#         y=alt.Y("YTD Gross:Q", title="Salary Distribution"),
#         opacity=alt.condition(select_bar,alt.value(1),alt.value(0)),
#         color=alt.value("#4C78A8")
#     )  
#     .properties(width=1000, height=800)
# )
# hist = (
#     alt.Chart(df_small)
#     .mark_bar(opacity=0.7)
#     .encode(
#         x=alt.X("YTD Gross:Q", bin=True, title="YTD Gross (binned)"),
#         y=alt.Y("count()", title="Count"),
#         color=alt.value("#4C78A8"),
#         tooltip=[alt.Tooltip("YTD Gross:Q",title="Range"),alt.Tooltip("count():Q",title="Count")]
#     )
#     .transform_filter(select_bar)  
#     .properties(width=400, height=300)
# )


strip = (
    alt.Chart(df_jcopy)
    .mark_circle(size=60, opacity=0.6)
    .encode(
        x=alt.X("YTD Gross:Q", title="YTD Gross"),
        y=alt.Y("Agency:N", title=""),
        color=alt.Color("Agency:N",title='Agency'),
        tooltip=[
            alt.Tooltip("Position Title:O"),
            alt.Tooltip("YTD Gross:Q", format="$,.0f")
        ]
    )
    .transform_filter(select_bar)   
    .transform_calculate(
        jitter="0.4 * (random() - 0.5)"   
    )
    .encode(
        y=alt.Y("jitter:Q", title="", axis=None) 
    )
    .properties(width=400, height=200)
)
dashboard = bar_chart & strip
dashboard