feat(prezentacja): eksport wyników do Excela — tabela robocza (DAN-23/PRE-10)
Testy / Testy warstwy logicznej (silnik) (pull_request) Successful in 10m29s
Testy / Testy warstwy prezentacji (dostęp do baz) (pull_request) Successful in 9m32s
Testy / Build obrazu silnika B (swisseph) (pull_request) Successful in 16s
Testy / Kontrola składni wszystkich warstw (pull_request) Successful in 11s
Testy / Testy warstwy prezentacji (dostęp do baz) (push) Has been cancelled
Testy / Build obrazu silnika B (swisseph) (push) Has been cancelled
Testy / Kontrola składni wszystkich warstw (push) Has been cancelled
Testy / Testy warstwy logicznej (silnik) (push) Has been cancelled
build / build (push) Successful in 53s
Testy / Testy warstwy logicznej (silnik) (pull_request) Successful in 10m29s
Testy / Testy warstwy prezentacji (dostęp do baz) (pull_request) Successful in 9m32s
Testy / Build obrazu silnika B (swisseph) (pull_request) Successful in 16s
Testy / Kontrola składni wszystkich warstw (pull_request) Successful in 11s
Testy / Testy warstwy prezentacji (dostęp do baz) (push) Has been cancelled
Testy / Build obrazu silnika B (swisseph) (push) Has been cancelled
Testy / Kontrola składni wszystkich warstw (push) Has been cancelled
Testy / Testy warstwy logicznej (silnik) (push) Has been cancelled
build / build (push) Successful in 53s
Astrolog chce PRACOWAĆ z dopasowaniami: filtrować, sortować, zaznaczać, usuwać — najwygodniej w Excelu. Raport z logiki jest zagnieżdżony (obiekt → fasety → próbki), więc spłaszczamy go do JEDNEJ płaskiej tabeli: wiersz = jedno dopasowanie z bazy. Kolumny: Obiekt · Faseta · Typ · Token · Sygnifikator · Rozwinięcie · Opis/efekt. - `report_export.py`: `report_to_xlsx(report)` (openpyxl). Auto-filtr + zamrożony nagłówek = filtrowanie/sortowanie od razu; „Opis" zawijany. Bez ozdób — materiał roboczy. Plik składamy TU, w prezentacji (jak PDF idzie przez render): logika liczy, prezentacja formatuje wyjście. - `/interpret` dostaje akcję `export` → pobranie `.xlsx` (nie strona). Przycisk „Pobierz Excel" obok „Szukaj interpretacji". - Zależność: openpyxl (czysty Python). Zero swissepha, zero walidacji krzyżowej, zero danych od użytkownika — pierwsza z iteracji „czysto". Testy: +7 (round-trip pliku: nagłówek, spłaszczenie, auto- filtr/zamrożenie, pusty-bezpieczny, %, wpięcie w UI). Prezentacja 180. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit was merged in pull request #45.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
"""Eksport raportu do Excela — tabela robocza (DAN-23/PRE-10)."""
|
||||
import io
|
||||
import pathlib
|
||||
|
||||
from openpyxl import load_workbook
|
||||
|
||||
from app.report_export import HEADERS, report_to_xlsx
|
||||
|
||||
APP = pathlib.Path(__file__).resolve().parents[1] / "app"
|
||||
MAIN = (APP / "main.py").read_text(encoding="utf-8")
|
||||
INTERPRET = (APP / "templates" / "interpret.html").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def _report() -> dict:
|
||||
return {"engine": "own", "objects": [
|
||||
{"name": "Sun", "facets": [
|
||||
{"type": "sign", "label": "w znaku Cancer", "token": "[Su + Can", "samples": [
|
||||
{"significator": "Su Can", "expanded": "Słońce w Raku", "effect": "opiekuńczy"},
|
||||
{"significator": "Su Can h10", "expanded": "Słońce w Raku, 10 dom", "effect": "kariera 50% publiczna"}]},
|
||||
{"type": "house", "label": "w 10 domu", "token": "10 H.", "samples": [
|
||||
{"significator": "Su h10", "expanded": "Słońce w 10 domu", "effect": "ambicja"}]}]},
|
||||
{"name": "Moon", "facets": [
|
||||
{"type": "aspect", "label": "trygon z Mars", "token": "[Mo tri [Ma", "samples": [
|
||||
{"significator": "Mo tri Ma", "expanded": "Księżyc trygon Mars", "effect": "energia"}]}]},
|
||||
]}
|
||||
|
||||
|
||||
def _load(report):
|
||||
return load_workbook(io.BytesIO(report_to_xlsx(report))).active
|
||||
|
||||
|
||||
def test_header_row_matches_columns():
|
||||
ws = _load(_report())
|
||||
assert [c.value for c in ws[1]] == HEADERS
|
||||
|
||||
|
||||
def test_one_row_per_sample_flattened():
|
||||
"""Zagnieżdżenie obiekt→fasety→próbki rozwijamy na płaskie wiersze."""
|
||||
ws = _load(_report())
|
||||
assert ws.max_row == 1 + 4 # nagłówek + 4 dopasowania
|
||||
|
||||
|
||||
def test_row_carries_object_facet_and_effect():
|
||||
ws = _load(_report())
|
||||
vals = [[c.value for c in row] for row in ws.iter_rows(min_row=2)]
|
||||
first = vals[0]
|
||||
assert first[0] == "Sun" and first[1] == "w znaku Cancer" and first[2] == "sign"
|
||||
assert first[6] == "opiekuńczy" # kolumna „Opis / efekt"
|
||||
assert any("kariera 50% publiczna" in (r[6] or "") for r in vals) # % nie psuje niczego
|
||||
|
||||
|
||||
def test_autofilter_and_frozen_header_for_working_table():
|
||||
"""Filtrowanie/sortowanie od razu w Excelu (PRE-10)."""
|
||||
ws = _load(_report())
|
||||
assert ws.auto_filter.ref == "A1:G5"
|
||||
assert ws.freeze_panes == "A2"
|
||||
|
||||
|
||||
def test_empty_report_is_safe():
|
||||
ws = _load({"objects": []})
|
||||
assert [c.value for c in ws[1]] == HEADERS
|
||||
assert ws.max_row == 1 # sam nagłówek, bez wyjątku
|
||||
assert ws.auto_filter.ref == "A1:G1"
|
||||
|
||||
|
||||
# ── wpięcie w UI ──
|
||||
|
||||
def test_interpret_has_export_button():
|
||||
assert 'name="action" value="export"' in INTERPRET
|
||||
|
||||
|
||||
def test_handler_returns_xlsx_download():
|
||||
assert 'if action == "export":' in MAIN
|
||||
assert "report_to_xlsx" in MAIN
|
||||
assert "spreadsheetml.sheet" in MAIN # media type .xlsx
|
||||
assert 'filename="interpretacje.xlsx"' in MAIN
|
||||
Reference in New Issue
Block a user