Skip to content

Commit 03c49ef

Browse files
xrendanclaude
andcommitted
Add missing CommitmentDriftSummarizer model, dashboard summary stats, and feed pagination
CommitmentDriftSummarizer was referenced by SourceDocumentProcessorJob but never committed, causing NameError in production. Also adds commitment status summary counts to the dashboard API and total_count to feed items pagination metadata. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6c11bd9 commit 03c49ef

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

app/controllers/api/dashboard_controller.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,25 @@ def at_a_glance
4545
}
4646
end
4747

48+
all_commitments = government.commitments
49+
total = all_commitments.count
50+
status_counts = all_commitments.group(:status).count
51+
52+
not_started = status_counts.fetch("not_started", 0)
53+
implemented = status_counts.fetch("implemented", 0)
54+
in_progress = status_counts.fetch("in_progress", 0) +
55+
status_counts.fetch("partially_implemented", 0)
56+
successful = all_commitments.joins(:success_criteria).merge(Criterion.where(status: :met)).distinct.count
57+
4858
render json: {
4959
government: { id: government.id, name: government.name },
50-
total_commitments: government.commitments.count,
60+
total_commitments: total,
61+
summary: {
62+
not_started: { count: not_started, label: "Not Started", subtitle: "no action taken" },
63+
completed: { count: implemented, label: "Completed", subtitle: "of #{total} commitments" },
64+
successful: { count: successful, label: "Successful", subtitle: "meeting success criteria" }
65+
},
66+
status_counts: status_counts,
5167
policy_areas: data
5268
}
5369
end

app/controllers/feed_items_controller.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ class FeedItemsController < ApplicationController
22
def index
33
scope = params[:commitment_id] ? FeedItem.where(commitment_id: params[:commitment_id]) : FeedItem.all
44

5-
@feed_items = scope
5+
@filtered = scope
66
.newest_first
77
.by_event_type(params[:event_type])
88
.by_policy_area(params[:policy_area_id])
99
.since(params[:since])
1010
.until_date(params[:until])
1111
.includes(:commitment, :policy_area)
1212

13-
@feed_items = @feed_items.limit(page_size).offset(page_offset)
13+
@total_count = @filtered.count
14+
@feed_items = @filtered.limit(page_size).offset(page_offset)
1415

1516
respond_to do |format|
1617
format.json { render json: feed_items_json }
@@ -20,18 +21,22 @@ def index
2021

2122
private
2223

24+
def current_page
25+
[(params[:page] || 1).to_i, 1].max
26+
end
27+
2328
def page_size
2429
[(params[:per_page] || 50).to_i, 100].min
2530
end
2631

2732
def page_offset
28-
[(params[:page] || 1).to_i - 1, 0].max * page_size
33+
(current_page - 1) * page_size
2934
end
3035

3136
def feed_items_json
3237
{
3338
feed_items: @feed_items.map { |fi| serialize_feed_item(fi) },
34-
meta: { page: (params[:page] || 1).to_i, per_page: page_size }
39+
meta: { page: current_page, per_page: page_size, total_count: @total_count }
3540
}
3641
end
3742

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class CommitmentDriftSummarizer < Chat
2+
include Structify::Model
3+
4+
MODEL = "gemini-3.1-flash-lite-preview"
5+
6+
after_create { with_model(MODEL, provider: :gemini, assume_exists: true) }
7+
8+
schema_definition do
9+
version 1
10+
name "CommitmentDriftSummarizer"
11+
field :change_summary, :string,
12+
description: "A 1-3 sentence human-readable summary of what changed and why it matters"
13+
end
14+
15+
def system_prompt
16+
"You are a government policy analyst summarizing changes to official commitments. " \
17+
"Be concise and factual. Focus on what changed and its significance."
18+
end
19+
20+
def prompt(old_values, new_values)
21+
<<~PROMPT
22+
A government commitment has been updated in a new source document.
23+
Summarize what changed and why it matters in 1-3 sentences.
24+
25+
PREVIOUS VERSION:
26+
Title: #{old_values[:title]}
27+
Description: #{old_values[:description]}
28+
Original text: #{old_values[:original_text]}
29+
30+
NEW VERSION:
31+
Title: #{new_values[:title]}
32+
Description: #{new_values[:description]}
33+
Original text: #{new_values[:original_text]}
34+
PROMPT
35+
end
36+
end

0 commit comments

Comments
 (0)