iachat/enterprise/app/models/captain
Rodribm10 f6488ce2de feat(retention): foundation for customer retention metrics
Lays the data + job foundation for tracking customer interactions,
recurrence, and Pix conversion on Contact. Design decisions negotiated
with Rodrigo (see docs to come):

Rules:
- Gap of 30h from last message defines separate interactions
- Qualified interaction = >=2 customer msgs + >=2 attendant msgs,
  both with textual content (>= 2 letters)
- One-shot consultation = >=1+1 but below the qualified threshold
  (tracked as secondary KPI)
- Excludes contacts labeled `equipe_interna`
- is_recurring = interactions_count >= 2
- pix_generated_count counts all PixCharges; reservations_paid_count
  only counts those with status = paid

Surface area:
- Migration adds denormalized stats to contacts + indexes for fast filtering
- Captain::ContactStats::InteractionCalculatorService computes the stats
  for a single contact (pure, no persistence)
- Captain::Retention::RecalculateContactStatsJob persists them for one
  contact (idempotent)
- Captain::Retention::RecalculateAllContactStatsJob runs daily at 3am BRT,
  enqueues per-contact jobs for everyone active in the last 120 days
- Event-driven refresh: CaptainListener#conversation_resolved enqueues
  recalc; Captain::PixCharge after_create/after_update enqueues recalc
  on status change

No UI yet — that's the next layer.
2026-04-22 09:50:23 -03:00
..
lifecycle feat(captain): semantic memory fixes + roleta + reclamações + analytics 2026-04-21 15:36:25 -03:00
assistant_response.rb feat: legacy features to ruby llm (#12994) 2025-12-11 14:17:28 +05:30
assistant.rb feat(captain): semantic memory fixes + roleta + reclamações + analytics 2026-04-21 15:36:25 -03:00
brand.rb chore(style): fix rubocop offenses and update typing indicators 2026-02-25 15:06:58 -03:00
contact_memory.rb feat(captain): semantic memory fixes + roleta + reclamações + analytics 2026-04-21 15:36:25 -03:00
conversation_insight.rb feat: Adiciona prompt orquestrador configurável para assistentes Captain com editor UI. 2026-02-27 11:57:59 -03:00
custom_tool.rb chore(style): fix rubocop offenses and update typing indicators 2026-02-25 15:06:58 -03:00
document.rb chore(style): fix rubocop offenses and update typing indicators 2026-02-25 15:06:58 -03:00
gallery_item.rb feat(units): allow one Pix unit to link to multiple inboxes (N:N) 2026-02-26 21:33:23 -03:00
lifecycle.rb feat(lifecycle): add Captain::Lifecycle::Config model 2026-04-15 01:14:19 -03:00
notification_template.rb refactor: move notification templates de units para inboxes 2026-03-01 22:17:27 -03:00
pix_charge.rb feat(retention): foundation for customer retention metrics 2026-04-22 09:50:23 -03:00
report_snapshot.rb feat(captain): improve suite photo search accuracy with AI guidance 2026-02-26 23:04:28 -03:00
reservation.rb feat(lifecycle): wire Captain::Reservation lifecycle hooks 2026-04-15 01:37:23 -03:00
scenario.rb feat(captain): hierarchical model routing + conversation-level memory cache 2026-04-19 09:47:15 -03:00
unit_inbox.rb feat(captain): improve suite photo search accuracy with AI guidance 2026-02-26 23:04:28 -03:00
unit.rb feat(lifecycle): add concierge_* accessors to Captain::Unit 2026-04-15 01:23:40 -03:00