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
|
|
@ -5,11 +5,16 @@
|
|||
``group_id`` filters client-side on ``group_id``/``gsid`` when present)
|
||||
- ``get_survey_properties(client, session_key, sid, properties=None)`` —
|
||||
properties dict of a single survey
|
||||
- ``get_survey_by_sid(client, session_key, sid, owner_id=None, group_id=None)`` —
|
||||
one survey dict from ``list_surveys`` by sid, or ``None``
|
||||
- ``get_survey_info(client, session_key, sid)`` — compact ``SurveyInfo``
|
||||
(sid/title/active), or ``None`` when the survey does not exist
|
||||
- ``filter_active(surveys)`` — only active surveys (``active == "Y"``)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Iterable
|
||||
|
||||
from .errors import LsApiError
|
||||
|
|
@ -99,3 +104,71 @@ def get_survey_properties(
|
|||
def filter_active(surveys: Iterable[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""Filter a survey list to active surveys only (``active == "Y"``)."""
|
||||
return [s for s in surveys if is_active_flag(s.get("active"))]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SurveyInfo:
|
||||
"""Compact info about a survey, built from a ``list_surveys`` entry.
|
||||
|
||||
Fields: ``sid``, ``title`` (``surveyls_title``) and ``active``.
|
||||
"""
|
||||
|
||||
sid: int
|
||||
title: str
|
||||
active: bool
|
||||
|
||||
|
||||
def get_survey_by_sid(
|
||||
client: RpcClient,
|
||||
session_key: str,
|
||||
sid: int | str,
|
||||
owner_id: int | str | None = None,
|
||||
group_id: int | str | None = None,
|
||||
) -> dict[str, Any] | None:
|
||||
"""Find one survey by sid in the ``list_surveys`` result.
|
||||
|
||||
Args:
|
||||
client: an ``RpcClient``.
|
||||
session_key: a valid session key.
|
||||
sid: survey ID to look for (matched as ``str(sid)`` against each entry).
|
||||
owner_id: optional, passed through to ``list_surveys``.
|
||||
group_id: optional, passed through to ``list_surveys``.
|
||||
|
||||
Returns:
|
||||
The survey dict, or ``None`` when no survey with this sid exists —
|
||||
"does not exist" is NOT an exception.
|
||||
|
||||
Raises:
|
||||
LsAuthError / LsApiError: propagated from ``list_surveys`` (e.g. a
|
||||
``{"status": ...}`` result is raised via ``raise_for_status``).
|
||||
"""
|
||||
surveys = list_surveys(client, session_key, owner_id=owner_id, group_id=group_id)
|
||||
for survey in surveys:
|
||||
if str(survey.get("sid")) == str(sid):
|
||||
return survey
|
||||
return None
|
||||
|
||||
|
||||
def get_survey_info(client: RpcClient, session_key: str, sid: int | str) -> SurveyInfo | None:
|
||||
"""Compact info (sid / title / active) of a survey.
|
||||
|
||||
Built from ``get_survey_by_sid``; handy for apps that want "does not exist /
|
||||
not active / title" in a single call.
|
||||
|
||||
Returns:
|
||||
``SurveyInfo(sid, title, active)``, or ``None`` when the survey does not exist.
|
||||
"""
|
||||
survey = get_survey_by_sid(client, session_key, sid)
|
||||
if survey is None:
|
||||
return None
|
||||
sid_int = to_int(survey.get("sid"))
|
||||
if sid_int is None:
|
||||
sid_int = to_int(sid) or 0
|
||||
title = survey.get("surveyls_title")
|
||||
if title is None:
|
||||
title = survey.get("title")
|
||||
return SurveyInfo(
|
||||
sid=sid_int,
|
||||
title=str(title) if title is not None else "",
|
||||
active=is_active_flag(survey.get("active")),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue