Niharmahesh commited on
Commit
d1628be
·
verified ·
1 Parent(s): b7715f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -116
app.py CHANGED
@@ -120,11 +120,11 @@ def create_chart(data, _x, y, title, color_sequence):
120
  fig = px.bar(data, x=_x, y=y, title=title, color_discrete_sequence=color_sequence)
121
  fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
122
  return fig
123
-
124
  def create_time_series(df, time_unit='day'):
125
- if time_unit == 'month':
126
- # Group by month and year
127
- df_by_date = df.groupby(df['date_posted'].dt.to_period('M')).size().reset_index(name='count')
128
  df_by_date['date_posted'] = df_by_date['date_posted'].dt.to_timestamp()
129
  else:
130
  # Keep daily grouping as before
@@ -139,122 +139,15 @@ def create_time_series(df, time_unit='day'):
139
  yaxis_title="Number of Job Postings"
140
  )
141
 
142
- # Adjust x-axis ticks for monthly view
143
- if time_unit == 'month':
144
  fig.update_xaxes(
145
- dtick="M1",
146
- tickformat="%b %Y"
 
147
  )
148
 
149
  return fig
150
-
151
- @st.cache_data
152
- def prepare_dashboard_data(df):
153
- top_companies = df['company'].value_counts().head(10)
154
- top_locations = df['location'].value_counts().head(10)
155
- top_job_titles = df['title'].value_counts().head(20)
156
- df_by_date = df.groupby('date_posted').size().reset_index(name='count')
157
- return top_companies, top_locations, top_job_titles, df_by_date
158
-
159
- def display_dashboard(df):
160
- top_companies, top_locations, top_job_titles, df_by_date = prepare_dashboard_data(df)
161
-
162
- today = datetime.now().date()
163
- jobs_today = df[df['date_posted'].dt.date == today].shape[0]
164
-
165
- col1, col2 = st.columns(2)
166
-
167
- with col1:
168
- st.subheader("Job Postings Overview")
169
- st.metric("Total Job Postings", len(df))
170
- st.metric("Unique Companies", df['company'].nunique())
171
- st.metric("Job Postings Today", jobs_today)
172
-
173
- min_date = df['date_posted'].min().date()
174
- max_date = df['date_posted'].max().date()
175
- st.write(f"Job postings from {min_date} to {max_date}")
176
-
177
- with col2:
178
- fig = create_chart(top_companies, top_companies.index, top_companies.values, "Top 10 Companies", ['#4e79a7'])
179
- st.plotly_chart(fig, use_container_width=True)
180
-
181
- # Job Postings Over Time Chart
182
- fig_time_series = create_time_series(df,time_unit='month')
183
- st.plotly_chart(fig_time_series, use_container_width=True)
184
-
185
- col3, col4 = st.columns(2)
186
-
187
- with col3:
188
- fig = create_chart(top_locations, top_locations.index, top_locations.values, "Top 10 Locations", ['#f28e2b'])
189
- st.plotly_chart(fig, use_container_width=True)
190
-
191
- with col4:
192
- fig = create_chart(top_job_titles, top_job_titles.index, top_job_titles.values, "Top 20 Job Titles", ['#59a14f'])
193
- st.plotly_chart(fig, use_container_width=True)
194
- @st.cache_data
195
- def filter_dataframe(df, companies, locations, job_types,Role_Name,Date_posted):
196
- filtered_df = df
197
- if companies:
198
- filtered_df = filtered_df[filtered_df['company'].isin(companies)]
199
- if locations:
200
- filtered_df = filtered_df[filtered_df['location'].isin(locations)]
201
- if job_types:
202
- filtered_df = filtered_df[filtered_df['job_type'].isin(job_types)]
203
- if Role_Name:
204
- filtered_df = filtered_df[filtered_df['title'].isin(Role_Name)]
205
- if Date_posted:
206
- filtered_df = filtered_df[filtered_df['date_posted'].isin(Date_posted)]
207
- return filtered_df
208
-
209
- def display_data_explorer(df):
210
- st.subheader("Data Explorer")
211
-
212
- show_all = st.radio("Display", ("All Data", "Filtered Data"))
213
-
214
- if show_all == "Filtered Data":
215
- unique_values = get_unique_values(df)
216
- col1, col2, col3, col4,col5 = st.columns(5)
217
- with col1:
218
- companies = st.multiselect("Select Companies", options=unique_values['companies'])
219
- with col2:
220
- locations = st.multiselect("Select Locations", options=unique_values['locations'])
221
- with col3:
222
- job_types = st.multiselect("Select Job Types", options=unique_values['job_types'])
223
- with col4:
224
- Role_Name = st.multiselect("Select Role Types", options=unique_values['Role_Name'])
225
- with col5:
226
- Date_posted = st.multiselect("Select Date Posted", options=unique_values['Date_posted'])
227
-
228
- filtered_df = filter_dataframe(df, companies, locations, job_types, Role_Name,Date_posted)
229
- else:
230
- filtered_df = df
231
-
232
- st.write(f"Showing {len(filtered_df)} job listings")
233
-
234
- # Pagination
235
- items_per_page = 15
236
- num_pages = math.ceil(len(filtered_df) / items_per_page)
237
-
238
- col1, col2, col3 = st.columns([1, 3, 1])
239
- with col2:
240
- page = st.number_input("Page", min_value=1, max_value=num_pages, value=1)
241
-
242
- start_idx = (page - 1) * items_per_page
243
- end_idx = start_idx + items_per_page
244
-
245
- page_df = filtered_df.iloc[start_idx:end_idx]
246
-
247
- def make_clickable(url):
248
- return f'<a href="{url}" target="_blank" style="color: #4e79a7;">Link</a>'
249
-
250
- page_df['job_url'] = page_df['job_url'].apply(make_clickable)
251
- page_df['company_url'] = page_df['company_url'].apply(make_clickable)
252
-
253
- st.write(page_df.to_html(escape=False, index=False), unsafe_allow_html=True)
254
-
255
- col1, col2, col3 = st.columns([1, 3, 1])
256
- with col2:
257
- st.write(f"Page {page} of {num_pages}")
258
  def display_about_page():
259
  st.markdown("""
260
  ## What is this application?
 
120
  fig = px.bar(data, x=_x, y=y, title=title, color_discrete_sequence=color_sequence)
121
  fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
122
  return fig
123
+
124
  def create_time_series(df, time_unit='day'):
125
+ if time_unit == 'week':
126
+ # Group by week and year
127
+ df_by_date = df.groupby(df['date_posted'].dt.to_period('W')).size().reset_index(name='count')
128
  df_by_date['date_posted'] = df_by_date['date_posted'].dt.to_timestamp()
129
  else:
130
  # Keep daily grouping as before
 
139
  yaxis_title="Number of Job Postings"
140
  )
141
 
142
+ # Adjust x-axis ticks for weekly view
143
+ if time_unit == 'week':
144
  fig.update_xaxes(
145
+ dtick="W1",
146
+ tickformat="%d %b %Y",
147
+ ticklabelmode="period"
148
  )
149
 
150
  return fig
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  def display_about_page():
152
  st.markdown("""
153
  ## What is this application?