Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /GRID-INTELLIGENCE_GRID /src /grid /progress /motivator.py
| """ | |
| Motivator: Progress tracking and momentum building for GRID shifts. | |
| This module provides real-time progress metrics and motivational milestones | |
| to keep momentum during the shift from 2nd โ 3rd โ 4th gear. | |
| """ | |
| import asyncio | |
| import json | |
| import sys | |
| from dataclasses import asdict, dataclass | |
| from datetime import UTC, datetime | |
| from pathlib import Path | |
| from typing import Any | |
| class GearMetrics: | |
| """Current state metrics for gear progress.""" | |
| timestamp: str | |
| rpm: int # Realistic Progress Momentum | |
| test_pass_rate: float # 0-100% | |
| test_count: int | |
| test_passing: int | |
| test_failing: int | |
| import_errors: int | |
| syntax_errors: int | |
| mypy_errors: int | |
| ruff_issues: int | |
| type_coverage: float # 0-100% | |
| def to_dict(self) -> dict[str, Any]: | |
| return asdict(self) | |
| class MotivationEngine: | |
| """Tracks progress and provides motivational milestones.""" | |
| # Gear definitions (RPM thresholds) | |
| GEARS: dict[str, dict[str, Any]] = { | |
| "2nd": {"rpm_min": 0, "rpm_max": 2500, "status": "Stalled - Starting repairs"}, | |
| "3rd": {"rpm_min": 2500, "rpm_max": 5000, "status": "Climbing - Building momentum"}, | |
| "4th": {"rpm_min": 5000, "rpm_max": 8000, "status": "Flying - Production ready"}, | |
| "5th": {"rpm_min": 8000, "rpm_max": 10000, "status": "Maximum - Enterprise scale"}, | |
| } | |
| MILESTONES = { | |
| "2nd": [ | |
| ("๐ง Diagnostic complete", "Test collection works"), | |
| ("โก Critical fixes applied", "Syntax errors resolved"), | |
| ("๐ฆ Imports stabilized", "Top 3 paths clear"), | |
| ], | |
| "3rd": [ | |
| ("โ Test execution enabled", "Can run pytest"), | |
| ("๐ฏ 50% tests passing", "Framework validates"), | |
| ("๐งน Code quality rising", "Type checking works"), | |
| ("๐ Benchmarks established", "Performance baseline set"), | |
| ], | |
| "4th": [ | |
| ("๐ 90%+ tests passing", "Comprehensive coverage"), | |
| ("โก Sub-100ms latency", "Performance optimized"), | |
| ("๐๏ธ Multi-tenant ready", "Enterprise architecture"), | |
| ("๐ Observability complete", "Full monitoring suite"), | |
| ], | |
| } | |
| def __init__(self, project_root: Path | None = None): | |
| """Initialize the motivation engine.""" | |
| self.project_root = project_root or Path(__file__).parent.parent.parent.parent | |
| async def measure_current_state(self) -> GearMetrics: | |
| """Measure current project metrics asynchronously.""" | |
| # Test metrics | |
| test_passing, test_failing, test_count = await self._count_tests_async() | |
| test_pass_rate = (test_passing / test_count * 100) if test_count > 0 else 0 | |
| # Error metrics | |
| import_errors = await self._count_errors_async("ImportError|ModuleNotFoundError") | |
| syntax_errors = await self._count_errors_async("SyntaxError") | |
| # Code quality | |
| mypy_errors = await self._count_mypy_errors_async() | |
| ruff_issues = await self._count_ruff_issues_async() | |
| # Type coverage (estimated from error ratio) | |
| type_coverage = max(0, 100 - (mypy_errors * 2)) | |
| # Calculate RPM | |
| rpm = self._calculate_rpm(test_pass_rate, import_errors, syntax_errors, mypy_errors, ruff_issues) | |
| return GearMetrics( | |
| timestamp=datetime.now(UTC).isoformat(), | |
| rpm=rpm, | |
| test_pass_rate=test_pass_rate, | |
| test_count=test_count, | |
| test_passing=test_passing, | |
| test_failing=test_failing, | |
| import_errors=import_errors, | |
| syntax_errors=syntax_errors, | |
| mypy_errors=mypy_errors, | |
| ruff_issues=ruff_issues, | |
| type_coverage=type_coverage, | |
| ) | |
| async def _run_cmd_async(self, cmd: list[str], timeout: int = 30) -> str: # noqa: ASYNC109 timeout parameter is handled by caller | |
| """Run a command asynchronously.""" | |
| try: | |
| proc = await asyncio.create_subprocess_exec( | |
| *cmd, cwd=self.project_root, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE | |
| ) | |
| async with asyncio.timeout(timeout): | |
| stdout, stderr = await proc.communicate() | |
| return stdout.decode() + stderr.decode() | |
| except Exception: | |
| return "" | |
| async def _count_tests_async(self) -> tuple[int, int, int]: | |
| """Count passing and failing tests asynchronously.""" | |
| output = await self._run_cmd_async([sys.executable, "-m", "pytest", "tests/", "-q", "--tb=no"], timeout=60) | |
| if not output: | |
| return 0, 200, 200 | |
| # Parse pytest output | |
| passing = output.count(" passed") | |
| failing = output.count(" failed") | |
| errors = output.count(" error") | |
| total = passing + failing + errors | |
| return passing, failing + errors, total if total > 0 else 200 | |
| async def _count_errors_async(self, pattern: str) -> int: | |
| """Count specific error types in test output asynchronously.""" | |
| output = await self._run_cmd_async( | |
| [sys.executable, "-m", "pytest", "tests/", "--collect-only", "-q"], timeout=30 | |
| ) | |
| if not output: | |
| return 0 | |
| import re | |
| matches = re.findall(pattern, output) | |
| return len(matches) | |
| async def _count_mypy_errors_async(self) -> int: | |
| """Count MyPy type checking errors asynchronously.""" | |
| output = await self._run_cmd_async(["mypy", "src/", "--ignore-missing-imports"], timeout=30) | |
| if not output: | |
| return 0 | |
| import re | |
| matches = re.findall(r"(\d+) error", output) | |
| return int(matches[0]) if matches else 0 | |
| async def _count_ruff_issues_async(self) -> int: | |
| """Count Ruff linting issues asynchronously.""" | |
| output = await self._run_cmd_async(["ruff", "check", "src/"], timeout=30) | |
| if not output: | |
| return 0 | |
| return len([l for l in output.split("\n") if l.strip()]) | |
| def _calculate_rpm( | |
| self, | |
| test_pass_rate: float, | |
| import_errors: int, | |
| syntax_errors: int, | |
| mypy_errors: int, | |
| ruff_issues: int, | |
| ) -> int: | |
| """Calculate Realistic Progress Momentum.""" | |
| # Base score from test pass rate | |
| base_rpm = int(test_pass_rate * 50) # 0-50 from tests | |
| # Subtract for errors | |
| error_penalty = min( | |
| 2500, | |
| (import_errors * 10) + (syntax_errors * 25) + (mypy_errors * 2) + (ruff_issues * 1), | |
| ) | |
| rpm = max(0, base_rpm - error_penalty) | |
| # Cap based on test pass rate | |
| if test_pass_rate < 5: | |
| rpm = min(rpm, 500) | |
| elif test_pass_rate < 25: | |
| rpm = min(rpm, 1500) | |
| elif test_pass_rate < 50: | |
| rpm = min(rpm, 3000) | |
| return rpm | |
| def current_gear(self, rpm: int) -> str: | |
| """Determine current gear based on RPM.""" | |
| for gear, specs in self.GEARS.items(): | |
| if specs["rpm_min"] <= rpm < specs["rpm_max"]: | |
| return gear | |
| return "5th" | |
| def next_gear(self, current_rpm: int) -> str: | |
| """Get next gear target.""" | |
| gears_list = ["2nd", "3rd", "4th", "5th"] | |
| current = self.current_gear(current_rpm) | |
| try: | |
| idx = gears_list.index(current) | |
| return gears_list[idx + 1] if idx < len(gears_list) - 1 else "5th" | |
| except ValueError: | |
| return "5th" | |
| def generate_report(self, metrics: GearMetrics) -> str: | |
| """Generate motivational progress report.""" | |
| current = self.current_gear(metrics.rpm) | |
| next_gear_target = self.next_gear(metrics.rpm) | |
| # Calculate progress toward next gear | |
| current_specs = self.GEARS[current] | |
| next_specs = self.GEARS[next_gear_target] | |
| progress_to_next = ( | |
| (metrics.rpm - current_specs["rpm_min"]) / (next_specs["rpm_max"] - current_specs["rpm_min"]) * 100 | |
| ) | |
| progress_to_next = max(0, min(100, progress_to_next)) | |
| # Build report | |
| report = [] | |
| report.append("\n" + "=" * 70) | |
| report.append(f"๐ GRID MOTIVATOR - {datetime.now(UTC).strftime('%Y-%m-%d %H:%M:%S')}") | |
| report.append("=" * 70) | |
| # Current gear status | |
| report.append(f"\n๐ฏ CURRENT GEAR: {current}") | |
| report.append(f" Status: {self.GEARS[current]['status']}") | |
| report.append(f" RPM: {metrics.rpm} / {self.GEARS[current]['rpm_max']}") | |
| # Progress bar | |
| bar_length = 50 | |
| filled = int(bar_length * progress_to_next / 100) | |
| bar = "โ" * filled + "โ" * (bar_length - filled) | |
| report.append(f"\n๐ PROGRESS TO {next_gear_target.upper()} GEAR:") | |
| report.append(f" [{bar}] {progress_to_next:.1f}%") | |
| # Metrics snapshot | |
| report.append("\n๐ METRICS SNAPSHOT:") | |
| report.append( | |
| f" โ Tests Passing: {metrics.test_passing:3d}/{metrics.test_count:3d} ({metrics.test_pass_rate:5.1f}%)" | |
| ) | |
| report.append(f" โ Tests Failing: {metrics.test_failing:3d}") | |
| report.append(f" ๐จ Import Errors: {metrics.import_errors:3d}") | |
| report.append(f" ๐ฅ Syntax Errors: {metrics.syntax_errors:3d}") | |
| report.append(f" โ ๏ธ MyPy Errors: {metrics.mypy_errors:3d}") | |
| report.append(f" ๐งน Ruff Issues: {metrics.ruff_issues:3d}") | |
| report.append(f" ๐ Type Coverage: {metrics.type_coverage:5.1f}%") | |
| # Milestones for current gear | |
| report.append(f"\n๐๏ธ MILESTONES - {current.upper()} GEAR:") | |
| for milestone, description in self.MILESTONES[current]: | |
| status = "โ " if "100%" in description or "complete" in description else "๐" | |
| report.append(f" {status} {milestone}") | |
| report.append(f" โ {description}") | |
| # Next gear teaser | |
| report.append(f"\n๐ NEXT GEAR ({next_gear_target.upper()}) UNLOCKS:") | |
| for milestone, description in self.MILESTONES[next_gear_target][:2]: | |
| report.append(f" ๐ฏ {milestone}") | |
| report.append(f" โ {description}") | |
| # Actionable next steps | |
| report.append("\n๐ช YOUR NEXT MOVE:") | |
| report.append(self._get_actionable_steps(metrics, current)) | |
| # Motivational message | |
| report.append(f"\n{self._get_motivational_message(metrics.rpm, progress_to_next)}") | |
| report.append("\n" + "=" * 70 + "\n") | |
| return "\n".join(report) | |
| def _get_actionable_steps(self, metrics: GearMetrics, current: str) -> str: | |
| """Get actionable next steps based on current state.""" | |
| steps = [] | |
| if metrics.syntax_errors > 0: | |
| steps.append(f" 1๏ธโฃ Fix {metrics.syntax_errors} syntax error(s) - BLOCKING!") | |
| if metrics.import_errors > 0: | |
| steps.append(f" 2๏ธโฃ Resolve {metrics.import_errors} import error(s) - BLOCKING!") | |
| if metrics.test_pass_rate < 50: | |
| target = int(metrics.test_pass_rate) + 10 | |
| steps.append(f" 3๏ธโฃ Get {target}% of tests passing") | |
| if metrics.mypy_errors > 20: | |
| steps.append(f" 4๏ธโฃ Reduce MyPy errors from {metrics.mypy_errors} โ 10") | |
| if metrics.ruff_issues > 100: | |
| steps.append(f" 5๏ธโฃ Clean Ruff issues: {metrics.ruff_issues} โ 50") | |
| if not steps: | |
| return " ๐ You're on track! Keep momentum going. Run this command again in 30 minutes." | |
| return "\n".join(steps[:3]) if len(steps) > 3 else "\n".join(steps) | |
| def _get_motivational_message(self, rpm: int, progress: float) -> str: | |
| """Get motivational message based on progress.""" | |
| messages = { | |
| "critical_low": ( | |
| "โ ๏ธ STUCK IN THE MUD\n" | |
| " Code isn't running yet. This is PHASE 0 - focus on unblocking.\n" | |
| " You're 30 minutes away from 1000 RPM. Push through! ๐ช" | |
| ), | |
| "climbing": ( | |
| "๐ CLIMBING THE HILL\n" | |
| " You're making progress! Tests are starting to pass.\n" | |
| " Keep fixing those imports - the road ahead is clearer. ๐" | |
| ), | |
| "halfway": ( | |
| "โก YOU'RE HALFWAY THERE\n" | |
| " Amazing progress! You're at the shift point.\n" | |
| " Time to engage 3rd gear and hit the accelerator. ๐๏ธ" | |
| ), | |
| "accelerating": ( | |
| "๐ ACCELERATING!\n" | |
| " 3rd gear is ENGAGED. You're in the zone now.\n" | |
| " 4th gear is within sight. Don't lose momentum! ๐ฅ" | |
| ), | |
| "flying": ( | |
| "๐ธ YOU'RE FLYING!\n" | |
| " 4th gear achieved! Production-ready code.\n" | |
| " Keep pushing - there's always room to grow. ๐ซ" | |
| ), | |
| } | |
| if rpm < 1000: | |
| return messages["critical_low"] | |
| elif rpm < 2500: | |
| return messages["climbing"] | |
| elif rpm < 3500 and progress < 50: | |
| return messages["halfway"] | |
| elif rpm < 5000: | |
| return messages["accelerating"] | |
| else: | |
| return messages["flying"] | |
| async def motivate() -> GearMetrics: | |
| """ | |
| Quick motivational check - call this frequently during the shift. | |
| Returns the current metrics so you can track progress. | |
| """ | |
| engine = MotivationEngine() | |
| metrics = await engine.measure_current_state() | |
| return metrics | |
| def print_motivation() -> None: | |
| """Print motivational report to console.""" | |
| engine = MotivationEngine() | |
| # Run async in sync context for CLI | |
| metrics = asyncio.run(engine.measure_current_state()) | |
| print(engine.generate_report(metrics)) | |
| def save_progress(metrics: GearMetrics, filepath: Path | None = None) -> None: | |
| """Save metrics to JSON for historical tracking.""" | |
| if filepath is None: | |
| filepath = Path(__file__).parent.parent.parent.parent / "progress_history.json" | |
| history = [] | |
| if filepath.exists(): | |
| with open(filepath) as f: | |
| history = json.load(f) | |
| history.append(metrics.to_dict()) | |
| # Keep last 100 records | |
| history = history[-100:] | |
| with open(filepath, "w") as f: | |
| json.dump(history, f, indent=2) | |
| return filepath | |
| if __name__ == "__main__": | |
| print_motivation() | |
Xet Storage Details
- Size:
- 14.4 kB
- Xet hash:
- e990a7a18c0848bd0d95cee36b6a6887e8eca24fcd904818be19eaf51997a708
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.