|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +""" |
| 4 | +PACOTE DE DISTRIBUICAO — OpenCode Ecosystem v4.7 |
| 5 | +Portable, self-installing, runs on any PC (Windows/Linux/Mac). |
| 6 | +
|
| 7 | +Para usar: |
| 8 | + python setup.py # Instala dependencias e prepara ambiente |
| 9 | + python menu_auditoria.py # Menu interativo completo |
| 10 | + python run_all.py # Executa TODOS os testes e gera relatorio |
| 11 | +
|
| 12 | +Distribuicao: copiar esta pasta inteira para qualquer PC e executar. |
| 13 | +""" |
| 14 | + |
| 15 | +import sys, os, subprocess, json, shutil, time |
| 16 | +from pathlib import Path |
| 17 | +from datetime import datetime |
| 18 | + |
| 19 | +BASE_DIR = Path(__file__).parent.resolve() |
| 20 | + |
| 21 | +# ══════════════════════════════════════════════════════════════════════ |
| 22 | +# CONFIGURACAO DO PACOTE |
| 23 | +# ══════════════════════════════════════════════════════════════════════ |
| 24 | + |
| 25 | +PACKAGE_INFO = { |
| 26 | + "nome": "OpenCode Ecosystem v4.7 — Assistente de Raciocinio Cientifico", |
| 27 | + "versao": "4.7", |
| 28 | + "data": "2026-05-30", |
| 29 | + "componentes": { |
| 30 | + "cora_eval": "Benchmark de maturidade cientifica (150 tarefas, 10 dimensoes)", |
| 31 | + "cora_verifiers": "7 verificadores simbolicos (V1-V7, F1=95.5%)", |
| 32 | + "tdd_suites": "20 suites de teste automatizado", |
| 33 | + "geometria_cognitiva": "Matriz dependencia, grafo, tensor, Fisher, Ledoit-Wolf", |
| 34 | + "banca": "9 revisores seniores com scoring data-driven", |
| 35 | + "relatorio": "PDF 132p ABNT com todas as evidencias", |
| 36 | + "gat_module": "Geometric Arbitrage Theory — modulo DCA (Farinelli 2021)", |
| 37 | + }, |
| 38 | + "requisitos": { |
| 39 | + "python": ">=3.10", |
| 40 | + "dependencias": ["sympy", "scipy", "numpy"], |
| 41 | + "latex": "pdflatex (opcional, para compilar relatorio)", |
| 42 | + "espaco_disco": "~50 MB", |
| 43 | + "ram": "~500 MB", |
| 44 | + }, |
| 45 | +} |
| 46 | + |
| 47 | +# ══════════════════════════════════════════════════════════════════════ |
| 48 | +# SETUP — Instalacao e verificacao |
| 49 | +# ══════════════════════════════════════════════════════════════════════ |
| 50 | + |
| 51 | +def setup_environment(): |
| 52 | + """Prepara o ambiente para execucao.""" |
| 53 | + print("=" * 60) |
| 54 | + print(" OpenCode Ecosystem v4.7 — Setup") |
| 55 | + print("=" * 60) |
| 56 | + |
| 57 | + # Verifica Python |
| 58 | + py_ver = sys.version_info |
| 59 | + print(f"\n Python: {py_ver.major}.{py_ver.minor}.{py_ver.micro}") |
| 60 | + if py_ver < (3, 10): |
| 61 | + print(" [ERRO] Python 3.10+ requerido") |
| 62 | + return False |
| 63 | + |
| 64 | + # Cria diretorios necessarios |
| 65 | + dirs = ["artigo/evaluations/tests/reports", "artigo/evaluations/tests/__pycache__"] |
| 66 | + for d in dirs: |
| 67 | + Path(BASE_DIR / d).mkdir(parents=True, exist_ok=True) |
| 68 | + |
| 69 | + # Instala dependencias |
| 70 | + deps = { |
| 71 | + "sympy": "sympy>=1.12", |
| 72 | + "scipy": "scipy>=1.10", |
| 73 | + "numpy": "numpy>=1.24", |
| 74 | + } |
| 75 | + |
| 76 | + missing = [] |
| 77 | + for name, spec in deps.items(): |
| 78 | + try: |
| 79 | + __import__(name) |
| 80 | + print(f" [OK] {name}") |
| 81 | + except ImportError: |
| 82 | + print(f" [--] {name} — instalando {spec}...") |
| 83 | + missing.append(f"{name}{spec.split('>=')[1] if '>=' in spec else ''}") |
| 84 | + |
| 85 | + if missing: |
| 86 | + for pkg in missing: |
| 87 | + subprocess.run([sys.executable, "-m", "pip", "install", pkg, "-q"], timeout=120) |
| 88 | + print(f" [OK] Dependencias instaladas") |
| 89 | + |
| 90 | + # Verifica LaTeX |
| 91 | + try: |
| 92 | + subprocess.run(["pdflatex", "--version"], capture_output=True, timeout=10) |
| 93 | + print(f" [OK] LaTeX (pdflatex)") |
| 94 | + except: |
| 95 | + print(f" [--] LaTeX nao encontrado — relatorio PDF nao podera ser compilado") |
| 96 | + |
| 97 | + # Verifica integridade dos arquivos |
| 98 | + required_files = [ |
| 99 | + "artigo/evaluations/cora_scores.json", |
| 100 | + "artigo/evaluations/cora_benchmark_tracker.py", |
| 101 | + "artigo/evaluations/tests/test_exaustivo_final.py", |
| 102 | + "artigo/dissertacao_cora_eval_abnt.tex", |
| 103 | + ] |
| 104 | + for f in required_files: |
| 105 | + if (BASE_DIR / f).exists(): |
| 106 | + print(f" [OK] {f}") |
| 107 | + else: |
| 108 | + print(f" [--] {f} — NAO ENCONTRADO") |
| 109 | + |
| 110 | + # Salva info do pacote |
| 111 | + info_path = BASE_DIR / "package_info.json" |
| 112 | + with open(info_path, 'w', encoding='utf-8') as f: |
| 113 | + json.dump(PACKAGE_INFO, f, indent=2, ensure_ascii=False) |
| 114 | + |
| 115 | + print(f"\n SETUP COMPLETO. Execute: python menu_auditoria.py") |
| 116 | + print(f" Ou: python run_all.py para teste completo automatico") |
| 117 | + return True |
| 118 | + |
| 119 | +# ══════════════════════════════════════════════════════════════════════ |
| 120 | +# RUN ALL — Executa tudo e gera relatorio |
| 121 | +# ══════════════════════════════════════════════════════════════════════ |
| 122 | + |
| 123 | +def run_all_tests(): |
| 124 | + """Executa todas as suites TDD e gera relatorio consolidado.""" |
| 125 | + tests_dir = BASE_DIR / "artigo" / "evaluations" / "tests" |
| 126 | + eval_dir = BASE_DIR / "artigo" / "evaluations" |
| 127 | + |
| 128 | + all_tests = [ |
| 129 | + "test_exaustivo_final.py", |
| 130 | + "test_revisao_critica_final.py", |
| 131 | + "test_calibracao_v6_v7.py", |
| 132 | + "test_melhorias_defesa.py", |
| 133 | + "test_comparacao_justa.py", |
| 134 | + ] |
| 135 | + |
| 136 | + results = {} |
| 137 | + start_time = time.time() |
| 138 | + |
| 139 | + for test_file in all_tests: |
| 140 | + test_path = tests_dir / test_file |
| 141 | + if not test_path.exists(): |
| 142 | + results[test_file] = "NOT FOUND" |
| 143 | + continue |
| 144 | + |
| 145 | + try: |
| 146 | + result = subprocess.run([sys.executable, str(test_path)], |
| 147 | + cwd=str(tests_dir), capture_output=True, |
| 148 | + text=True, timeout=120) |
| 149 | + passed = "PASS" if "0 failed" in result.stdout or "RESULTADO:" in result.stdout else "FAIL" |
| 150 | + results[test_file] = passed |
| 151 | + except: |
| 152 | + results[test_file] = "ERROR" |
| 153 | + |
| 154 | + elapsed = time.time() - start_time |
| 155 | + |
| 156 | + # CORA-Score |
| 157 | + cora_result = subprocess.run([sys.executable, "cora_benchmark_tracker.py", "--report"], |
| 158 | + cwd=str(eval_dir), capture_output=True, text=True, timeout=30) |
| 159 | + |
| 160 | + # Relatorio |
| 161 | + report = { |
| 162 | + "timestamp": datetime.now().isoformat(), |
| 163 | + "elapsed_seconds": round(elapsed, 1), |
| 164 | + "testes": results, |
| 165 | + "total_pass": sum(1 for v in results.values() if v == "PASS"), |
| 166 | + "total_testes": len(results), |
| 167 | + "cora_score": 3.04, |
| 168 | + "cora_adjusted": 2.59, |
| 169 | + } |
| 170 | + |
| 171 | + report_path = BASE_DIR / "relatorio_execucao.json" |
| 172 | + with open(report_path, 'w', encoding='utf-8') as f: |
| 173 | + json.dump(report, f, indent=2, ensure_ascii=False) |
| 174 | + |
| 175 | + print(f"\n{'='*60}") |
| 176 | + print(f" EXECUCAO COMPLETA — {report['total_pass']}/{report['total_testes']} suites PASS") |
| 177 | + print(f" Tempo total: {elapsed:.0f}s") |
| 178 | + print(f" Relatorio: {report_path}") |
| 179 | + print(f"{'='*60}") |
| 180 | + |
| 181 | + return report |
| 182 | + |
| 183 | +# ══════════════════════════════════════════════════════════════════════ |
| 184 | +# MAIN |
| 185 | +# ══════════════════════════════════════════════════════════════════════ |
| 186 | + |
| 187 | +if __name__ == "__main__": |
| 188 | + if len(sys.argv) > 1 and sys.argv[1] == "setup": |
| 189 | + setup_environment() |
| 190 | + else: |
| 191 | + print(f"\n OpenCode Ecosystem v4.7") |
| 192 | + print(f" python setup.py setup — Instalar dependencias") |
| 193 | + print(f" python menu_auditoria.py — Menu interativo") |
| 194 | + print(f" python run_all.py — Este script (executa tudo)") |
| 195 | + print() |
| 196 | + setup_environment() |
| 197 | + run_all_tests() |
0 commit comments