Skip to content

Instantly share code, notes, and snippets.

@phyllisstein
Created August 3, 2022 12:36
Show Gist options
  • Save phyllisstein/104902168d8ad3c2c5768cc3d1eca351 to your computer and use it in GitHub Desktop.
Save phyllisstein/104902168d8ad3c2c5768cc3d1eca351 to your computer and use it in GitHub Desktop.
require 'active_support/all'
map_recircs = {}
map_venues = {}
average_recirc = 0
MapStack.all.each do |map|
next unless map.map_cards.present?
title = map.title.parameterize(separator: '_').to_sym
venues = map.map_cards.pluck(:venue_id)
.compact
.map { |venue_id| Geo::Venue.find(venue_id) }
.compact
.map { |venue| ContentService::Entries.tagged_with_hermano_record(venue).collection }
.flatten
map_recircs[title] = {
venues: venues,
totalMatches: venues.size,
}
end
map_stack_count = MapStack.count
total_recirc = map_recircs.values.map { |map| map[:totalMatches] }.sum
average_recirc = map_recircs.values.map { |map| map[:totalMatches] }.sum / map_recircs.size
fewer_than_three = map_recircs.values.select { |map| map[:totalMatches] < 3 }.size
zero_matches = map_recircs.values.select { |map| map[:totalMatches] == 0 }.size
average_creation_date = map_recircs.values.map { |map| map[:venues].map { |venue| venue[:created_on].to_i } }.flatten.sum / total_recirc
average_update_date = map_recircs.values.map { |map| map[:venues].map { |venue| venue[:updated_on].to_i } }.flatten.sum / total_recirc
average_published_date = map_recircs.values.map { |map| map[:venues].map { |venue| venue[:published_date].to_i } }.flatten.sum / total_recirc
entry_count = map_recircs.values.reduce(0) do |acc, map|
acc += map[:totalMatches]
end
recirc_stats = {
map_stacks_queried: map_stack_count,
total_matched_entries: entry_count,
average_matched_entries: average_recirc,
fewer_than_three_matched_entries: fewer_than_three,
average_venue_creation_date: Time.at(average_creation_date).strftime('%B %Y'),
average_venue_published_date: Time.at(average_published_date).strftime('%B %Y'),
average_venue_update_date: Time.at(average_update_date).strftime('%B %Y'),
zero_matched_entries: zero_matches,
match_details: map_recircs,
}
open('map_recirc_detail.json', 'w') do |f|
f.write(JSON.pretty_generate(recirc_stats))
end
open('map_recirc.json', 'w') do |f|
f.write(JSON.pretty_generate(recirc_stats.except(:match_details)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment