Skip to content

Commit

Permalink
Small hack script to count repeating events
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankocienski committed Sep 7, 2024
1 parent 1c34031 commit 4fc189f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions hacks/event-repeat-counting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'json'

module Hack
extend self

def main
path = File.expand_path(File.join(File.dirname(__FILE__), '../db/fixtures/events.json'))
puts "Loading events from #{path}"
data = JSON.parse(File.open(path).read)
events = data['data']['eventsByFilter']
puts " Loaded #{events.count} events"

events_by_name = {}
events.each do |event|
name = event['name']
events_by_name[name] = (events_by_name[name] || 0) + 1
end

repeating = events_by_name.reduce(0) { |result, (name, count)| result + (count > 1 ? count : 0) }

puts "found #{repeating} repeating events"

end
end

Hack.main

0 comments on commit 4fc189f

Please sign in to comment.