PyLimeRPC 0.2.0 — prompts.md Prompt 1-4
- responses.py: get_summary() (raw RPC get_summary), count_responses() -> frozen ResponseCounts(completed, incomplete, total), export_responses_auto() with automatic format fallback (xlsx -> xls -> csv) on IWriter errors - utils.py: summary_counts_full() -> (completed, incomplete, total) with per-LS-version key fallbacks; summary_counts left untouched - surveys.py: get_survey_by_sid() (dict | None), get_survey_info() -> frozen SurveyInfo(sid, title, active) - tokens.py: documented that extra/custom token attributes (attribute_1, ...) pass through unchanged in add_participants/list_participants - LsClient: get_summary, count_responses, get_survey_by_sid, get_survey_info, export_responses_auto; __all__ + re-exports updated - README: new "Response counts & summary" section + usage examples - .gitignore: prompts.md added (local-only docs, like werkdocument.md) - version 0.1.0 -> 0.2.0 (__init__.py + pyproject.toml) - tests: +27 FakeRpc unit tests (96 passed, 2 deselected) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
d7d9dc61bf
commit
6822eab467
1 changed files with 633 additions and 24 deletions
|
|
@ -3,6 +3,7 @@
|
|||
- ``to_int`` / ``is_active_flag`` / ``is_filled`` — safe parsing of LS values
|
||||
- ``parse_responses_json`` / ``decode_export_json`` — decode a JSON responses export
|
||||
- ``summary_counts`` — completed/total counts from a get_summary result
|
||||
- ``summary_counts_full`` — (completed, incomplete, total) from a get_summary result
|
||||
- ``raise_for_status`` — LimeSurvey sometimes puts ``{"status": "..."}`` in the
|
||||
*result* (instead of ``error``); this detects that and raises an
|
||||
``LsApiError`` (or ``LsAuthError`` for session/auth texts).
|
||||
|
|
@ -100,6 +101,31 @@ def summary_counts(summary: dict[str, Any]) -> tuple[int | None, int | None]:
|
|||
return completed, total
|
||||
|
||||
|
||||
def _summary_int(summary: dict[str, Any], keys: tuple[str, ...]) -> int:
|
||||
"""First present key of ``keys`` as int; missing/invalid → 0."""
|
||||
for key in keys:
|
||||
if key in summary:
|
||||
value = to_int(summary[key])
|
||||
return value if value is not None else 0
|
||||
return 0
|
||||
|
||||
|
||||
def summary_counts_full(summary: dict[str, Any]) -> tuple[int, int, int]:
|
||||
"""Extract (completed, incomplete, total) from a ``get_summary`` result.
|
||||
|
||||
Key names differ per LS version; the first present key wins:
|
||||
``completed_responses`` (fallback ``responses_completed`` / ``completed``) and
|
||||
``incomplete_responses`` (fallback ``in_progress_responses``). ``total`` is
|
||||
``full_responses`` when present, else ``completed + incomplete``.
|
||||
Missing or invalid values count as 0.
|
||||
"""
|
||||
completed = _summary_int(summary, ("completed_responses", "responses_completed", "completed"))
|
||||
incomplete = _summary_int(summary, ("incomplete_responses", "in_progress_responses"))
|
||||
full = to_int(summary["full_responses"]) if "full_responses" in summary else None
|
||||
total = full if full is not None else completed + incomplete
|
||||
return completed, incomplete, total
|
||||
|
||||
|
||||
def is_status_error(result: Any) -> bool:
|
||||
"""True if ``result`` is an LS error dict: ``{"status": "..."}`` or
|
||||
``{"status": "...", "error_code": "..."}``.
|
||||
|
|
|
|||
Loading…
Reference in a new issue