{"id":43773502,"url":"https://github.com/luismr/megasena-2025-analysis","last_synced_at":"2026-02-05T17:05:01.177Z","repository":{"id":331164883,"uuid":"1125536482","full_name":"luismr/megasena-2025-analysis","owner":"luismr","description":"A comprehensive Python tool for analyzing Mega Sena lottery draws with multiple prediction strategies. Refactored following DRY (Don't Repeat Yourself) and SOLID principles for maintainability and extensibility.","archived":false,"fork":false,"pushed_at":"2025-12-30T23:35:02.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-03T22:34:37.941Z","etag":null,"topics":["dry","megasena","pandas","python","solid"],"latest_commit_sha":null,"homepage":"https://luismachadoreis.dev","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luismr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-30T22:53:49.000Z","updated_at":"2025-12-30T23:39:43.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/luismr/megasena-2025-analysis","commit_stats":null,"previous_names":["luismr/megasena-2025-analysis"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/luismr/megasena-2025-analysis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luismr%2Fmegasena-2025-analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luismr%2Fmegasena-2025-analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luismr%2Fmegasena-2025-analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luismr%2Fmegasena-2025-analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luismr","download_url":"https://codeload.github.com/luismr/megasena-2025-analysis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luismr%2Fmegasena-2025-analysis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29126093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T14:05:12.718Z","status":"ssl_error","status_checked_at":"2026-02-05T14:03:53.078Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dry","megasena","pandas","python","solid"],"created_at":"2026-02-05T17:05:00.090Z","updated_at":"2026-02-05T17:05:01.171Z","avatar_url":"https://github.com/luismr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mega Sena Analysis Tool\n\n\u003c!-- Build \u0026 Quality --\u003e\n[![CI/CD Pipeline](https://github.com/luismr/megasena-2025-analysis/actions/workflows/ci.yml/badge.svg)](https://github.com/luismr/megasena-2025-analysis/actions/workflows/ci.yml)\n[![Tests](https://img.shields.io/badge/tests-55%20passed-success)](https://github.com/luismr/megasena-2025-analysis)\n[![Coverage](https://img.shields.io/badge/coverage-96%25-brightgreen)](https://github.com/luismr/megasena-2025-analysis)\n[![Code Quality](https://img.shields.io/badge/code%20quality-A-brightgreen)](https://github.com/luismr/megasena-2025-analysis)\n\n\u003c!-- Language \u0026 Tools --\u003e\n[![Python Version](https://img.shields.io/badge/python-3.9%2B-blue)](https://www.python.org/downloads/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Linting: flake8](https://img.shields.io/badge/linting-flake8-blue)](https://flake8.pycqa.org/)\n[![Type Checking: mypy](https://img.shields.io/badge/type%20checking-mypy-blue)](http://mypy-lang.org/)\n\n\u003c!-- Repository Stats --\u003e\n[![GitHub stars](https://img.shields.io/github/stars/luismr/megasena-2025-analysis?style=social)](https://github.com/luismr/megasena-2025-analysis/stargazers)\n[![GitHub forks](https://img.shields.io/github/forks/luismr/megasena-2025-analysis?style=social)](https://github.com/luismr/megasena-2025-analysis/network/members)\n[![GitHub issues](https://img.shields.io/github/issues/luismr/megasena-2025-analysis)](https://github.com/luismr/megasena-2025-analysis/issues)\n[![GitHub pull requests](https://img.shields.io/github/issues-pr/luismr/megasena-2025-analysis)](https://github.com/luismr/megasena-2025-analysis/pulls)\n\n\u003c!-- Activity --\u003e\n[![Last Commit](https://img.shields.io/github/last-commit/luismr/megasena-2025-analysis)](https://github.com/luismr/megasena-2025-analysis/commits)\n[![Repo Size](https://img.shields.io/github/repo-size/luismr/megasena-2025-analysis)](https://github.com/luismr/megasena-2025-analysis)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/luismr/megasena-2025-analysis/graphs/commit-activity)\n\nA comprehensive Python tool for analyzing Mega Sena lottery draws with multiple prediction strategies. Refactored following **DRY (Don't Repeat Yourself)** and **SOLID** principles for maintainability and extensibility.\n\n## 📁 Project Structure\n\n```\nmegasena/\n├── input/                          # Input data files\n│   └── mega_sena_resultados.csv    # Historical Mega Sena draw results\n├── output/                         # Generated analysis reports\n│   ├── mega_virada_analysis.txt\n│   ├── number_frequency_analysis.txt\n│   ├── weighted_analysis_all_draws.txt\n│   └── weighted_analysis_results.txt\n├── src/                            # Core modules (following SOLID principles)\n│   ├── __init__.py                 # Package initialization\n│   ├── data_loader.py              # CSV data loading (Single Responsibility)\n│   ├── frequency_calculator.py     # Frequency calculation strategies (Open/Closed)\n│   ├── output_formatter.py         # Result formatting and display\n│   └── file_manager.py             # File I/O operations\n├── scripts/                        # Executable analysis scripts\n│   ├── predict_all_draws.py        # Analyze all historical draws\n│   ├── predict_mega_virada.py      # Analyze only Mega da Virada draws\n│   ├── predict_weighted_all_draws.py      # Weighted analysis (all draws)\n│   └── predict_weighted_mega_virada.py    # Weighted analysis (Mega da Virada)\n└── README.md                       # This file\n```\n\n## 🎯 Features\n\n### Core Modules (SOLID Design)\n\n1. **`data_loader.py`** - Single Responsibility Principle\n   - Load all Mega Sena draws\n   - Filter Mega da Virada draws (Dec 31st)\n   - Filter by year range\n   - Extract numbers from draws\n\n2. **`frequency_calculator.py`** - Open/Closed Principle\n   - **Strategy Pattern** for extensibility\n   - Multiple calculation strategies:\n     - Simple frequency (equal weight)\n     - Weighted by recency (exponential)\n     - Weighted by recency (linear)\n     - Weighted favoring older draws\n     - Recent N years/draws only\n\n3. **`output_formatter.py`** - Single Responsibility\n   - Format and display analysis results\n   - Pattern analysis (even/odd, low/high, sum)\n   - Consensus analysis across strategies\n   - Complete 60-number rankings\n\n4. **`file_manager.py`** - Single Responsibility\n   - Save frequency analysis\n   - Save strategy comparisons\n   - Save detailed reports\n   - Manage output directory\n\n## 🚀 Usage\n\n### Prerequisites\n\n- Python 3.7 or higher\n- No external dependencies required (uses only standard library)\n\n### Running Analysis Scripts\n\nAll scripts should be run from the project root directory:\n\n#### 1. Analyze All Historical Draws\n```bash\npython scripts/predict_all_draws.py\n```\nAnalyzes all Mega Sena draws using simple frequency analysis.\n\n**Output:** `output/number_frequency_analysis.txt`\n\n#### 2. Analyze Mega da Virada Only\n```bash\npython scripts/predict_mega_virada.py\n```\nAnalyzes only Mega da Virada draws (Dec 31st, 2008-2024) with pattern analysis.\n\n**Output:** `output/mega_virada_analysis.txt`\n\n#### 3. Weighted Analysis - All Draws\n```bash\npython scripts/predict_weighted_all_draws.py\n```\nCompares 5 different weighting strategies across all historical draws:\n- Simple frequency\n- Recent weighted more (exponential)\n- Recent weighted more (linear)\n- Older weighted more\n- Last 5 years only\n\n**Output:** `output/weighted_analysis_all_draws.txt`\n\n#### 4. Weighted Analysis - Mega da Virada\n```bash\npython scripts/predict_weighted_mega_virada.py\n```\nCompares 5 different weighting strategies for Mega da Virada draws only.\n\n**Output:** `output/weighted_analysis_results.txt`\n\n## 🏗️ Architecture \u0026 Design Principles\n\n### SOLID Principles Applied\n\n#### **S - Single Responsibility Principle**\n- Each module has one clear purpose:\n  - `data_loader`: Load and filter data\n  - `frequency_calculator`: Calculate frequencies\n  - `output_formatter`: Format output\n  - `file_manager`: Handle file I/O\n\n#### **O - Open/Closed Principle**\n- Easy to extend with new strategies without modifying existing code\n- Add new `FrequencyStrategy` subclasses to introduce new calculation methods\n\n#### **L - Liskov Substitution Principle**\n- All `FrequencyStrategy` subclasses can be used interchangeably\n- Consistent interface across all strategies\n\n#### **I - Interface Segregation Principle**\n- Small, focused interfaces\n- Classes only depend on methods they use\n\n#### **D - Dependency Inversion Principle**\n- Scripts depend on abstract `FrequencyStrategy` interface\n- Concrete implementations are injected at runtime\n\n### DRY (Don't Repeat Yourself)\n\n- **Before:** Each script duplicated CSV loading, frequency calculation, and output formatting\n- **After:** Common functionality extracted into reusable modules\n- **Result:** ~70% code reduction, easier maintenance\n\n### Design Patterns Used\n\n1. **Strategy Pattern** - `FrequencyStrategy` and subclasses\n2. **Template Method** - Common analysis workflow in scripts\n3. **Dependency Injection** - Strategies injected into `FrequencyCalculator`\n\n## 📊 Analysis Strategies\n\n### 1. Simple Frequency\nEqual weight for all draws across history.\n\n### 2. Weighted Frequency (Recent More - Exponential)\nRecent draws have exponentially more weight (~7x for newest vs oldest).\n\n### 3. Weighted Frequency (Recent More - Linear)\nRecent draws have linearly more weight (~4x for newest vs oldest).\n\n### 4. Weighted Frequency (Older More)\nOlder draws have more weight (favors historical stability).\n\n### 5. Recent Only\nOnly considers the most recent N draws or years.\n\n## 🔧 Extending the Tool\n\n### Adding a New Frequency Strategy\n\n1. Create a new class inheriting from `FrequencyStrategy`:\n\n```python\nfrom src.frequency_calculator import FrequencyStrategy\n\nclass MyCustomStrategy(FrequencyStrategy):\n    def calculate(self, draws):\n        # Your calculation logic\n        return frequencies_dict\n    \n    def get_name(self):\n        return \"My Custom Strategy\"\n    \n    def get_description(self):\n        return \"Description of what this does\"\n```\n\n2. Add it to your script:\n\n```python\ncalculator.add_strategy('my_custom', MyCustomStrategy())\n```\n\n### Adding a New Script\n\n1. Create a new file in `scripts/`\n2. Import the required modules from `src/`\n3. Follow the existing script structure\n\n## 🧪 Testing \u0026 CI/CD\n\n### Quick Start\n```bash\n# Install dependencies\npip install -r requirements.txt\n\n# Run tests\npytest\n\n# Run with coverage\npytest --cov=src --cov-report=term-missing\n```\n\n### Test Coverage\n- **55 unit tests** - 96% coverage\n- **data_loader.py**: 98% | **file_manager.py**: 100% | **frequency_calculator.py**: 88% | **output_formatter.py**: 98%\n\n### CI/CD Pipeline\n\n**Automated on every push/PR:**\n- ✅ **Tests** - Ubuntu, macOS, Windows × Python 3.9-3.12\n- ✅ **Linting** - flake8, black, mypy\n- ✅ **Coverage** - Automatic PR comments with detailed reports\n- ✅ **Security** - Dependency \u0026 code scanning\n- ✅ **Build** - Package validation\n\n**GitHub Actions Workflows:**\n- `ci.yml` - Main CI/CD pipeline (lint, test, coverage, build, security)\n- `pr-comment.yml` - Coverage reports as PR comments\n- `codeql.yml` - Security analysis\n- `dependabot.yml` - Automatic dependency updates\n\n**Coverage on PRs:**\nEvery PR gets an automatic comment with:\n- Overall coverage % with color indicators (🟢 ≥90%, 🟡 ≥80%, 🟠 ≥70%, 🔴 \u003c70%)\n- Per-module breakdown\n- Coverage trends\n\n## 🤝 Contributing\n\n### Quick Start\n\n```bash\n# 1. Clone the repository\ngit clone https://github.com/luismr/megasena-2025-analysis.git\ncd megasena-2025-analysis\n\n# 2. Install dependencies\npip install -r requirements.txt\n\n# 3. Run tests\npytest\n\n# 4. Run scripts\npython scripts/predict_all_draws.py\n```\n\n### Submit a Pull Request\n\n1. **Fork the repository** on GitHub\n2. **Clone your fork:**\n   ```bash\n   git clone https://github.com/YOUR_USERNAME/megasena-2025-analysis.git\n   cd megasena-2025-analysis\n   ```\n\n3. **Create a feature branch:**\n   ```bash\n   git checkout -b feature/your-feature-name\n   ```\n\n4. **Make your changes** and ensure quality:\n   ```bash\n   # Run tests\n   pytest\n   \n   # Check coverage\n   pytest --cov=src --cov-report=term-missing\n   \n   # Lint your code\n   flake8 src/ scripts/\n   \n   # Format code\n   black src/ scripts/\n   ```\n\n5. **Commit your changes:**\n   ```bash\n   git add .\n   git commit -m \"feat: add your feature description\"\n   ```\n\n6. **Push to your fork:**\n   ```bash\n   git push origin feature/your-feature-name\n   ```\n\n7. **Create a Pull Request** on GitHub\n   - Go to the [main repository](https://github.com/luismr/megasena-2025-analysis)\n   - Click \"Pull Requests\" → \"New Pull Request\"\n   - Select your fork and branch\n   - Fill in the PR template\n   - Submit!\n\n### Contribution Guidelines\n\n- ✅ Write tests for new features\n- ✅ Maintain 90%+ code coverage\n- ✅ Follow PEP 8 style guide\n- ✅ Update documentation\n- ✅ Use descriptive commit messages\n\n### CI/CD Checks\n\nYour PR will automatically run:\n- Unit tests on multiple platforms\n- Code coverage analysis\n- Linting and formatting checks\n- Security scans\n\nA bot will comment with coverage report! 📊\n\n## 📝 License\n\nMIT License - see the [LICENSE](LICENSE) file for details.\n\nCopyright (c) 2025 Luis Machado Reis\n\nThis is a personal analysis tool. Use at your own risk. Lottery is a game of chance.\n\n## 🍀 Good Luck!\n\nRemember: This tool is for educational and entertainment purposes. Past results do not guarantee future outcomes in random lottery draws.\n\n---\n\n**Boa Sorte na Mega da Virada 2025! 🎉**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluismr%2Fmegasena-2025-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluismr%2Fmegasena-2025-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluismr%2Fmegasena-2025-analysis/lists"}