import pandas as pd import numpy as np from pathlib import Path np.random.seed(42) print("=" * 60) print("GENERATING SYNTHETIC TASK ASSIGNMENT DATASET") print("=" * 60) n_samples = 5000 n_developers = 12 dev_profiles = { 'junior': { 'ids': [1, 2, 3], 'avg_time': (8, 15), 'skill_range': (40, 75), 'max_capacity': 20, 'overtime_tolerance': 8 }, 'senior': { 'ids': [4, 5, 6, 7, 8], 'avg_time': (3, 8), 'skill_range': (70, 95), 'max_capacity': 35, 'overtime_tolerance': 15 }, 'specialist': { 'ids': [9, 10, 11, 12], 'avg_time': (4, 10), 'skill_range': (60, 100), 'max_capacity': 28, 'overtime_tolerance': 12 } } specialist_skills = { 9: 'frontend', 10: 'backend', 11: 'devops', 12: 'ml' } data = [] for i in range(1, n_samples + 1): dev_type = np.random.choice(['junior', 'senior', 'specialist'], p=[0.2, 0.5, 0.3]) profile = dev_profiles[dev_type] dev_id = np.random.choice(profile['ids']) current_tasks = max(0, int(np.random.poisson(4))) current_tasks = min(current_tasks, 12) avg_comp_time = np.random.uniform(*profile['avg_time']) story_points_assigned = current_tasks * np.random.randint(2, 5) story_points_assigned = min(story_points_assigned, profile['max_capacity']) overtime = max(0, int(np.random.exponential(4))) overtime = min(overtime, 20) if current_tasks > 6: task_switches = np.random.uniform(4, 8) elif current_tasks > 3: task_switches = np.random.uniform(2, 5) else: task_switches = np.random.uniform(0.5, 3) task_switches = round(task_switches, 2) pr_pending = max(0, int(np.random.poisson(3))) pr_pending = min(pr_pending, 15) priority = np.random.choice([0, 1, 2, 3], p=[0.1, 0.3, 0.4, 0.2]) if priority == 0: story_points = np.random.choice([5, 8, 13], p=[0.5, 0.3, 0.2]) elif priority == 1: story_points = np.random.choice([3, 5, 8], p=[0.4, 0.4, 0.2]) else: story_points = np.random.choice([1, 2, 3, 5], p=[0.2, 0.3, 0.3, 0.2]) is_sprint_end = np.random.random() < 0.35 if is_sprint_end: days_deadline = np.random.randint(1, 4) else: days_deadline = np.random.randint(4, 31) required_skill = np.random.choice(['frontend', 'backend', 'devops', 'ml', 'testing']) if dev_id in specialist_skills: if required_skill == specialist_skills[dev_id]: skill_match = np.random.randint(85, 101) else: skill_match = np.random.randint(45, 75) else: base_skill = profile['skill_range'] skill_match = np.random.randint(*base_skill) skill_match = np.clip(skill_match, 0, 100) has_deps = 1 if np.random.random() < 0.3 else 0 task_type = np.random.choice([0, 1, 2], p=[0.5, 0.3, 0.2]) team_size = np.random.randint(8, 13) sprint_days = np.random.randint(1, 15) team_velocity = np.random.randint(35, 71) workload_ratio = (story_points_assigned + story_points) / profile['max_capacity'] task_count_ratio = current_tasks / 8 switch_ratio = min(task_switches, 10) / 10 skill_penalty = (100 - skill_match) / 100 capacity = ( workload_ratio * 0.35 + task_count_ratio * 0.25 + switch_ratio * 0.20 + skill_penalty * 0.15 + (pr_pending / 15) * 0.05 ) if overtime > profile['overtime_tolerance']: fatigue_multiplier = 1 + ((overtime - profile['overtime_tolerance']) / 10) capacity *= fatigue_multiplier if days_deadline <= 2 and priority == 0: capacity *= 1.25 elif days_deadline <= 3 and priority <= 1: capacity *= 1.15 if has_deps == 1 and current_tasks > 5: capacity *= 1.12 if skill_match < 50 and workload_ratio > 0.7: capacity *= 1.20 if current_tasks > 8 and task_switches > 6: capacity *= 1.18 noise = np.random.normal(0, 0.05) capacity += noise green_threshold = 0.65 yellow_threshold = 0.82 if dev_type == 'junior': green_threshold = 0.55 yellow_threshold = 0.72 elif dev_type == 'senior': green_threshold = 0.70 yellow_threshold = 0.87 if capacity < green_threshold: risk = 0 elif capacity < yellow_threshold: risk = 1 else: risk = 2 base_completion = avg_comp_time * (story_points / 5) if skill_match < 60: base_completion *= 1.3 elif skill_match > 85: base_completion *= 0.85 if risk == 0: completion_multiplier = 1.0 elif risk == 1: completion_multiplier = 1.2 else: completion_multiplier = 1.5 actual_days = base_completion * completion_multiplier actual_days += np.random.normal(0, 1.5) actual_days = max(1, round(actual_days, 1)) data.append([ i, dev_id, i, current_tasks, round(avg_comp_time, 2), skill_match, story_points_assigned, overtime, task_switches, pr_pending, priority, story_points, days_deadline, required_skill, has_deps, task_type, team_size, sprint_days, team_velocity, risk, actual_days ]) df = pd.DataFrame(data, columns=[ 'assignment_id', 'developer_id', 'task_id', 'current_task_count', 'avg_completion_time_days', 'skill_match_score', 'total_story_points_assigned', 'recent_overtime_hours', 'task_switch_frequency', 'pr_review_pending', 'priority', 'estimated_story_points', 'days_until_deadline', 'required_skill', 'has_dependencies', 'task_type', 'team_size', 'sprint_days_remaining', 'team_avg_velocity', 'overload_risk', 'actual_completion_days' ]) print("\n QUALITY CHECKS") print("-" * 60) print("\n1. Missing Values:") missing = df.isnull().sum().sum() print(f" Total missing: {missing} {' PASS' if missing == 0 else '❌ FAIL'}") print("\n2. Value Range Validation:") checks = [ ('skill_match_score', 0, 100), ('current_task_count', 0, 15), ('recent_overtime_hours', 0, 25), ('task_switch_frequency', 0, 10), ('priority', 0, 3), ('overload_risk', 0, 2), ] all_valid = True for col, min_val, max_val in checks: valid = df[col].between(min_val, max_val).all() actual_min = df[col].min() actual_max = df[col].max() status = 'Ok' if valid else 'Not OK' print(f" {col}: [{actual_min}, {actual_max}] {status}") all_valid = all_valid and valid print(f"\n Overall: {'PASS' if all_valid else 'FAIL'}") print("\n3. Class Distribution:") class_dist = df['overload_risk'].value_counts().sort_index() class_pct = df['overload_risk'].value_counts(normalize=True).sort_index() for cls in [0, 1, 2]: count = class_dist.get(cls, 0) pct = class_pct.get(cls, 0) * 100 print(f" Class {cls}: {count:4d} samples ({pct:5.2f}%)") min_class_size = class_dist.min() print(f" Minimum class size: {min_class_size} {'PASS' if min_class_size >= 100 else 'WARNING'}") print("\n4. Feature Correlations with Target:") correlations = df.select_dtypes(include=[np.number]).corr()['overload_risk'].sort_values(ascending=False) print("\n Top Positive Correlations:") for feat, corr in correlations.head(6).items(): if feat != 'overload_risk': print(f" {feat:35s}: {corr:+.3f}") print("\n Top Negative Correlations:") for feat, corr in correlations.tail(5).items(): if feat != 'overload_risk': print(f" {feat:35s}: {corr:+.3f}") print("\n5. Statistical Summary:") print(f" Total samples: {len(df)}") print(f" Total features: {len(df.columns) - 1}") print(f" Developers: {df['developer_id'].nunique()}") print(f" Avg tasks per developer: {df['current_task_count'].mean():.2f}") print(f" Avg story points: {df['total_story_points_assigned'].mean():.2f}") print(f" Avg skill match: {df['skill_match_score'].mean():.1f}%") print("\n6. Logical Consistency:") consistency_checks = [] consistency_checks.append(df['estimated_story_points'].isin([1,2,3,5,8,13]).all()) consistency_checks.append(df['required_skill'].isin(['frontend','backend','devops','ml','testing']).all()) consistency_checks.append((df['has_dependencies'].isin([0, 1])).all()) consistency_checks.append((df['task_type'].isin([0, 1, 2])).all()) if all(consistency_checks): print("All consistency checks passed") else: print("Some consistency checks failed") Path('data').mkdir(exist_ok=True) df.to_csv('data/task_assignments.csv', index=False) sample_df = df.head(50) sample_df.to_csv('data/sample_input.csv', index=False) print("\n" + "=" * 60) print("💾 FILES SAVED") print("=" * 60) print(f"data/task_assignments.csv ({len(df)} rows)") print(f"data/sample_input.csv (50 rows for testing)") print("\nDataset generation complete!")