Files
2026-07-17 12:57:18 +03:00

30 lines
1.1 KiB
Python

"""Разделы экспорта analytics: итоги, сравнение, отчёты."""
from __future__ import annotations
VALID_EXPORT_SECTIONS = frozenset({"summary", "comparison", "reports"})
_SECTION_FILENAMES = {
"summary": "itogi",
"comparison": "sravnenie",
"reports": "podrobno",
}
def parse_export_sections(section: str | None = None) -> frozenset[str]:
if not section or not str(section).strip() or str(section).strip().lower() == "all":
return VALID_EXPORT_SECTIONS
parts = {p.strip().lower() for p in str(section).split(",") if p.strip()}
filtered = parts & VALID_EXPORT_SECTIONS
return filtered if filtered else VALID_EXPORT_SECTIONS
def export_filename_base(*, date_from: str, date_to: str, sections: frozenset[str]) -> str:
if sections == VALID_EXPORT_SECTIONS:
return f"otchety_{date_from}_{date_to}"
if len(sections) == 1:
key = next(iter(sections))
return f"{_SECTION_FILENAMES[key]}_{date_from}_{date_to}"
joined = "_".join(sorted(_SECTION_FILENAMES[s] for s in sections))
return f"{joined}_{date_from}_{date_to}"