qfa.services.coding_trends#
Deterministic, non-LLM coding-trend table.
Counts coding labels over time periods, assembled from feedback-record
metadata. Best-effort: when created is absent or unparseable the
table is omitted (None) and the reduce step degrades to text-only
synthesis. No LLM, no port — pure services logic.
The period granularity is configurable (day / week / month)
so a one-month corpus can still show meaningful trend buckets. week
uses ISO week numbering (YYYY-Www) so the ISO year — not the
calendar year — anchors the bucket, avoiding the silent off-by-one
where 2024-12-30 would otherwise collide with truly-January-2024
records.
Functions
|
Build a code-by-period count table from record metadata. |
|
Render the table as a compact text grid for the reduce prompt. |
- qfa.services.coding_trends.build_coding_trend_table(records: tuple[FeedbackRecordModel, ...], *, code_fields: Sequence[str], period: Literal['day', 'week', 'month'] = 'week') CodingTrendTable | None[source]#
Build a code-by-period count table from record metadata.
- Parameters:
records (tuple[FeedbackRecordModel, ...]) – The full input record set.
code_fields (Sequence[str]) – Metadata keys holding coding labels (comma-separated strings).
period (TrendPeriod) – Bucket granularity.
week(the default) is usually right;monthis better for multi-year corpora;dayfor short-window deep-dives.
- Returns:
The assembled table, or
Nonewhen no record carries a parseable date increated(best-effort omission).- Return type:
CodingTrendTable | None
- qfa.services.coding_trends.render_coding_trend_table(table: CodingTrendTable) str[source]#
Render the table as a compact text grid for the reduce prompt.
Rows are codes, columns are periods, cells are integer counts. This is the faithfulness anchor the synthesis prompt cites.