engineer-impact / app.py
Gmrock's picture
Upload 5 files
fef9b59 verified
import streamlit as st
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# Set page layout to wide for dashboard tracking
st.set_page_config(layout="wide", page_title="PostHog Engineering Impact Dashboard")
# -------------------------------------------------------------
# 🎯 INJECTED CSS: HIDES STREAMLIT ROW-SELECTION BUTTONS COLUMN
# -------------------------------------------------------------
st.html("""
<style>
/* Target and completely hide the data grid's row-selection column wrapper */
div[data-testid="stDataFrame"] [class*="gdg-row-header"],
div[data-testid="stDataFrame"] .glide-data-grid-row-header-container,
div[data-testid="stDataFrame"] th[class*="row-header"] {
display: none !important;
width: 0px !important;
}
</style>
""")
# Load the data generated by fetch_data.py
try:
df = pd.read_csv("posthog_impact_data.csv")
except FileNotFoundError:
st.error("❌ Data file 'posthog_impact_data.csv' not found. Please run 'python fetch_data.py' first to collect telemetry.")
st.stop()
# -------------------------------------------------------------
# DYNAMIC TIMELINE DETECTOR
# -------------------------------------------------------------
end_date = datetime.now()
start_date = end_date - timedelta(days=90)
date_string = f"πŸ—“οΈ Duration: {start_date.strftime('%b %d, %Y')} – {end_date.strftime('%b %d, %Y')} (Past 90 Days)"
# -------------------------------------------------------------
# SIDEBAR: CORE PILLARS PHILOSOPHY & CONTROLS
# -------------------------------------------------------------
st.sidebar.title("πŸ›οΈ Impact Framework Definitions")
st.sidebar.markdown("""
**πŸ“¦ 1. Execution:**
Measures operational scope, and handling of complex features. Blends bug Fix tags, core architectural, library, infrastructure, core, critical, P0, P1 text/labels/tags matches.
***
**πŸ’¬ 2. Collaboration:**
Quantifies engineering leverage and team citizenship. Blends *Review Actions* with a *Rubber-Stamp Filter* (>15 words) to isolate meaningful mentorship.
***
**πŸ›‘ 3. System Quality:**
Tracks production stability and defensive coding. Evaluates long-term stability by applying a deduction penalty for triggered *Git Reverts*.
***
**🀝 4. Human Touch:**
Captures critical qualitive values provided through direct team leadership, presence during incident escalation triage, and guidance in design/planning syncs.
""")
st.sidebar.markdown("---")
st.sidebar.header("βš–οΈ Strategic Priority Weights")
st.sidebar.markdown("Adjust macro priorities based on organizational needs:")
# Default weights: 0.35, 0.35, 0.20, 0.10
exec_w = st.sidebar.slider("Execution Weight", 0.0, 1.0, 0.35, 0.05)
collab_w = st.sidebar.slider("Collaboration Weight", 0.0, 1.0, 0.35, 0.05)
quality_w = st.sidebar.slider("System Quality Weight", 0.0, 1.0, 0.20, 0.05)
human_w = st.sidebar.slider("Human Touch Weight", 0.0, 1.0, 0.10, 0.05)
# Defensive Zero-Weight Divide-by-Zero Guard
total_weight = exec_w + collab_w + quality_w + human_w
if np.isclose(total_weight, 0.0):
exec_w_norm = 0.25
collab_w_norm = 0.25
quality_w_norm = 0.25
human_w_norm = 0.25
st.sidebar.info("ℹ️ All weights set to 0. Defaulting to an equal split (25% each) to prevent math errors.")
else:
exec_w_norm = exec_w / total_weight
collab_w_norm = collab_w / total_weight
quality_w_norm = quality_w / total_weight
human_w_norm = human_w / total_weight
# -------------------------------------------------------------
# CORE METRICS ENGINE: Peer Cohort Normalization
# -------------------------------------------------------------
max_prs = df['prs_merged'].max() if df['prs_merged'].max() > 0 else 1
max_bugs = df['bug_fixes'].max() if df['bug_fixes'].max() > 0 else 1
max_mult = df['multiplier_impact'].max() if df['multiplier_impact'].max() > 0 else 1
max_actions = df['review_actions'].max() if df['review_actions'].max() > 0 else 1
max_words = df['review_words_written'].max() if df['review_words_written'].max() > 0 else 1
max_reverts = df['reverts_triggered'].max() if df['reverts_triggered'].max() > 0 else 1
# Synthesize normalized values (0.0 to 1.0)
df['norm_prs'] = df['prs_merged'] / max_prs
df['norm_bugs'] = df['bug_fixes'] / max_bugs
df['norm_mult'] = df['multiplier_impact'] / max_mult
df['norm_actions'] = df['review_actions'] / max_actions
df['norm_words'] = df['review_words_written'] / max_words
df['norm_reverts'] = df['reverts_triggered'] / max_reverts
# Human Touch Core Mock Value Generator
df['human_touch_baseline'] = 0.85
# Calculate Internal Pillar Strengths
df['Execution_Pillar'] = (df['norm_prs'] * 0.4) + (df['norm_bugs'] * 0.3) + (df['norm_mult'] * 0.3)
df['Collaboration_Pillar'] = (df['norm_actions'] * 0.5) + (df['norm_words'] * 0.5)
df['Quality_Pillar'] = 1.0 - df['norm_reverts']
df['Human_Pillar'] = df['human_touch_baseline']
# Calculate final component contribution points
df['Exec_Contribution'] = df['Execution_Pillar'] * exec_w_norm * 100
df['Collab_Contribution'] = df['Collaboration_Pillar'] * collab_w_norm * 100
df['Quality_Contribution'] = df['Quality_Pillar'] * quality_w_norm * 100
df['Human_Contribution'] = df['Human_Pillar'] * human_w_norm * 100
# Calculate Final Aggregated Impact Score
df['Impact_Score'] = df['Exec_Contribution'] + df['Collab_Contribution'] + df['Quality_Contribution'] + df['Human_Contribution']
# Sort dataset by absolute overall impact
df = df.sort_values(by="Impact_Score", ascending=False).reset_index(drop=True)
# -------------------------------------------------------------
# MAIN DISPLAY: LEADERBOARD MATRIX WITH DIRECT ROW SELECTION
# -------------------------------------------------------------
st.title("πŸ›οΈ PostHog Engineering Impact Leaderboard")
st.markdown(f"**{date_string}**")
st.caption("πŸ’‘ Click on checkbox on the engineer's row below to instantly update their deep-dive profile.")
# Dynamic row count limiter dropdown
view_option = st.selectbox(
"Set Leaderboard Depth Range:",
options=["Top 5", "Top 10", "Top 20", "Top 30", "View All Teams"],
index=0
)
if view_option == "Top 5":
limit = 5
elif view_option == "Top 10":
limit = 10
elif view_option == "Top 20":
limit = 20
elif view_option == "Top 30":
limit = 30
else:
limit = len(df)
# Prepare clean dataframe containing active slice data
leaderboard_slice = df.head(limit).copy()
# Dynamically calculate the maximum points possible per column based on weights
max_exec_possible = exec_w_norm * 100
max_collab_possible = collab_w_norm * 100
max_quality_possible = quality_w_norm * 100
max_human_possible = human_w_norm * 100
# Construct display dataframe with explicit Max Point indicators in headers
display_df = pd.DataFrame({
'Engineer Username': leaderboard_slice['engineer'],
'πŸ… Total Impact Score (out of 100)': leaderboard_slice['Impact_Score'].round(1),
f'πŸ“¦ Execution (Max {max_exec_possible:.1f} pts)': leaderboard_slice['Exec_Contribution'].round(1),
f'πŸ’¬ Collaboration (Max {max_collab_possible:.1f} pts)': leaderboard_slice['Collab_Contribution'].round(1),
f'πŸ›‘ System Quality (Max {max_quality_possible:.1f} pts)': leaderboard_slice['Quality_Contribution'].round(1),
f'🀝 Human Touch (Max {max_human_possible:.1f} pts)': leaderboard_slice['Human_Contribution'].round(1)
})
# Dynamically calculate optimal table height to eliminate empty rows
row_height = 35
header_height = 40
calculated_height = min(header_height + (len(display_df) * row_height), 450)
# Render interactive table with selection tracking active
selection = st.dataframe(
display_df.style.format({
'πŸ… Total Impact Score (out of 100)': '{:.1f}',
f'πŸ“¦ Execution (Max {max_exec_possible:.1f} pts)': '{:.1f}',
f'πŸ’¬ Collaboration (Max {max_collab_possible:.1f} pts)': '{:.1f}',
f'πŸ›‘ System Quality (Max {max_quality_possible:.1f} pts)': '{:.1f}',
f'🀝 Human Touch (Max {max_human_possible:.1f} pts)': '{:.1f}'
}),
use_container_width=True,
height=calculated_height,
hide_index=True,
on_select="rerun",
selection_mode="single-row-required"
)
# -------------------------------------------------------------
# MASTER-DETAIL VIEW: DYNAMIC METRICS AUDITOR
# -------------------------------------------------------------
st.markdown("<br>", unsafe_allow_html=True)
st.markdown("---")
# Extract chosen engineer row natively without checking box arrays
if selection and selection.get("selection", {}).get("rows"):
selected_row_idx = selection["selection"]["rows"][0]
eng_row = leaderboard_slice.iloc[selected_row_idx]
else:
# Safely fall back to the absolute top engineer on landing
eng_row = df.iloc[0]
selected_eng = eng_row['engineer']
# --- ADDED: DIRECT MATH PROOF OF THE MAIN MATRIX ACCURACY ---
st.info(
f"πŸ“Š **Formula Proof for {selected_eng}:** "
f"πŸ“¦ Execution (`{eng_row['Exec_Contribution']:.1f}`) + "
f"πŸ’¬ Collaboration (`{eng_row['Collab_Contribution']:.1f}`) + "
f"πŸ›‘ Quality (`{eng_row['Quality_Contribution']:.1f}`) + "
f"🀝 Human Touch (`{eng_row['Human_Contribution']:.1f}`) = "
f"**πŸ… Total Impact Score of {eng_row['Impact_Score']:.1f} / 100**"
)
st.subheader(f"πŸ” Deep-Dive Calculation Audit Engine: {selected_eng}")
col1, col2 = st.columns([1, 2], gap="large")
with col1:
st.metric("Overall Performance Rating", f"{eng_row['Impact_Score']:.1f} / 100")
st.markdown(f"""
**Active Weight Allocation Matrix:**
* πŸ“¦ **Execution Contribution:** `{eng_row['Exec_Contribution']:.1f}` pts
* πŸ’¬ **Collaboration Contribution:** `{eng_row['Collab_Contribution']:.1f}` pts
* πŸ›‘ **System Quality Contribution:** `{eng_row['Quality_Contribution']:.1f}` pts
* 🀝 **Human Touch Contribution:** `{eng_row['Human_Contribution']:.1f}` pts
""")
with col2:
st.markdown("#### **Line-Item Pillar Math Breakdowns**")
# -------------------------------------------------------------
# PILLAR 1: EXECUTION DEEP DIVE
# -------------------------------------------------------------
with st.expander(f"πŸ“¦ Execution Pillar Breakdown: {eng_row['Exec_Contribution']:.1f} pts", expanded=False):
st.markdown("**1. Cohort Normalization (Raw vs Peak Team Ceiling):**")
st.markdown(f"- Merged PRs: `{int(eng_row['prs_merged'])}` / `{int(max_prs)}` Max = **{eng_row['norm_prs']:.3f}** ratio")
st.markdown(f"- Bug Fixes: `{int(eng_row['bug_fixes'])}` / `{int(max_bugs)}` Max = **{eng_row['norm_bugs']:.3f}** ratio")
st.markdown(f"- **Impact Multipliers:** `{int(eng_row['multiplier_impact'])}` / `{int(max_mult)}` Max = **{eng_row['norm_mult']:.3f}** ratio")
st.markdown("""
> πŸ’‘ **What is an Impact Multiplier?** \n
> This tracks high-leverage architectural code contributions. It scans text logs, labels, and files across your pull requests for engineering foundations that multiply the velocity of other teams:
> * πŸ› οΈ **Infrastructure & Shared Libraries** (`lib`, `infra`, `framework`)
> * ⚑ **Core System Optimization** (`core`, `performance`, `latency`)
> * πŸ”’ **Security & High-Criticality Guards** (`critical`, `P0`, `P1`, `security`, `auth`)
""")
st.markdown("**2. Composite Subsystem Weight Assembly Formula:**")
st.code(f"""
Execution Baseline Score = (Norm_PRs * 0.4) + (Norm_Bugs * 0.3) + (Norm_Multipliers * 0.3)
= ({eng_row['norm_prs']:.3f} * 0.4) + ({eng_row['norm_bugs']:.3f} * 0.3) + ({eng_row['norm_mult']:.3f} * 0.3)
= {eng_row['Execution_Pillar']:.3f}
""", language="text")
st.markdown("**3. Priority Control Scaling:**")
st.code(f"""
Final Points = Baseline Score * Strategy Weight * 100
= {eng_row['Execution_Pillar']:.3f} * {exec_w_norm:.2f} * 100
= {eng_row['Exec_Contribution']:.1f} pts
""", language="text")
# -------------------------------------------------------------
# PILLAR 2: COLLABORATION DEEP DIVE
# -------------------------------------------------------------
with st.expander(f"πŸ’¬ Collaboration Pillar Breakdown: {eng_row['Collab_Contribution']:.1f} pts", expanded=False):
st.markdown("**1. Cohort Normalization (Raw vs Peak Team Ceiling):**")
st.markdown(f"- Review Actions Count: `{int(eng_row['review_actions'])}` / `{int(max_actions)}` Max = **{eng_row['norm_actions']:.3f}** ratio")
st.markdown(f"- Substantive Mentorship Words (>15w): `{int(eng_row['review_words_written'])}` / `{int(max_words)}` Max = **{eng_row['norm_words']:.3f}** ratio")
st.markdown("**2. Composite Subsystem Weight Assembly Formula:**")
st.code(f"""
Collaboration Baseline Score = (Norm_Actions * 0.5) + (Norm_Words * 0.5)
= ({eng_row['norm_actions']:.3f} * 0.5) + ({eng_row['norm_words']:.3f} * 0.5)
= {eng_row['Collaboration_Pillar']:.3f}
""", language="text")
st.markdown("**3. Priority Control Scaling:**")
st.code(f"""
Final Points = Baseline Score * Strategy Weight * 100
= {eng_row['Collaboration_Pillar']:.3f} * {collab_w_norm:.2f} * 100
= {eng_row['Collab_Contribution']:.1f} pts
""", language="text")
# -------------------------------------------------------------
# PILLAR 3: SYSTEM QUALITY DEEP DIVE
# -------------------------------------------------------------
with st.expander(f"πŸ›‘ System Quality Pillar Breakdown: {eng_row['Quality_Contribution']:.1f} pts", expanded=False):
st.markdown("**1. Cohort Normalization (Raw vs Peak Team Ceiling):**")
st.markdown(f"- Git Reverts Triggered: `{int(eng_row['reverts_triggered'])}` / `{int(max_reverts)}` Max = **{eng_row['norm_reverts']:.3f}** ratio")
st.markdown("**2. Composite Subsystem Weight Assembly Formula:**")
st.code(f"""
Quality Baseline Score = 1.0 - Norm_Reverts
= 1.0 - {eng_row['norm_reverts']:.3f}
= {eng_row['Quality_Pillar']:.3f}
""", language="text")
st.markdown("**3. Priority Control Scaling:**")
st.code(f"""
Final Points = Baseline Score * Strategy Weight * 100
= {eng_row['Quality_Pillar']:.3f} * {quality_w_norm:.2f} * 100
= {eng_row['Quality_Contribution']:.1f} pts
""", language="text")
# -------------------------------------------------------------
# PILLAR 4: HUMAN TOUCH DEEP DIVE
# -------------------------------------------------------------
with st.expander(f"🀝 Human Touch Pillar Breakdown: {eng_row['Human_Contribution']:.1f} pts", expanded=False):
st.markdown("**1. Qualitative Evaluation Criteria Score (Manager Inputs Matrix):**")
st.markdown(f"- Current Assigned Sync/Escalation Presence Rating = **{eng_row['human_touch_baseline']:.2f}** / 1.0")
st.markdown("""
> πŸ’‘ **What factors calculate the Human Touch Rating?** \n
> This value tracks critical behaviors that telemetry cannot isolate from GitHub APIs alone:
> * 🧠 **Planning & Brainstorming** (Active, clarifying architectural contributions during syncs)
> * 🚨 **Incident Escalation Response** (Availability and speed to jumping on critical production issues)
""")
st.markdown("**2. Composite Assembly Score Formula:**")
st.code(f"""
Human Touch Baseline Score = Manager Evaluation Score
= {eng_row['human_touch_baseline']:.2f}
""", language="text")
st.markdown("**3. Priority Control Scaling:**")
st.code(f"""
Final Points = Baseline Score * Strategy Weight * 100
= {eng_row['Human_Pillar']:.2f} * {human_w_norm:.2f} * 100
= {eng_row['Human_Contribution']:.1f} pts
""", language="text")
# -------------------------------------------------------------
# UNDER THE HOOD RAW TELEMETRY (COLLAPSED BY DEFAULT)
# -------------------------------------------------------------
st.markdown("<br>", unsafe_allow_html=True)
with st.expander("πŸ“Š View Underlying Raw GitHub Telemetry Metrics"):
st.markdown("This section details the raw activity counts gathered before weights or normalization filters were applied.")
st.dataframe(
df[['engineer', 'prs_merged', 'bug_fixes', 'multiplier_impact', 'review_actions', 'review_words_written', 'reverts_triggered']],
use_container_width=True,
hide_index=True
)