Update app.py
Browse files
app.py
CHANGED
|
@@ -2,13 +2,10 @@ import pandas as pd
|
|
| 2 |
import streamlit as st
|
| 3 |
import joblib
|
| 4 |
import time
|
| 5 |
-
import plotly.graph_objects as go
|
| 6 |
-
import numpy as np
|
| 7 |
from datetime import datetime
|
| 8 |
from sklearn.pipeline import Pipeline
|
| 9 |
from sklearn.compose import ColumnTransformer
|
| 10 |
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
| 11 |
-
from prophet import Prophet
|
| 12 |
from PIL import Image, ImageFile
|
| 13 |
ImageFile.LOAD_TRUNCATED_IMAGES = True # Disables the check
|
| 14 |
|
|
@@ -200,180 +197,6 @@ def company_metric(label, value, change=None):
|
|
| 200 |
</div>
|
| 201 |
""", unsafe_allow_html=True)
|
| 202 |
|
| 203 |
-
def stock_chart(data, company_name):
|
| 204 |
-
try:
|
| 205 |
-
# Debug: Print raw data
|
| 206 |
-
|
| 207 |
-
# Ensure we have a DataFrame with proper datetime index
|
| 208 |
-
df_prophet = data.reset_index()
|
| 209 |
-
df_prophet.columns = ['ds', 'y']
|
| 210 |
-
|
| 211 |
-
# Debug: Check date conversion
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
# Convert to datetime if not already
|
| 215 |
-
df_prophet['ds'] = pd.to_datetime(df_prophet['ds'], errors='coerce')
|
| 216 |
-
|
| 217 |
-
# Drop any rows with invalid dates
|
| 218 |
-
df_prophet = df_prophet.dropna(subset=['ds'])
|
| 219 |
-
|
| 220 |
-
# Debug: Check after datetime conversion
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
# Initialize and fit model
|
| 224 |
-
model_prophet = Prophet(daily_seasonality=True, yearly_seasonality=True)
|
| 225 |
-
model_prophet.fit(df_prophet)
|
| 226 |
-
|
| 227 |
-
# Create future dataframe
|
| 228 |
-
future = model_prophet.make_future_dataframe(periods=180)
|
| 229 |
-
|
| 230 |
-
# Generate forecast
|
| 231 |
-
forecast_prophet = model_prophet.predict(future)
|
| 232 |
-
forecast_prophet['ds'] = pd.to_datetime(forecast_prophet['ds'])
|
| 233 |
-
|
| 234 |
-
# Filter forecast to show only future predictions
|
| 235 |
-
forecast_prophet_filtered = forecast_prophet[forecast_prophet['ds'] >= pd.to_datetime('today').normalize()]
|
| 236 |
-
|
| 237 |
-
# Create figure
|
| 238 |
-
fig = go.Figure()
|
| 239 |
-
|
| 240 |
-
# Add historical data trace
|
| 241 |
-
fig.add_trace(go.Scatter(
|
| 242 |
-
x=df_prophet['ds'],
|
| 243 |
-
y=df_prophet['y'],
|
| 244 |
-
name='Historical',
|
| 245 |
-
line=dict(color='#014d4f', width=3),
|
| 246 |
-
hovertemplate='Date: %{x|%b %d, %Y}<br>Price: %{y:$,.2f}<extra></extra>'
|
| 247 |
-
))
|
| 248 |
-
|
| 249 |
-
# Add forecast trace
|
| 250 |
-
fig.add_trace(go.Scatter(
|
| 251 |
-
x=forecast_prophet_filtered['ds'],
|
| 252 |
-
y=forecast_prophet_filtered['yhat'],
|
| 253 |
-
name='Forecast',
|
| 254 |
-
line=dict(color='#017a7c', width=3, dash='dot'),
|
| 255 |
-
hovertemplate='Date: %{x|%b %d, %Y}<br>Forecast: %{y:$,.2f}<extra></extra>'
|
| 256 |
-
))
|
| 257 |
-
|
| 258 |
-
# Update layout
|
| 259 |
-
fig.update_layout(
|
| 260 |
-
title=f"<b>{company_name}</b> Stock Performance",
|
| 261 |
-
xaxis_title=None,
|
| 262 |
-
yaxis_title="Stock Price",
|
| 263 |
-
hovermode="x unified",
|
| 264 |
-
template="plotly_white",
|
| 265 |
-
plot_bgcolor="white",
|
| 266 |
-
paper_bgcolor="white",
|
| 267 |
-
font=dict(color="#2b2d42"),
|
| 268 |
-
margin=dict(l=40, r=40, t=60, b=40),
|
| 269 |
-
legend=dict(
|
| 270 |
-
orientation="h",
|
| 271 |
-
yanchor="bottom",
|
| 272 |
-
y=1.02,
|
| 273 |
-
xanchor="right",
|
| 274 |
-
x=1
|
| 275 |
-
)
|
| 276 |
-
)
|
| 277 |
-
|
| 278 |
-
return fig
|
| 279 |
-
|
| 280 |
-
except Exception as e:
|
| 281 |
-
st.error(f"Error generating stock chart: {str(e)}")
|
| 282 |
-
st.write("Debug info - data received:", data)
|
| 283 |
-
return go.Figure() # Return empty figure on error
|
| 284 |
-
|
| 285 |
-
# =============================================
|
| 286 |
-
# JOB POSITIONS DATA
|
| 287 |
-
# =============================================
|
| 288 |
-
|
| 289 |
-
job_positions = {
|
| 290 |
-
"Project Manager": {
|
| 291 |
-
1: "Aselsan",
|
| 292 |
-
2: "Turkcell İletişim Hizmetleri",
|
| 293 |
-
3: "Enka İnşaat ve Sanayi"
|
| 294 |
-
},
|
| 295 |
-
"Civil Engineer": {
|
| 296 |
-
1: "Enka İnşaat ve Sanayi",
|
| 297 |
-
2: "Tekfen Holding",
|
| 298 |
-
3: "Alarko Holding"
|
| 299 |
-
},
|
| 300 |
-
"Budget Analyst": {
|
| 301 |
-
1: "Koç Holding",
|
| 302 |
-
2: "Sabancı Holding",
|
| 303 |
-
3: "Türkiye İş Bankası"
|
| 304 |
-
},
|
| 305 |
-
"Data Scientist": {
|
| 306 |
-
1: "Turkcell İletişim Hizmetleri",
|
| 307 |
-
2: "Logo Yazılım Sanayi ve Ticaret",
|
| 308 |
-
3: "Türk Telekomünikasyon"
|
| 309 |
-
},
|
| 310 |
-
"Data Analyst": {
|
| 311 |
-
1: "Turkcell İletişim Hizmetleri",
|
| 312 |
-
2: "Türk Telekomünikasyon",
|
| 313 |
-
3: "Koç Holding"
|
| 314 |
-
},
|
| 315 |
-
"Design Engineer": {
|
| 316 |
-
1: "Aselsan",
|
| 317 |
-
2: "Arçelik",
|
| 318 |
-
3: "Enka İnşaat ve Sanayi"
|
| 319 |
-
},
|
| 320 |
-
"Project Engineer": {
|
| 321 |
-
1: "Enka İnşaat ve Sanayi",
|
| 322 |
-
2: "Tekfen Holding",
|
| 323 |
-
3: "Alarko Holding"
|
| 324 |
-
},
|
| 325 |
-
"Construction Engineer": {
|
| 326 |
-
1: "Enka İnşaat ve Sanayi",
|
| 327 |
-
2: "Tekfen Holding",
|
| 328 |
-
3: "Alarko Holding"
|
| 329 |
-
},
|
| 330 |
-
"Software Engineer": {
|
| 331 |
-
1: "Türk Telekomünikasyon",
|
| 332 |
-
2: "Netas Telekomünikasyon",
|
| 333 |
-
3: "Vestel"
|
| 334 |
-
},
|
| 335 |
-
"Environmental Engineer": {
|
| 336 |
-
1: "Şişecam",
|
| 337 |
-
2: "Tekfen Holding",
|
| 338 |
-
3: "Enka İnşaat ve Sanayi"
|
| 339 |
-
},
|
| 340 |
-
"Mechanical Engineer": {
|
| 341 |
-
1: "Ford Otosan",
|
| 342 |
-
2: "Tofaş Türk Otomobil Fabrikası",
|
| 343 |
-
3: "Arçelik"
|
| 344 |
-
},
|
| 345 |
-
"Energy": {
|
| 346 |
-
1: "Aksa Enerji Üretim",
|
| 347 |
-
2: "Enerjisa Enerji",
|
| 348 |
-
3: "Galata Wind Enerji"
|
| 349 |
-
},
|
| 350 |
-
"Project Coordinator": {
|
| 351 |
-
1: "Aselsan",
|
| 352 |
-
2: "Türk Hava Yolları",
|
| 353 |
-
3: "Tekfen Holding"
|
| 354 |
-
},
|
| 355 |
-
"Project Director": {
|
| 356 |
-
1: "Aselsan",
|
| 357 |
-
2: "Türk Telekomünikasyon",
|
| 358 |
-
3: "Tekfen Holding"
|
| 359 |
-
},
|
| 360 |
-
"Systems Administrator": {
|
| 361 |
-
1: "Türk Telekomünikasyon",
|
| 362 |
-
2: "Vestel",
|
| 363 |
-
3: "Aselsan"
|
| 364 |
-
},
|
| 365 |
-
"IT Support Specialist": {
|
| 366 |
-
1: "Türk Telekomünikasyon",
|
| 367 |
-
2: "Koç Holding",
|
| 368 |
-
3: "Vestel"
|
| 369 |
-
},
|
| 370 |
-
"Applications Developer": {
|
| 371 |
-
1: "Turkcell İletişim Hizmetleri",
|
| 372 |
-
2: "Logo Yazılım Sanayi ve Ticaret",
|
| 373 |
-
3: "Yapı Kredi Teknoloji"
|
| 374 |
-
}
|
| 375 |
-
}
|
| 376 |
-
|
| 377 |
# =============================================
|
| 378 |
# MAIN APP
|
| 379 |
# =============================================
|
|
@@ -545,46 +368,6 @@ def main():
|
|
| 545 |
company_metric("Experience Required", f"{MinExperience} years")
|
| 546 |
with col3:
|
| 547 |
company_metric("Education Level", RequiredDegree)
|
| 548 |
-
|
| 549 |
-
# Market analysis section
|
| 550 |
-
if BusinessTitle in job_positions:
|
| 551 |
-
st.markdown("## Market Intelligence")
|
| 552 |
-
st.markdown("""
|
| 553 |
-
<p style="color: #64748b;">
|
| 554 |
-
Below you'll find financial performance data for top companies hiring this position
|
| 555 |
-
</p>
|
| 556 |
-
""", unsafe_allow_html=True)
|
| 557 |
-
companies = job_positions[BusinessTitle]
|
| 558 |
-
for i in range(1, 4): # Show first 3 companies (keys 1, 2, 3)
|
| 559 |
-
company_name = companies[i]
|
| 560 |
-
with st.expander(f"{company_name} Market Analysis", expanded=(i==1)):
|
| 561 |
-
try:
|
| 562 |
-
data = pd.read_csv(f'Finance Data/{company_name}.csv', index_col=0, header=[0, 1])
|
| 563 |
-
close_data = data['Close'].copy()
|
| 564 |
-
close_data = pd.DataFrame(close_data)
|
| 565 |
-
close_data.index = pd.to_datetime(close_data.index)
|
| 566 |
-
close_data.columns = ['Close']
|
| 567 |
-
|
| 568 |
-
fig = stock_chart(close_data, company_name)
|
| 569 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 570 |
-
|
| 571 |
-
# Company metrics
|
| 572 |
-
current_price = close_data['Close'].iloc[-1]
|
| 573 |
-
monthly_change = ((current_price - close_data['Close'].iloc[-30]) / close_data['Close'].iloc[-30]) * 100
|
| 574 |
-
volatility = (close_data['Close'].std() / close_data['Close'].mean()) * 100
|
| 575 |
-
|
| 576 |
-
cols = st.columns(3)
|
| 577 |
-
with cols[0]:
|
| 578 |
-
company_metric("Current Price", f"${current_price:.2f}")
|
| 579 |
-
with cols[1]:
|
| 580 |
-
company_metric("30-Day Change", f"{monthly_change:.2f}%", monthly_change)
|
| 581 |
-
with cols[2]:
|
| 582 |
-
company_metric("Volatility", f"{volatility:.2f}%")
|
| 583 |
-
|
| 584 |
-
except FileNotFoundError:
|
| 585 |
-
st.error(f"Data not available for {company_name}")
|
| 586 |
-
except Exception as e:
|
| 587 |
-
st.error(f"Error loading data for {company_name}: {str(e)}")
|
| 588 |
|
| 589 |
st.markdown("""
|
| 590 |
<style>
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import joblib
|
| 4 |
import time
|
|
|
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
from sklearn.pipeline import Pipeline
|
| 7 |
from sklearn.compose import ColumnTransformer
|
| 8 |
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
|
|
|
| 9 |
from PIL import Image, ImageFile
|
| 10 |
ImageFile.LOAD_TRUNCATED_IMAGES = True # Disables the check
|
| 11 |
|
|
|
|
| 197 |
</div>
|
| 198 |
""", unsafe_allow_html=True)
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
# =============================================
|
| 201 |
# MAIN APP
|
| 202 |
# =============================================
|
|
|
|
| 368 |
company_metric("Experience Required", f"{MinExperience} years")
|
| 369 |
with col3:
|
| 370 |
company_metric("Education Level", RequiredDegree)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
st.markdown("""
|
| 373 |
<style>
|