Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add already_seen flag to classification_events #80

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/stream_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ def self.session_time(event_data)
diff = SESSION_CAP if diff > SESSION_LIMIT
diff
end

def self.already_seen(event_data)
event_data.fetch('metadata')&.fetch('subject_selection_state', nil)&.fetch('already_seen', nil)
end
end
3 changes: 2 additions & 1 deletion app/models/stream_events/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def process
workflow_id: @links.fetch('workflow'),
user_id: @links&.fetch('user', nil),
user_group_ids: @data.fetch('metadata')&.fetch('user_group_ids', []),
session_time: StreamEvents.session_time(@data)
session_time: StreamEvents.session_time(@data),
already_seen: StreamEvents.already_seen(@data)
}
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAlreadySeenToClassificationEvents < ActiveRecord::Migration[7.0]
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
def change
add_column :classification_events, :already_seen, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_09_26_233924) do
ActiveRecord::Schema[7.0].define(version: 2024_11_27_220919) do
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "timescaledb"
Expand All @@ -28,6 +28,7 @@
t.float "session_time"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "already_seen"
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
t.index ["event_time"], name: "classification_events_event_time_idx", order: :desc
t.index ["user_id"], name: "index_classification_events_on_user_id"
end
Expand Down
3,442 changes: 151 additions & 3,291 deletions spec/fixtures/example_kinesis_classification_payload.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spec/models/stream_events/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
expect(prepared_payload[:user_id]).to eq(links.fetch('user'))
expect(prepared_payload[:user_group_ids]).to eq(data.fetch('metadata').fetch('user_group_ids'))
expect(prepared_payload[:session_time]).to eq(StreamEvents.session_time(data))
expect(prepared_payload[:already_seen]).to eq(StreamEvents.already_seen(data))
end

it 'sets the user_id to nil if no user in stream payload' do
Expand Down
17 changes: 17 additions & 0 deletions spec/models/stream_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@
expect(StreamEvents.session_time(event_data)).to be_zero
end
end

context 'already_seen' do
it 'returns already_seen from payload if provided' do
expected_already_seen = event_metadata['subject_selection_state']['already_seen']
expect(StreamEvents.already_seen(event_data)).to eq(expected_already_seen)
end

it 'returns nil if subject_selection_state is not provided' do
event_metadata.delete('subject_selection_state')
expect(StreamEvents.already_seen(event_data)).to eq(nil)
end

it 'returns nil if subject_selection_state does not have already_seen' do
event_metadata['subject_selection_state'] = {}
expect(StreamEvents.already_seen(event_data)).to eq(nil)
end
end
end

describe 'unknown event' do
Expand Down