gamesize 1.0.1__py3-none-any.whl
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.
- gamesize-1.0.1.dist-info/METADATA +235 -0
- gamesize-1.0.1.dist-info/RECORD +17 -0
- gamesize-1.0.1.dist-info/WHEEL +5 -0
- gamesize-1.0.1.dist-info/entry_points.txt +2 -0
- gamesize-1.0.1.dist-info/licenses/LICENSE +21 -0
- gamesize-1.0.1.dist-info/top_level.txt +1 -0
- inventory/__init__.py +4 -0
- inventory/__main__.py +7 -0
- inventory/cell_format.py +175 -0
- inventory/cli.py +856 -0
- inventory/config.py +104 -0
- inventory/data.py +278 -0
- inventory/excel.py +1022 -0
- inventory/i18n.py +688 -0
- inventory/network.py +495 -0
- inventory/scan.py +74 -0
- inventory/text.py +9 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gamesize
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Game inventory: GB per hour, backlog plan, history and wishlist
|
|
5
|
+
Author: Iker Abad
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/IkerAbad/game-inventory
|
|
8
|
+
Project-URL: Repository, https://github.com/IkerAbad/game-inventory
|
|
9
|
+
Project-URL: Issues, https://github.com/IkerAbad/game-inventory/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/IkerAbad/game-inventory/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: games,backlog,excel,openpyxl,inventory,steam
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Games/Entertainment
|
|
20
|
+
Classifier: Topic :: Office/Business
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: openpyxl<3.2,>=3.1.5
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
27
|
+
Requires-Dist: coverage>=7.6; extra == "dev"
|
|
28
|
+
Requires-Dist: pyflakes>=3.2; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Game inventory
|
|
32
|
+
|
|
33
|
+
[](https://github.com/IkerAbad/game-inventory/actions/workflows/ci.yml)
|
|
34
|
+
[](https://github.com/IkerAbad/game-inventory/actions/workflows/codeql.yml)
|
|
35
|
+
[](https://github.com/IkerAbad/game-inventory/blob/main/pyproject.toml)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
|
|
38
|
+
English | [Español](README.es.md)
|
|
39
|
+
|
|
40
|
+
Scan the folders where your games are installed, cross the disk size with the main-story hours and build an Excel workbook with the GB per hour ratio, a deletion plan, the history and the wishlist. The console and the workbook are available in English and Spanish.
|
|
41
|
+
|
|
42
|
+
## What it does
|
|
43
|
+
|
|
44
|
+
- Scans the drives and folders configured in `inventory/config.py` and measures every game on disk.
|
|
45
|
+
- Fills missing hours from the network (Deku Deals, twoaveragegamers and an estimate from Steam reviews), the Metascore and, when there is no Metascore, the share of positive Steam reviews.
|
|
46
|
+
- Purges from `hours.json` the keys of games that are no longer installed, only when every drive is present.
|
|
47
|
+
- Builds the Excel workbook with up to six sheets: Games, Space, Summary, Plan, History and Wishlist.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
Example workbook with fictional games. The personal paths column is not shown.
|
|
52
|
+
|
|
53
|
+
## Requirements
|
|
54
|
+
|
|
55
|
+
- Python 3.12 or newer.
|
|
56
|
+
- `openpyxl` (see `requirements.txt`).
|
|
57
|
+
- Network access is optional: `--offline` skips every request.
|
|
58
|
+
- The default libraries are Windows paths; `data/config.json` adapts them to any system.
|
|
59
|
+
|
|
60
|
+
## Limitations
|
|
61
|
+
|
|
62
|
+
- Hours are main-story estimates from third-party pages (Deku Deals, twoaveragegamers and Steam reviews). Those pages can change, rate-limit or block requests, and title matching can miss a game or pick another edition.
|
|
63
|
+
- With `--offline` there are no requests at all, so missing hours, Metascores and Steam percentages stay empty. The rest of the workbook is still built.
|
|
64
|
+
- Metascore and the Steam percentage use different scales and are never mixed into one number.
|
|
65
|
+
- It does not measure real playtime, achievements, save files, DLC owned separately, cloud libraries that are not installed, or games outside the configured folders.
|
|
66
|
+
- Folder size is the size on disk, not the download size. Compression, sparse files and hard links can make them differ.
|
|
67
|
+
- The verdicts are a suggestion based on GB per hour and the quartiles of the current list, not a recommendation.
|
|
68
|
+
- The default libraries are Windows paths; other systems need `data/config.json`.
|
|
69
|
+
- Some workbook dates are formulas, so Excel or LibreOffice has to recalculate after opening.
|
|
70
|
+
- Network access is best effort: there is a request budget and stored data, but no guarantee that a source answers.
|
|
71
|
+
- It never uninstalls or deletes a game. The purge only removes stale keys from `hours.json`, after a backup.
|
|
72
|
+
|
|
73
|
+
## Tests
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
py -m venv .venv
|
|
77
|
+
.venv\Scripts\activate
|
|
78
|
+
py -m pip install -e ".[dev]"
|
|
79
|
+
py -m unittest discover -s tests
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Run from the repository root. Without `openpyxl`, three test modules fail at import with `ModuleNotFoundError: No module named 'openpyxl'`; that is a missing dependency, not a failing test. `pip install -e .` or `pip install -r requirements.txt` installs it. Reproduced on 2026-11-23: a clean venv reported 3 import errors from the missing dependency, and after installing `requirements.txt` the same command ran 259 tests with `OK`.
|
|
83
|
+
|
|
84
|
+
## Install as a package
|
|
85
|
+
|
|
86
|
+
The distribution is `gamesize`, because PyPI rejected `game-inventory` as too
|
|
87
|
+
similar to an existing project. The command is still `game-inventory` and the
|
|
88
|
+
import package is still `inventory`.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
pip install gamesize
|
|
92
|
+
game-inventory --lang es
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
From the repository, `py -m pip install .` works the same. If the package is
|
|
96
|
+
already installed, running the script from the repository with `py -m pip
|
|
97
|
+
install -e .` gives the editable version.
|
|
98
|
+
|
|
99
|
+
The direct script and module commands below also work without installing. When installed, `data/` is read from the current folder unless `GAME_INVENTORY_DATA` points to another one.
|
|
100
|
+
|
|
101
|
+
Or as an isolated command with [pipx](https://pipx.pypa.io):
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
pipx install gamesize
|
|
105
|
+
game-inventory --version
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
cd C:\Dev\game-inventory
|
|
112
|
+
py -m pip install -r requirements.txt
|
|
113
|
+
py generate_inventory.py
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Or as a module, from the same folder:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
py -m inventory
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Or double-click `start.cmd`. It saves the output to `data/last_run.log` and keeps the window open when there is an error.
|
|
123
|
+
|
|
124
|
+
Options:
|
|
125
|
+
|
|
126
|
+
| Option | What it does |
|
|
127
|
+
|---|---|
|
|
128
|
+
| `--lang en\|es` | Output language for the console and the workbook. Default: `en`. |
|
|
129
|
+
| `--offline`, `--sin-red` | Do not use the network. |
|
|
130
|
+
| `--keep`, `--conservar` | Do not purge uninstalled game keys. |
|
|
131
|
+
| `--force-purge`, `--forzar-purga` | Allow purging more than half of the keys at once. |
|
|
132
|
+
| `--dry-run`, `--simular` | Scan and show the summary without writing anything. |
|
|
133
|
+
| `--top N` | Show the N best GB/h picks that are not completed or playing (0 disables it). |
|
|
134
|
+
| `--report PATH`, `--informe PATH` | Write a Markdown summary after the run. It cannot be inside `data/` or use the workbook path. |
|
|
135
|
+
| `--open`, `--abrir` | Open the saved workbook with the default application. |
|
|
136
|
+
| `--check-data`, `--validar` | Validate the JSON data files, stale metadata keys, invalid metadata values, repeated wishlist titles and the history, then exit. |
|
|
137
|
+
| `--strict`, `--estricto` | With `--check-data`, exit with code 1 when warnings are found. |
|
|
138
|
+
| `--output PATH`, `--salida PATH` | Write the Excel workbook to another path. |
|
|
139
|
+
| `--version` | Show the installed version. |
|
|
140
|
+
|
|
141
|
+
The workbook is written by default to `%USERPROFILE%\Desktop\Juegos\Inventario juegos GB por hora.xlsx` and keeps a `.bak.xlsx` copy of the previous run. The Spanish file name is kept so the existing workbook is updated in place. Close the workbook before running, otherwise the script stops before scanning anything.
|
|
142
|
+
|
|
143
|
+
Exit codes: `0` success, `1` aborted or invalid data, `130` cancelled with Ctrl+C.
|
|
144
|
+
|
|
145
|
+
`GAME_INVENTORY_LANG=es` changes the default language; `--lang` still wins.
|
|
146
|
+
|
|
147
|
+
## Data
|
|
148
|
+
|
|
149
|
+
All personal data lives in `data/`, which is not versioned. The script creates the folder when it does not exist.
|
|
150
|
+
|
|
151
|
+
| File | Content |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `data/hours.json` | Main-story hours by normalized key. `null` = no end. The `_metacritic`, `_steam`, `_dificultad` and `_notas` blocks keep the notes. |
|
|
154
|
+
| `data/wishlist.json` | Wishlist titles with hours, notes, Metacritic, Steam and difficulty. |
|
|
155
|
+
| `data/playing.json` | Keys of the games you are playing now. |
|
|
156
|
+
| `data/completed.json` | Keys of the games you finished but still have installed. |
|
|
157
|
+
| `data/history.csv` | One row per run day. It feeds the History sheet. |
|
|
158
|
+
| `data/config.json` | Optional. Overrides the libraries, loose paths, exclusions and output path. |
|
|
159
|
+
|
|
160
|
+
The source notes inside the JSON files keep the language they were written in.
|
|
161
|
+
|
|
162
|
+
## Robustness
|
|
163
|
+
|
|
164
|
+
- A syntax error in a JSON file aborts the run, shows the line and column, and writes nothing.
|
|
165
|
+
- Hours that are not positive numbers, `null` or `"?"` are treated as no data and reported.
|
|
166
|
+
- JSON, history and the workbook are written to a temporary file and renamed, so a mid-write failure leaves no corrupt file.
|
|
167
|
+
- The purge keeps `hours.json.bak` and refuses to remove more than half of the keys without `--force-purge`.
|
|
168
|
+
- If the history cannot be read or has broken rows, the original is kept as `history.csv.corrupto`.
|
|
169
|
+
- If the workbook is open, the script stops before scanning.
|
|
170
|
+
- Only one run can be active at a time, enforced by a lock in `data/`.
|
|
171
|
+
- BOM-prefixed JSON is accepted and broken history rows are skipped with a warning.
|
|
172
|
+
|
|
173
|
+
- `--dry-run` scans and prints the summary but writes no workbook, history or JSON.
|
|
174
|
+
|
|
175
|
+
## Troubleshooting
|
|
176
|
+
|
|
177
|
+
| Symptom | What to do |
|
|
178
|
+
|---|---|
|
|
179
|
+
| `ABORTED: the Excel file is open` | Close the workbook and run again. Nothing has been scanned. |
|
|
180
|
+
| `ABORTED: another inventory run is in progress` | Wait for the other run. The lock lives in `data/`. |
|
|
181
|
+
| `is not valid JSON (line ..., column ...)` | Fix that line or restore a backup of the file. |
|
|
182
|
+
| `Warning: cannot read history.csv` | The original is kept as `history.csv.corrupto` and the run writes a clean one. |
|
|
183
|
+
| A game is missing | Add its folder to `libraries` or `loose_paths` in `data/config.json`. |
|
|
184
|
+
| Every game shows NO DATA | `hours.json` is missing or its keys do not match the folder names. Run `--check-data`. |
|
|
185
|
+
|
|
186
|
+
## Structure
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
generate_inventory.py entry point
|
|
190
|
+
pyproject.toml package metadata and console script
|
|
191
|
+
CHANGELOG.md English changelog
|
|
192
|
+
CONTRIBUTING.md English contributing guide
|
|
193
|
+
SECURITY.md English security policy
|
|
194
|
+
docs/
|
|
195
|
+
DATA.md data formats and backups
|
|
196
|
+
ARCHITECTURE.md flow, modules and guarantees
|
|
197
|
+
EXAMPLES.md console, workbook and data folder examples
|
|
198
|
+
FAQ.md common questions
|
|
199
|
+
BENCHMARKS.md measured scan and workbook times
|
|
200
|
+
PUBLISHING.md build, PyPI and trusted publishing
|
|
201
|
+
tools/
|
|
202
|
+
check_all.py runs pyflakes, link and translation checks
|
|
203
|
+
check_dist.py checks the wheel and sdist contents
|
|
204
|
+
check_release.py checks a release tag against the changelogs
|
|
205
|
+
check_links.py checks relative links in the docs
|
|
206
|
+
inventory/
|
|
207
|
+
config.py drives, paths and network settings
|
|
208
|
+
data.py JSON: loading, formatting and safe writing
|
|
209
|
+
scan.py size, days installed and workbook lock
|
|
210
|
+
cell_format.py cells: Metacritic, Steam and difficulty
|
|
211
|
+
excel.py sheets, styles, charts and comparisons
|
|
212
|
+
network.py network autocomplete
|
|
213
|
+
i18n.py English and Spanish strings
|
|
214
|
+
cli.py options, orchestration and console summary
|
|
215
|
+
tests/ unit and end-to-end tests
|
|
216
|
+
start.cmd Windows launcher
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Documentation
|
|
220
|
+
|
|
221
|
+
`README.es.md` is the Spanish version. The personal notes with sources and decisions live in `data/NOTES.md`, which is not versioned.
|
|
222
|
+
|
|
223
|
+
- [Changelog](CHANGELOG.md) / [Registro de cambios](CHANGELOG.es.md)
|
|
224
|
+
- [Contributing](CONTRIBUTING.md) / [Contribuir](CONTRIBUTING.es.md)
|
|
225
|
+
- [Data formats](docs/DATA.md) / [Formatos de datos](docs/DATA.es.md)
|
|
226
|
+
- [Architecture](docs/ARCHITECTURE.md) / [Arquitectura](docs/ARCHITECTURE.es.md)
|
|
227
|
+
- [Examples](docs/EXAMPLES.md) / [Ejemplos](docs/EXAMPLES.es.md)
|
|
228
|
+
- [FAQ](docs/FAQ.md) / [Preguntas frecuentes](docs/FAQ.es.md)
|
|
229
|
+
- [Benchmarks](docs/BENCHMARKS.md) / [Rendimiento](docs/BENCHMARKS.es.md)
|
|
230
|
+
- [Publishing](docs/PUBLISHING.md) / [Publicación](docs/PUBLISHING.es.md)
|
|
231
|
+
- [Security](SECURITY.md) / [Seguridad](SECURITY.es.md)
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
gamesize-1.0.1.dist-info/licenses/LICENSE,sha256=aKXaQxz0hwNwpGUcL8hqQ7JKl0S-L0gb9qxNOHhZX3A,1066
|
|
2
|
+
inventory/__init__.py,sha256=XAW35DLguL5hCaOn4_jEmeX1Qon1wQrwOuPjTayh6o0,116
|
|
3
|
+
inventory/__main__.py,sha256=mxiaDZ_2WIF94H4uuV--8oawLBDBwVuptszlYmTydt8,150
|
|
4
|
+
inventory/cell_format.py,sha256=kyGR0WXM-3yvSOtYo2F7YOmWqtb1F7QVEwHilNcBnJ8,7108
|
|
5
|
+
inventory/cli.py,sha256=59t-kGyVKttNWp7daTBHzJaHqLeqIMNoJ5-n1azekNo,34966
|
|
6
|
+
inventory/config.py,sha256=UjJDO8ss1yVRwZWNMQfOOsx_yiGOMQhGIhBrpJj3PKo,3865
|
|
7
|
+
inventory/data.py,sha256=gPRtcdhPhFtEgToDJueul8BhrtCa8W2A5Tsrl7fuKKQ,11008
|
|
8
|
+
inventory/excel.py,sha256=a2ZZOlvOgByCaSXwp-yRLDkC5iPeWSAVyQuXm4a8fCc,44350
|
|
9
|
+
inventory/i18n.py,sha256=tgCdYuXPCyD3__WEnWs6Ac4bENMJGfq-g9Pvj0DLurk,43830
|
|
10
|
+
inventory/network.py,sha256=BBZAFJ6-j2WGa-BxelTuNWjFL6_ZzmQplCpPvohzTuY,21411
|
|
11
|
+
inventory/scan.py,sha256=nr7wBu_pcoOiv1_naUKu95zJOmv_XQ7uMLIBOyOylS8,2395
|
|
12
|
+
inventory/text.py,sha256=AIFjP6i_dpEoTEpddjjEDb4z_cEjgjdsd5hhrttXp2E,276
|
|
13
|
+
gamesize-1.0.1.dist-info/METADATA,sha256=dC-cXoa9dWE8eirXoihKLm19UMr8fPuNRU34FWweHcU,12442
|
|
14
|
+
gamesize-1.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
15
|
+
gamesize-1.0.1.dist-info/entry_points.txt,sha256=g1l-rvB-kI-HMjUitGSpWzdV2R7t1gy3DeSuU1KtWP4,53
|
|
16
|
+
gamesize-1.0.1.dist-info/top_level.txt,sha256=Aa2qQL83daQCBMHizsLTZqw3sXuGDAJNbPzP668oNw4,10
|
|
17
|
+
gamesize-1.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Iker Abad
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
inventory
|
inventory/__init__.py
ADDED
inventory/__main__.py
ADDED
inventory/cell_format.py
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Cell formatting: Metacritic, Steam and difficulty."""
|
|
3
|
+
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from .i18n import fmt_int, t
|
|
8
|
+
|
|
9
|
+
# Cell prefix when the score is the share of positive Steam reviews.
|
|
10
|
+
MC_FMT_STEAM = '"S "0"%"'
|
|
11
|
+
_ILLEGAL = re.compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f]")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def clean_text(value, limit=32767):
|
|
15
|
+
"""Remove control characters Excel rejects and cap the cell length."""
|
|
16
|
+
return _ILLEGAL.sub("", str(value))[:limit]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PctSteam(int):
|
|
20
|
+
"""Fallback score (0-100 positive Steam reviews): stored as a number so it sorts
|
|
21
|
+
with Metascores. fmt = cell number format (S prefix by default)."""
|
|
22
|
+
fmt = MC_FMT_STEAM
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _reviews(n):
|
|
26
|
+
return t("comment.reviews", n=n) if isinstance(n, int) else ""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def mc_cell(e, st=None):
|
|
30
|
+
"""_metacritic entry ({s, p, n, nota}) -> (cell value, comment or None).
|
|
31
|
+
s: number = Metascore; "s/n" = Metacritic does not publish a Metascore; null = no data.
|
|
32
|
+
st: _steam entry ({id, name, n, pct, desc}); only used when there is no numeric Metascore:
|
|
33
|
+
the cell holds 92 (PctSteam) with format 'S 92%' (positive Steam reviews, another scale)."""
|
|
34
|
+
pct = st.get("pct") if isinstance(st, dict) else None
|
|
35
|
+
if (isinstance(pct, int) and not isinstance(pct, bool) and 0 <= pct <= 100
|
|
36
|
+
and not (isinstance(e, dict) and isinstance(e.get("s"), (int, float)))):
|
|
37
|
+
note = str(e.get("nota") or "").strip() if isinstance(e, dict) else ""
|
|
38
|
+
note = (" (" + note + ")") if note else ""
|
|
39
|
+
n_st = st.get("n")
|
|
40
|
+
if isinstance(n_st, bool) or not isinstance(n_st, int):
|
|
41
|
+
n_st = 0
|
|
42
|
+
txt = (t("comment.no_metascore", note=note) + "\n"
|
|
43
|
+
+ t("comment.steam", pct=pct, n=fmt_int(n_st), desc=st.get("desc") or "?",
|
|
44
|
+
name=st.get("name") or "?", id=st.get("id")))
|
|
45
|
+
value = PctSteam(pct)
|
|
46
|
+
if st.get("pref"):
|
|
47
|
+
value.fmt = '"%s "0' % st["pref"] if st["pref"] != "S" else MC_FMT_STEAM
|
|
48
|
+
if st.get("txt"):
|
|
49
|
+
txt = t("comment.no_metascore", note=note) + "\n" + str(st["txt"])
|
|
50
|
+
return value, txt
|
|
51
|
+
if not isinstance(e, dict):
|
|
52
|
+
return None, None
|
|
53
|
+
s, n = e.get("s"), e.get("n")
|
|
54
|
+
p = str(e.get("p") or "").strip()
|
|
55
|
+
note = str(e.get("nota") or "").strip()
|
|
56
|
+
lines = []
|
|
57
|
+
if p and p != "?":
|
|
58
|
+
lines.append(t("comment.platform_reviews", platform=p, n=n)
|
|
59
|
+
if isinstance(n, int) else t("comment.platform", platform=p))
|
|
60
|
+
elif isinstance(n, int):
|
|
61
|
+
lines.append(t("comment.reviews", n=n))
|
|
62
|
+
if s is None and not note:
|
|
63
|
+
note = t("comment.no_data")
|
|
64
|
+
if note:
|
|
65
|
+
lines.append(note)
|
|
66
|
+
comment = "\n".join(lines) if lines and (p not in ("PC", "") or note) else None
|
|
67
|
+
if isinstance(s, str):
|
|
68
|
+
# 's/n' (no Metascore and no Steam page): leave the cell empty so sorting
|
|
69
|
+
# does not put a text first; the reason goes in the comment.
|
|
70
|
+
extra = (" (" + _reviews(n) + ")") if isinstance(n, int) else ""
|
|
71
|
+
lines2 = [t("comment.no_metascore_steam", note=extra)]
|
|
72
|
+
if note:
|
|
73
|
+
lines2.append(note)
|
|
74
|
+
return None, "\n".join(lines2)
|
|
75
|
+
if isinstance(s, (int, float)) and not isinstance(s, bool) and math.isfinite(s):
|
|
76
|
+
return s, comment
|
|
77
|
+
return None, comment
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def mc_comment(txt):
|
|
81
|
+
from openpyxl.comments import Comment
|
|
82
|
+
txt = clean_text(txt)
|
|
83
|
+
c = Comment(t("comment.metacritic") + "\n" + txt, t("comment.author"))
|
|
84
|
+
c.width = 270
|
|
85
|
+
c.height = 60 + 15 * (txt.count("\n") + len(txt) // 38)
|
|
86
|
+
return c
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def note_comment(txt):
|
|
90
|
+
from openpyxl.comments import Comment
|
|
91
|
+
txt = clean_text(txt)
|
|
92
|
+
c = Comment(t("comment.hours") + "\n" + txt, t("comment.author"))
|
|
93
|
+
c.width = 330
|
|
94
|
+
c.height = 70 + 15 * (txt.count("\n") + len(txt) // 48)
|
|
95
|
+
return c
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def mc_format(ws, cell_range, first_cell):
|
|
99
|
+
"""Score colour: >=75 green, 50-74 yellow, <50 red (Metascore and Steam % alike). Text is ignored."""
|
|
100
|
+
from openpyxl.formatting.rule import FormulaRule
|
|
101
|
+
from openpyxl.styles import PatternFill, Font
|
|
102
|
+
for cond, bg, fg in (("AND(ISNUMBER({c}),{c}>=75)", "C8E6C9", "1B5E20"),
|
|
103
|
+
("AND(ISNUMBER({c}),{c}>=50,{c}<75)", "FFF9C4", "7A4F01"),
|
|
104
|
+
("AND(ISNUMBER({c}),{c}<50)", "FFCDD2", "B71C1C")):
|
|
105
|
+
ws.conditional_formatting.add(
|
|
106
|
+
cell_range,
|
|
107
|
+
FormulaRule(formula=[cond.format(c=first_cell)],
|
|
108
|
+
fill=PatternFill("solid", start_color=bg, end_color=bg),
|
|
109
|
+
font=Font(bold=True, color=fg)))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
DIF_CERTAINTY = {
|
|
113
|
+
"source": "comment.backed",
|
|
114
|
+
"fuente": "comment.backed",
|
|
115
|
+
"consenso": "comment.consensus",
|
|
116
|
+
"inferencia": "comment.inference",
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def dif_cells(e):
|
|
121
|
+
"""_dificultad entry ({h, c, ct, src, nota}) -> (skill, complexity, comment or None, is_inference).
|
|
122
|
+
h = Skill 0-10 (reflexes, punishment, execution); c = Complexity 0-10 (rules, systems, learning
|
|
123
|
+
curve); ct = certainty: source | consenso | inferencia. A null axis is left empty."""
|
|
124
|
+
if not isinstance(e, dict):
|
|
125
|
+
return None, None, None, False
|
|
126
|
+
num = lambda v: (v if isinstance(v, (int, float)) and not isinstance(v, bool)
|
|
127
|
+
and math.isfinite(v) else None)
|
|
128
|
+
h, c = num(e.get("h")), num(e.get("c"))
|
|
129
|
+
if h is None and c is None:
|
|
130
|
+
return None, None, None, False
|
|
131
|
+
ct = e.get("ct") or "inferencia"
|
|
132
|
+
fmt = lambda v: "-" if v is None else ("%g" % v)
|
|
133
|
+
key = DIF_CERTAINTY.get(ct) if isinstance(ct, str) else None
|
|
134
|
+
cert = t(key) if key else str(ct)
|
|
135
|
+
if ct == "inferencia" and e.get("src"):
|
|
136
|
+
cert = t("comment.inference_source")
|
|
137
|
+
lines = [t("comment.skill", h=fmt(h), c=fmt(c)),
|
|
138
|
+
t("comment.certainty", cert=cert)]
|
|
139
|
+
if e.get("src"):
|
|
140
|
+
lines.append(t("comment.source", src=e["src"]))
|
|
141
|
+
if e.get("nota"):
|
|
142
|
+
lines.append(str(e["nota"]))
|
|
143
|
+
return h, c, "\n".join(lines), ct == "inferencia"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def dif_comment(txt):
|
|
147
|
+
from openpyxl.comments import Comment
|
|
148
|
+
txt = clean_text(txt)
|
|
149
|
+
c = Comment(t("comment.difficulty") + "\n" + txt, t("comment.author"))
|
|
150
|
+
c.width = 330
|
|
151
|
+
c.height = 70 + 15 * (txt.count("\n") + len(txt) // 48)
|
|
152
|
+
return c
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def dif_write(ws, row, first_col, e):
|
|
156
|
+
"""Skill in column first_col and Complexity in first_col+1; orange italics for inferences;
|
|
157
|
+
the comment carries certainty and source."""
|
|
158
|
+
from openpyxl.styles import Font
|
|
159
|
+
h, c, txt, inference = dif_cells(e)
|
|
160
|
+
for col, value in ((first_col, h), (first_col + 1, c)):
|
|
161
|
+
cell = ws.cell(row, col, value)
|
|
162
|
+
if txt:
|
|
163
|
+
cell.comment = dif_comment(txt)
|
|
164
|
+
if inference and value is not None:
|
|
165
|
+
cell.font = Font(italic=True, color="C2410C")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def dif_format(ws, cell_range):
|
|
169
|
+
"""0-10 colour scale: green (easy) -> yellow -> red (hard). Informative."""
|
|
170
|
+
from openpyxl.formatting.rule import ColorScaleRule
|
|
171
|
+
ws.conditional_formatting.add(
|
|
172
|
+
cell_range,
|
|
173
|
+
ColorScaleRule(start_type="num", start_value=0, start_color="C8E6C9",
|
|
174
|
+
mid_type="num", mid_value=5, mid_color="FFF9C4",
|
|
175
|
+
end_type="num", end_value=10, end_color="FFCDD2"))
|