msg
Browse files- app.py +13 -0
- components/__pycache__/dashboard.cpython-313.pyc +0 -0
- components/__pycache__/home.cpython-313.pyc +0 -0
- components/__pycache__/sidebar.cpython-313.pyc +0 -0
- components/charts.py +31 -0
- components/dashboard.py +77 -0
- components/home.py +23 -0
- components/sidebar.py +5 -0
- requirements.txt +4 -0
- services/__pycache__/api.cpython-313.pyc +0 -0
- services/api.py +21 -0
- utils/helpers.py +5 -0
app.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from components.sidebar import render_sidebar
|
| 3 |
+
from components.home import render_home
|
| 4 |
+
from components.dashboard import render_dashboard
|
| 5 |
+
|
| 6 |
+
# Sidebar navigation
|
| 7 |
+
page = render_sidebar()
|
| 8 |
+
|
| 9 |
+
# Route to appropriate page
|
| 10 |
+
if page == "π Home":
|
| 11 |
+
render_home()
|
| 12 |
+
elif page == "π Analytics Dashboard":
|
| 13 |
+
render_dashboard()
|
components/__pycache__/dashboard.cpython-313.pyc
ADDED
|
Binary file (3.27 kB). View file
|
|
|
components/__pycache__/home.cpython-313.pyc
ADDED
|
Binary file (1.36 kB). View file
|
|
|
components/__pycache__/sidebar.cpython-313.pyc
ADDED
|
Binary file (563 Bytes). View file
|
|
|
components/charts.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import plotly.express as px
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
def generate_chart(analysis_option, data):
|
| 5 |
+
if analysis_option == "Employee Satisfaction":
|
| 6 |
+
return px.bar(data, x="DepartmentType", y="Satisfaction Score",
|
| 7 |
+
title="Satisfaction Score by Department", color="DepartmentType")
|
| 8 |
+
|
| 9 |
+
elif analysis_option == "Department Performance":
|
| 10 |
+
return px.line(data, x="DepartmentType", y=["Performance Score", "Current Employee Rating"],
|
| 11 |
+
title="Departmental Performance Trends", markers=True)
|
| 12 |
+
|
| 13 |
+
elif analysis_option == "Training Analytics":
|
| 14 |
+
return px.bar(data, x="Training Program Name", y="Training Outcome",
|
| 15 |
+
title="Training Participation by Program", color="Training Program Name")
|
| 16 |
+
|
| 17 |
+
elif analysis_option == "Cost-Benefit Analysis":
|
| 18 |
+
return px.scatter(data, x="DepartmentType", y="ROI", title="ROI by Department", size="ROI")
|
| 19 |
+
|
| 20 |
+
elif analysis_option == "Training Effectiveness":
|
| 21 |
+
return px.bar(data, x="Training Program Name", y="Performance Score",
|
| 22 |
+
title="Training Effectiveness by Program", color="Training Program Name")
|
| 23 |
+
|
| 24 |
+
elif analysis_option == "Diversity & Inclusion":
|
| 25 |
+
return px.bar(data, x="Category", y="Count", color="Group",
|
| 26 |
+
title="Diversity & Inclusion Breakdown", barmode="stack")
|
| 27 |
+
|
| 28 |
+
elif analysis_option == "Career Development":
|
| 29 |
+
return px.histogram(data, x="Career Movements", title="Career Progression Histogram")
|
| 30 |
+
|
| 31 |
+
return None
|
components/dashboard.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from services.api import fetch_data
|
| 5 |
+
|
| 6 |
+
def render_dashboard():
|
| 7 |
+
st.sidebar.subheader("Select Analysis")
|
| 8 |
+
analysis_option = st.sidebar.selectbox(
|
| 9 |
+
"Choose an analysis type:", [
|
| 10 |
+
"Employee Satisfaction",
|
| 11 |
+
"Department Performance",
|
| 12 |
+
"Training Analytics",
|
| 13 |
+
"Engagement vs Performance",
|
| 14 |
+
"Cost-Benefit Analysis",
|
| 15 |
+
"Training Effectiveness",
|
| 16 |
+
"Diversity & Inclusion",
|
| 17 |
+
"Work-Life Balance Impact",
|
| 18 |
+
"Career Development"
|
| 19 |
+
]
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# API endpoint mapping
|
| 23 |
+
endpoint_mapping = {
|
| 24 |
+
"Employee Satisfaction": "/satisfaction-analysis",
|
| 25 |
+
"Department Performance": "/department-performance",
|
| 26 |
+
"Training Analytics": "/training-analytics",
|
| 27 |
+
"Engagement vs Performance": "/engagement-performance-correlation",
|
| 28 |
+
"Cost-Benefit Analysis": "/cost-benefit-analysis",
|
| 29 |
+
"Training Effectiveness": "/training-effectiveness",
|
| 30 |
+
"Diversity & Inclusion": "/diversity-dashboard",
|
| 31 |
+
"Work-Life Balance Impact": "/worklife-balance-impact",
|
| 32 |
+
"Career Development": "/career-development"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# Fetch data
|
| 36 |
+
data = fetch_data(endpoint_mapping[analysis_option])
|
| 37 |
+
|
| 38 |
+
if data is None:
|
| 39 |
+
st.error("Failed to fetch data.")
|
| 40 |
+
return
|
| 41 |
+
|
| 42 |
+
st.title(f"π {analysis_option}")
|
| 43 |
+
|
| 44 |
+
# Correlation metric
|
| 45 |
+
if isinstance(data, dict) and "correlation_coefficient" in data:
|
| 46 |
+
st.metric("Correlation Coefficient", data["correlation_coefficient"])
|
| 47 |
+
return
|
| 48 |
+
|
| 49 |
+
# Display DataFrame
|
| 50 |
+
if isinstance(data, pd.DataFrame) and not data.empty:
|
| 51 |
+
st.dataframe(data)
|
| 52 |
+
|
| 53 |
+
# Generate visualization
|
| 54 |
+
fig = None
|
| 55 |
+
if analysis_option == "Employee Satisfaction":
|
| 56 |
+
fig = px.bar(data, x="DepartmentType", y="Satisfaction Score",
|
| 57 |
+
title="Satisfaction Score by Department", color="DepartmentType")
|
| 58 |
+
elif analysis_option == "Department Performance":
|
| 59 |
+
fig = px.line(data, x="DepartmentType", y=["Performance Score", "Current Employee Rating"],
|
| 60 |
+
title="Departmental Performance Trends", markers=True)
|
| 61 |
+
elif analysis_option == "Training Analytics":
|
| 62 |
+
fig = px.bar(data, x="Training Program Name", y="Training Outcome",
|
| 63 |
+
title="Training Participation by Program", color="Training Program Name")
|
| 64 |
+
elif analysis_option == "Cost-Benefit Analysis":
|
| 65 |
+
fig = px.scatter(data, x="DepartmentType", y="ROI", title="ROI by Department", size="ROI")
|
| 66 |
+
elif analysis_option == "Training Effectiveness":
|
| 67 |
+
fig = px.bar(data, x="Training Program Name", y="Performance Score",
|
| 68 |
+
title="Training Effectiveness by Program", color="Training Program Name")
|
| 69 |
+
elif analysis_option == "Diversity & Inclusion":
|
| 70 |
+
fig = px.bar(data, x="Category", y="Count", color="Group",
|
| 71 |
+
title="Diversity & Inclusion Breakdown", barmode="stack")
|
| 72 |
+
elif analysis_option == "Career Development":
|
| 73 |
+
fig = px.histogram(data, x="Career Movements", title="Career Progression Histogram")
|
| 74 |
+
|
| 75 |
+
# Display chart
|
| 76 |
+
if fig:
|
| 77 |
+
st.plotly_chart(fig)
|
components/home.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from services.api import fetch_data
|
| 3 |
+
|
| 4 |
+
def render_home():
|
| 5 |
+
st.title("π Welcome to the HR Analytics Home Page")
|
| 6 |
+
st.write("""
|
| 7 |
+
This dashboard provides insights into employee satisfaction, performance metrics,
|
| 8 |
+
training effectiveness, diversity & inclusion, and much more.
|
| 9 |
+
""")
|
| 10 |
+
|
| 11 |
+
# Fetch available API endpoints
|
| 12 |
+
home_data = fetch_data("/home")
|
| 13 |
+
|
| 14 |
+
if isinstance(home_data, dict):
|
| 15 |
+
st.subheader("π Available API Endpoints")
|
| 16 |
+
st.json(home_data.get("endpoints", {}))
|
| 17 |
+
|
| 18 |
+
st.markdown("### π How to Use")
|
| 19 |
+
st.write("""
|
| 20 |
+
- Navigate to the **Analytics Dashboard** from the sidebar.
|
| 21 |
+
- Select an analysis type to fetch insights.
|
| 22 |
+
- Visualize results with interactive charts.
|
| 23 |
+
""")
|
components/sidebar.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
def render_sidebar():
|
| 4 |
+
st.sidebar.title("HR Analytics Dashboard")
|
| 5 |
+
return st.sidebar.radio("Select Page", ["π Home", "π Analytics Dashboard"])
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|
| 3 |
+
pandas
|
| 4 |
+
plotly
|
services/__pycache__/api.cpython-313.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
services/api.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
API_BASE_URL = "http://127.0.0.1:8000"
|
| 6 |
+
|
| 7 |
+
def fetch_data(endpoint):
|
| 8 |
+
url = f"{API_BASE_URL}{endpoint}"
|
| 9 |
+
try:
|
| 10 |
+
response = requests.get(url)
|
| 11 |
+
response.raise_for_status()
|
| 12 |
+
data = response.json()
|
| 13 |
+
|
| 14 |
+
# Handle scalar responses
|
| 15 |
+
if isinstance(data, dict) and len(data) == 1:
|
| 16 |
+
return data
|
| 17 |
+
|
| 18 |
+
return pd.DataFrame(data)
|
| 19 |
+
except requests.exceptions.RequestException as e:
|
| 20 |
+
st.error(f"Error fetching data: {e}")
|
| 21 |
+
return None
|
utils/helpers.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
def clean_data(data):
|
| 4 |
+
"""Cleans and preprocesses data before visualization."""
|
| 5 |
+
return data.dropna().reset_index(drop=True) if isinstance(data, pd.DataFrame) else data
|