Skip to content

Commit

Permalink
Merge pull request #23 from alphagov/save-to-bq
Browse files Browse the repository at this point in the history
Submit feedback to BigQuery
  • Loading branch information
csutter authored Nov 26, 2023
2 parents cad1734 + fd01762 commit 1ae1939
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ def result_ratings_attributes=(attributes)
def save
return false unless valid?

# TODO: Implement me!
Rails.logger.info "Feedback submitted: #{inspect}"
true
dataset = Google::Cloud::Bigquery.new.dataset(Rails.configuration.bigquery_dataset)
table = dataset.table(Rails.configuration.bigquery_table)

data = to_bigquery_row
table.insert(data)
Rails.logger.info "Feedback submitted: #{data.inspect}"
end

def to_bigquery_row
{
query_id: SecureRandom.uuid,
anonymised_user_id: "not-yet-available",
timestamp: Time.zone.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"),
search_query:,
result_ratings: result_ratings.map(&:to_bigquery_data),
suggested_url:,
comments:,
}
end
end
17 changes: 17 additions & 0 deletions app/models/result_rating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ def self.rating_options
end

def id = content_id

def to_bigquery_data
{
content_id:,
url:,
position: position + 1, # have it 1-indexed in BigQuery
rating:,
}
end

def url
if link.start_with?("/")
Plek.new.website_root + link
else
link
end
end
end

0 comments on commit 1ae1939

Please sign in to comment.