dashgusbr 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dashgusbr-0.1.0/.github/workflows/ci.yml +31 -0
- dashgusbr-0.1.0/.github/workflows/publish.yml +28 -0
- dashgusbr-0.1.0/.gitignore +31 -0
- dashgusbr-0.1.0/CHANGELOG.md +19 -0
- dashgusbr-0.1.0/LICENSE +21 -0
- dashgusbr-0.1.0/PKG-INFO +179 -0
- dashgusbr-0.1.0/README.md +128 -0
- dashgusbr-0.1.0/examples/demo.py +45 -0
- dashgusbr-0.1.0/pyproject.toml +57 -0
- dashgusbr-0.1.0/src/dashgusbr/__init__.py +39 -0
- dashgusbr-0.1.0/src/dashgusbr/_theme.py +113 -0
- dashgusbr-0.1.0/src/dashgusbr/analytics.py +363 -0
- dashgusbr-0.1.0/src/dashgusbr/client.py +183 -0
- dashgusbr-0.1.0/src/dashgusbr/config.py +40 -0
- dashgusbr-0.1.0/src/dashgusbr/data.py +93 -0
- dashgusbr-0.1.0/src/dashgusbr/schema.py +125 -0
- dashgusbr-0.1.0/src/dashgusbr/viz.py +342 -0
- dashgusbr-0.1.0/tests/conftest.py +49 -0
- dashgusbr-0.1.0/tests/test_analytics.py +108 -0
- dashgusbr-0.1.0/tests/test_client.py +58 -0
- dashgusbr-0.1.0/tests/test_data.py +55 -0
- dashgusbr-0.1.0/tests/test_schema.py +36 -0
- dashgusbr-0.1.0/tests/test_viz.py +66 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
pip install -e ".[dev]"
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: pytest -q
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-and-publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write # necessário para Trusted Publishing (OIDC)
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Python
|
|
18
|
+
uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
|
|
22
|
+
- name: Build package
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip build
|
|
25
|
+
python -m build
|
|
26
|
+
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.eggs/
|
|
8
|
+
|
|
9
|
+
# Ambientes
|
|
10
|
+
.venv/
|
|
11
|
+
venv/
|
|
12
|
+
env/
|
|
13
|
+
|
|
14
|
+
# Testes / cobertura
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.coverage
|
|
17
|
+
htmlcov/
|
|
18
|
+
|
|
19
|
+
# IDEs
|
|
20
|
+
.vscode/
|
|
21
|
+
.idea/
|
|
22
|
+
|
|
23
|
+
# Jupyter
|
|
24
|
+
.ipynb_checkpoints/
|
|
25
|
+
|
|
26
|
+
# Saídas de exemplo
|
|
27
|
+
demo_brasileirao.html
|
|
28
|
+
|
|
29
|
+
# SO
|
|
30
|
+
Thumbs.db
|
|
31
|
+
.DS_Store
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Todas as mudanças relevantes deste projeto são documentadas neste arquivo.
|
|
4
|
+
|
|
5
|
+
O formato segue [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/)
|
|
6
|
+
e o projeto adota [Versionamento Semântico](https://semver.org/lang/pt-BR/).
|
|
7
|
+
|
|
8
|
+
## [Não lançado]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-07-22
|
|
11
|
+
|
|
12
|
+
### Adicionado
|
|
13
|
+
- Cliente `Brasileirao` para consumo da OBT do projeto Infra-Brasileirao.
|
|
14
|
+
- Camadas puras `data`, `analytics` e `viz` (gráficos Plotly).
|
|
15
|
+
- Módulos de apoio `config`, `schema` e tema visual.
|
|
16
|
+
- Suíte de testes (`pytest`) e exemplo de uso em `examples/demo.py`.
|
|
17
|
+
|
|
18
|
+
[Não lançado]: https://github.com/gustavogasperetti/DashGusBr-lib/compare/v0.1.0...HEAD
|
|
19
|
+
[0.1.0]: https://github.com/gustavogasperetti/DashGusBr-lib/releases/tag/v0.1.0
|
dashgusbr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gustavo Gasperetti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dashgusbr-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dashgusbr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Camada de consumo e visualização (Plotly) do histórico de partidas do Campeonato Brasileiro, sobre a OBT do projeto Infra-Brasileirao.
|
|
5
|
+
Project-URL: Homepage, https://github.com/gustavogasperetti/DashGusBr-lib
|
|
6
|
+
Project-URL: Repository, https://github.com/gustavogasperetti/DashGusBr-lib
|
|
7
|
+
Project-URL: Issues, https://github.com/gustavogasperetti/DashGusBr-lib/issues
|
|
8
|
+
Project-URL: Fonte de dados (ETL), https://github.com/gustavogasperetti/Infra-Brasileirao
|
|
9
|
+
Author-email: Gustavo Gasperetti <gustavolgasperetti@gmail.com>
|
|
10
|
+
License: MIT License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026 Gustavo Gasperetti
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Keywords: brasileirao,dados,dataviz,futebol,pandas,plotly
|
|
33
|
+
Classifier: Development Status :: 3 - Alpha
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Natural Language :: Portuguese (Brazilian)
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
43
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
44
|
+
Requires-Python: >=3.9
|
|
45
|
+
Requires-Dist: pandas>=2.0
|
|
46
|
+
Requires-Dist: plotly>=5.19
|
|
47
|
+
Provides-Extra: dev
|
|
48
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
49
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
50
|
+
Description-Content-Type: text/markdown
|
|
51
|
+
|
|
52
|
+
# dashgusbr
|
|
53
|
+
|
|
54
|
+
**Análise e visualização do histórico completo do Campeonato Brasileiro (1971–hoje), em uma linha de Python.**
|
|
55
|
+
|
|
56
|
+
`dashgusbr` é a camada de consumo e visualização de uma arquitetura serverless desacoplada em dois
|
|
57
|
+
repositórios: o [Infra-Brasileirao](https://github.com/gustavogasperetti/Infra-Brasileirao) roda o
|
|
58
|
+
pipeline ETL agendado (cron) que limpa e consolida todas as partidas do Brasileirão em uma
|
|
59
|
+
**OBT (One Big Table)** publicada na camada gold; este repositório contém apenas a biblioteca, que
|
|
60
|
+
lê essa tabela (CSV no GitHub, com fallback para Google Sheets) e oferece análises prontas em
|
|
61
|
+
**Pandas** e gráficos interativos em **Plotly**. O único acoplamento entre os dois é o contrato de
|
|
62
|
+
dados: a URL da OBT e o schema documentado abaixo.
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ ┌────────────┐
|
|
66
|
+
│ Fontes brutas │ ──▶ │ Pipeline ETL │ ──▶ │ OBT (camada gold) │ ──▶ │ dashgusbr │
|
|
67
|
+
└─────────────┘ └──────────────┘ │ GitHub / Sheets │ │ análise+viz│
|
|
68
|
+
└──────────────────┘ └────────────┘
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Instalação
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install dashgusbr
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Requer Python ≥ 3.9. Dependências: `pandas` e `plotly`.
|
|
78
|
+
|
|
79
|
+
## Uso rápido
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from dashgusbr import Brasileirao
|
|
83
|
+
|
|
84
|
+
br = Brasileirao() # baixa a OBT na primeira consulta e cacheia
|
|
85
|
+
|
|
86
|
+
br.tabela(2023) # DataFrame: classificação de 2023
|
|
87
|
+
br.plot_tabela(2023).show() # gráfico de barras da classificação
|
|
88
|
+
|
|
89
|
+
br.plot_evolucao(["Palmeiras", "Botafogo"], 2023).show() # corrida do título
|
|
90
|
+
br.plot_confronto("Flamengo", "Palmeiras").show() # histórico do confronto
|
|
91
|
+
br.plot_historico("Santos").show() # aproveitamento temporada a temporada
|
|
92
|
+
br.plot_gols_por_temporada().show() # média de gols/jogo desde 1971
|
|
93
|
+
br.plot_mandante_visitante().show() # o fator casa ao longo da história
|
|
94
|
+
br.plot_placares().show() # heatmap: frequência de cada placar
|
|
95
|
+
br.goleadas(10) # DataFrame: as 10 maiores goleadas
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Métodos utilitários: `br.anos()`, `br.times(ano=2023)`, `br.partidas(ano=2023, time="Grêmio")`,
|
|
99
|
+
`br.recarregar()` (força novo download).
|
|
100
|
+
|
|
101
|
+
## Uso avançado — camadas puras
|
|
102
|
+
|
|
103
|
+
A classe `Brasileirao` é uma fachada. Por baixo, a biblioteca é organizada em três camadas de
|
|
104
|
+
funções puras que você pode importar diretamente (por exemplo, para montar seu próprio dashboard
|
|
105
|
+
em Streamlit):
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from dashgusbr import data, analytics, viz
|
|
109
|
+
|
|
110
|
+
df = data.carregar_dados() # OBT completa, schema canônico
|
|
111
|
+
tab = analytics.classificacao(df, ano=2023) # DataFrame → DataFrame
|
|
112
|
+
fig = viz.classificacao(tab) # DataFrame → plotly Figure
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
| Camada | Responsabilidade | Principais funções |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `dashgusbr.data` | carga, fallback e cache | `carregar_dados`, `limpar_cache` |
|
|
118
|
+
| `dashgusbr.analytics` | agregações Pandas | `classificacao`, `evolucao_pontos`, `historico_time`, `confronto`, `estatisticas_temporada`, `distribuicao_placares`, `maiores_goleadas` |
|
|
119
|
+
| `dashgusbr.viz` | figuras Plotly | `classificacao`, `evolucao`, `historico`, `confronto`, `gols_por_temporada`, `mandante_visitante`, `distribuicao_placares` |
|
|
120
|
+
|
|
121
|
+
## Fontes de dados
|
|
122
|
+
|
|
123
|
+
Por padrão, `dashgusbr` tenta o CSV publicado no GitHub e, se indisponível, cai para o Google
|
|
124
|
+
Sheets. Também é possível apontar para um arquivo local ou URL própria:
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
br = Brasileirao() # auto: GitHub → Sheets
|
|
128
|
+
br = Brasileirao(fonte="sheets") # força o Google Sheets
|
|
129
|
+
br = Brasileirao(fonte="dados/obt.csv") # arquivo local no mesmo schema
|
|
130
|
+
br = Brasileirao(github_url="https://raw.githubusercontent.com/.../obt.csv")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Schema da OBT
|
|
134
|
+
|
|
135
|
+
A biblioteca normaliza os nomes na carga (`Data` → `data`, `Mandante` → `mandante`, ...) e valida
|
|
136
|
+
as colunas obrigatórias. Schema canônico:
|
|
137
|
+
|
|
138
|
+
| Coluna | Tipo | Descrição |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `id_partida` | int | identificador da partida |
|
|
141
|
+
| `ano_campeonato` | int | temporada |
|
|
142
|
+
| `data` | date | data da partida |
|
|
143
|
+
| `mandante` / `visitante` | str | times |
|
|
144
|
+
| `estado_mandante` / `estado_visitante` | str | UF de cada time |
|
|
145
|
+
| `gols_mandante` / `gols_visitante` | int | placar |
|
|
146
|
+
| `resultado_mandante` / `resultado_visitante` | str | `V`/`E`/`D` |
|
|
147
|
+
| `placar_status` | str | status do placar |
|
|
148
|
+
| `fase` / `tipo_fase` | str | fase do campeonato (`Pontos Corridos`, mata-mata...) |
|
|
149
|
+
| `is_mata_mata` / `is_classico_estadual` | bool | flags |
|
|
150
|
+
| `total_gols`, `saldo_gols_*` | int | derivadas do placar |
|
|
151
|
+
| `pontos_mandante` / `pontos_visitante` | int | pontos da partida, **já na regra da época** |
|
|
152
|
+
|
|
153
|
+
> **Nota histórica:** a vitória valia **2 pontos até 1994** e **3 pontos a partir de 1995**. As
|
|
154
|
+
> colunas de pontos já vêm calculadas pelo ETL com a regra correta de cada era; por isso as tabelas
|
|
155
|
+
> de classificação somam esses pontos (em vez de recalcular 3-1-0) e o **aproveitamento** é
|
|
156
|
+
> normalizado pelo valor da vitória da temporada — a única métrica comparável entre eras.
|
|
157
|
+
|
|
158
|
+
Apenas jogos com `tipo_fase == "Pontos Corridos"` entram na classificação e nas estatísticas de
|
|
159
|
+
temporada; o confronto direto considera todas as fases.
|
|
160
|
+
|
|
161
|
+
## Desenvolvimento
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
git clone https://github.com/gustavogasperetti/DashGusBr-lib.git
|
|
165
|
+
cd DashGusBr-lib
|
|
166
|
+
pip install -e ".[dev]"
|
|
167
|
+
pytest # suíte offline (fixture com mini-OBT)
|
|
168
|
+
pytest -m rede -o addopts="" # smoke tests que baixam a OBT real (requer internet)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Antes da publicação no PyPI, é possível instalar direto do GitHub:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pip install git+https://github.com/gustavogasperetti/DashGusBr-lib.git
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Licença
|
|
178
|
+
|
|
179
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# dashgusbr
|
|
2
|
+
|
|
3
|
+
**Análise e visualização do histórico completo do Campeonato Brasileiro (1971–hoje), em uma linha de Python.**
|
|
4
|
+
|
|
5
|
+
`dashgusbr` é a camada de consumo e visualização de uma arquitetura serverless desacoplada em dois
|
|
6
|
+
repositórios: o [Infra-Brasileirao](https://github.com/gustavogasperetti/Infra-Brasileirao) roda o
|
|
7
|
+
pipeline ETL agendado (cron) que limpa e consolida todas as partidas do Brasileirão em uma
|
|
8
|
+
**OBT (One Big Table)** publicada na camada gold; este repositório contém apenas a biblioteca, que
|
|
9
|
+
lê essa tabela (CSV no GitHub, com fallback para Google Sheets) e oferece análises prontas em
|
|
10
|
+
**Pandas** e gráficos interativos em **Plotly**. O único acoplamento entre os dois é o contrato de
|
|
11
|
+
dados: a URL da OBT e o schema documentado abaixo.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
┌─────────────┐ ┌──────────────┐ ┌──────────────────┐ ┌────────────┐
|
|
15
|
+
│ Fontes brutas │ ──▶ │ Pipeline ETL │ ──▶ │ OBT (camada gold) │ ──▶ │ dashgusbr │
|
|
16
|
+
└─────────────┘ └──────────────┘ │ GitHub / Sheets │ │ análise+viz│
|
|
17
|
+
└──────────────────┘ └────────────┘
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Instalação
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install dashgusbr
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requer Python ≥ 3.9. Dependências: `pandas` e `plotly`.
|
|
27
|
+
|
|
28
|
+
## Uso rápido
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from dashgusbr import Brasileirao
|
|
32
|
+
|
|
33
|
+
br = Brasileirao() # baixa a OBT na primeira consulta e cacheia
|
|
34
|
+
|
|
35
|
+
br.tabela(2023) # DataFrame: classificação de 2023
|
|
36
|
+
br.plot_tabela(2023).show() # gráfico de barras da classificação
|
|
37
|
+
|
|
38
|
+
br.plot_evolucao(["Palmeiras", "Botafogo"], 2023).show() # corrida do título
|
|
39
|
+
br.plot_confronto("Flamengo", "Palmeiras").show() # histórico do confronto
|
|
40
|
+
br.plot_historico("Santos").show() # aproveitamento temporada a temporada
|
|
41
|
+
br.plot_gols_por_temporada().show() # média de gols/jogo desde 1971
|
|
42
|
+
br.plot_mandante_visitante().show() # o fator casa ao longo da história
|
|
43
|
+
br.plot_placares().show() # heatmap: frequência de cada placar
|
|
44
|
+
br.goleadas(10) # DataFrame: as 10 maiores goleadas
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Métodos utilitários: `br.anos()`, `br.times(ano=2023)`, `br.partidas(ano=2023, time="Grêmio")`,
|
|
48
|
+
`br.recarregar()` (força novo download).
|
|
49
|
+
|
|
50
|
+
## Uso avançado — camadas puras
|
|
51
|
+
|
|
52
|
+
A classe `Brasileirao` é uma fachada. Por baixo, a biblioteca é organizada em três camadas de
|
|
53
|
+
funções puras que você pode importar diretamente (por exemplo, para montar seu próprio dashboard
|
|
54
|
+
em Streamlit):
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from dashgusbr import data, analytics, viz
|
|
58
|
+
|
|
59
|
+
df = data.carregar_dados() # OBT completa, schema canônico
|
|
60
|
+
tab = analytics.classificacao(df, ano=2023) # DataFrame → DataFrame
|
|
61
|
+
fig = viz.classificacao(tab) # DataFrame → plotly Figure
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
| Camada | Responsabilidade | Principais funções |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `dashgusbr.data` | carga, fallback e cache | `carregar_dados`, `limpar_cache` |
|
|
67
|
+
| `dashgusbr.analytics` | agregações Pandas | `classificacao`, `evolucao_pontos`, `historico_time`, `confronto`, `estatisticas_temporada`, `distribuicao_placares`, `maiores_goleadas` |
|
|
68
|
+
| `dashgusbr.viz` | figuras Plotly | `classificacao`, `evolucao`, `historico`, `confronto`, `gols_por_temporada`, `mandante_visitante`, `distribuicao_placares` |
|
|
69
|
+
|
|
70
|
+
## Fontes de dados
|
|
71
|
+
|
|
72
|
+
Por padrão, `dashgusbr` tenta o CSV publicado no GitHub e, se indisponível, cai para o Google
|
|
73
|
+
Sheets. Também é possível apontar para um arquivo local ou URL própria:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
br = Brasileirao() # auto: GitHub → Sheets
|
|
77
|
+
br = Brasileirao(fonte="sheets") # força o Google Sheets
|
|
78
|
+
br = Brasileirao(fonte="dados/obt.csv") # arquivo local no mesmo schema
|
|
79
|
+
br = Brasileirao(github_url="https://raw.githubusercontent.com/.../obt.csv")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Schema da OBT
|
|
83
|
+
|
|
84
|
+
A biblioteca normaliza os nomes na carga (`Data` → `data`, `Mandante` → `mandante`, ...) e valida
|
|
85
|
+
as colunas obrigatórias. Schema canônico:
|
|
86
|
+
|
|
87
|
+
| Coluna | Tipo | Descrição |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| `id_partida` | int | identificador da partida |
|
|
90
|
+
| `ano_campeonato` | int | temporada |
|
|
91
|
+
| `data` | date | data da partida |
|
|
92
|
+
| `mandante` / `visitante` | str | times |
|
|
93
|
+
| `estado_mandante` / `estado_visitante` | str | UF de cada time |
|
|
94
|
+
| `gols_mandante` / `gols_visitante` | int | placar |
|
|
95
|
+
| `resultado_mandante` / `resultado_visitante` | str | `V`/`E`/`D` |
|
|
96
|
+
| `placar_status` | str | status do placar |
|
|
97
|
+
| `fase` / `tipo_fase` | str | fase do campeonato (`Pontos Corridos`, mata-mata...) |
|
|
98
|
+
| `is_mata_mata` / `is_classico_estadual` | bool | flags |
|
|
99
|
+
| `total_gols`, `saldo_gols_*` | int | derivadas do placar |
|
|
100
|
+
| `pontos_mandante` / `pontos_visitante` | int | pontos da partida, **já na regra da época** |
|
|
101
|
+
|
|
102
|
+
> **Nota histórica:** a vitória valia **2 pontos até 1994** e **3 pontos a partir de 1995**. As
|
|
103
|
+
> colunas de pontos já vêm calculadas pelo ETL com a regra correta de cada era; por isso as tabelas
|
|
104
|
+
> de classificação somam esses pontos (em vez de recalcular 3-1-0) e o **aproveitamento** é
|
|
105
|
+
> normalizado pelo valor da vitória da temporada — a única métrica comparável entre eras.
|
|
106
|
+
|
|
107
|
+
Apenas jogos com `tipo_fase == "Pontos Corridos"` entram na classificação e nas estatísticas de
|
|
108
|
+
temporada; o confronto direto considera todas as fases.
|
|
109
|
+
|
|
110
|
+
## Desenvolvimento
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
git clone https://github.com/gustavogasperetti/DashGusBr-lib.git
|
|
114
|
+
cd DashGusBr-lib
|
|
115
|
+
pip install -e ".[dev]"
|
|
116
|
+
pytest # suíte offline (fixture com mini-OBT)
|
|
117
|
+
pytest -m rede -o addopts="" # smoke tests que baixam a OBT real (requer internet)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Antes da publicação no PyPI, é possível instalar direto do GitHub:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install git+https://github.com/gustavogasperetti/DashGusBr-lib.git
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Licença
|
|
127
|
+
|
|
128
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Demonstração da dashgusbr: gera um relatório HTML com os gráficos do MVP.
|
|
2
|
+
|
|
3
|
+
Uso:
|
|
4
|
+
python examples/demo.py [ano]
|
|
5
|
+
|
|
6
|
+
Baixa a OBT real (GitHub, com fallback para Sheets) e grava
|
|
7
|
+
``demo_brasileirao.html`` no diretório atual.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
from dashgusbr import Brasileirao
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main() -> None:
|
|
16
|
+
ano = int(sys.argv[1]) if len(sys.argv) > 1 else 2023
|
|
17
|
+
|
|
18
|
+
br = Brasileirao()
|
|
19
|
+
print(f"Base carregada: {len(br.partidas())} partidas, {br.anos()[0]}–{br.anos()[-1]}")
|
|
20
|
+
|
|
21
|
+
tabela = br.tabela(ano)
|
|
22
|
+
lideres = list(tabela.head(4)["time"])
|
|
23
|
+
print(f"G4 de {ano}: {', '.join(lideres)}")
|
|
24
|
+
|
|
25
|
+
figuras = [
|
|
26
|
+
br.plot_tabela(ano),
|
|
27
|
+
br.plot_evolucao(lideres, ano),
|
|
28
|
+
br.plot_confronto(lideres[0], lideres[1]),
|
|
29
|
+
br.plot_historico(lideres[0]),
|
|
30
|
+
br.plot_gols_por_temporada(),
|
|
31
|
+
br.plot_mandante_visitante(),
|
|
32
|
+
br.plot_placares(),
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
destino = "demo_brasileirao.html"
|
|
36
|
+
with open(destino, "w", encoding="utf-8") as saida:
|
|
37
|
+
saida.write(f"<html><head><meta charset='utf-8'><title>dashgusbr — {ano}</title></head><body>")
|
|
38
|
+
for i, fig in enumerate(figuras):
|
|
39
|
+
saida.write(fig.to_html(full_html=False, include_plotlyjs=(i == 0)))
|
|
40
|
+
saida.write("</body></html>")
|
|
41
|
+
print(f"Relatório gravado em {destino}")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dashgusbr"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Camada de consumo e visualização (Plotly) do histórico de partidas do Campeonato Brasileiro, sobre a OBT do projeto Infra-Brasileirao."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Gustavo Gasperetti", email = "gustavolgasperetti@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["brasileirao", "futebol", "dados", "plotly", "pandas", "dataviz"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Natural Language :: Portuguese (Brazilian)",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"pandas>=2.0",
|
|
31
|
+
"plotly>=5.19",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=8.0",
|
|
37
|
+
"pytest-cov>=5.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/gustavogasperetti/DashGusBr-lib"
|
|
42
|
+
Repository = "https://github.com/gustavogasperetti/DashGusBr-lib"
|
|
43
|
+
Issues = "https://github.com/gustavogasperetti/DashGusBr-lib/issues"
|
|
44
|
+
"Fonte de dados (ETL)" = "https://github.com/gustavogasperetti/Infra-Brasileirao"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.version]
|
|
47
|
+
path = "src/dashgusbr/__init__.py"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/dashgusbr"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
testpaths = ["tests"]
|
|
54
|
+
markers = [
|
|
55
|
+
"rede: testes que acessam a internet (desmarcados por padrão: -m 'not rede')",
|
|
56
|
+
]
|
|
57
|
+
addopts = "-m 'not rede'"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""dashgusbr — consumo e visualização do histórico do Campeonato Brasileiro.
|
|
2
|
+
|
|
3
|
+
Camada de consumo da arquitetura serverless do projeto Infra-Brasileirao:
|
|
4
|
+
lê a OBT (One Big Table) publicada pelo pipeline ETL (CSV no GitHub, com
|
|
5
|
+
fallback para Google Sheets) e oferece análises em Pandas e gráficos Plotly.
|
|
6
|
+
|
|
7
|
+
Uso rápido::
|
|
8
|
+
|
|
9
|
+
from dashgusbr import Brasileirao
|
|
10
|
+
|
|
11
|
+
br = Brasileirao()
|
|
12
|
+
br.tabela(2023) # DataFrame da classificação
|
|
13
|
+
br.plot_confronto("Flamengo", "Palmeiras").show()
|
|
14
|
+
|
|
15
|
+
Uso avançado (camadas puras)::
|
|
16
|
+
|
|
17
|
+
from dashgusbr import analytics, data, viz
|
|
18
|
+
|
|
19
|
+
df = data.carregar_dados()
|
|
20
|
+
tab = analytics.classificacao(df, ano=2023)
|
|
21
|
+
fig = viz.classificacao(tab)
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from . import analytics, config, data, schema, viz
|
|
25
|
+
from .client import Brasileirao
|
|
26
|
+
from .data import carregar_dados
|
|
27
|
+
|
|
28
|
+
__version__ = "0.1.0"
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"Brasileirao",
|
|
32
|
+
"carregar_dados",
|
|
33
|
+
"analytics",
|
|
34
|
+
"config",
|
|
35
|
+
"data",
|
|
36
|
+
"schema",
|
|
37
|
+
"viz",
|
|
38
|
+
"__version__",
|
|
39
|
+
]
|