-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small hack script to count repeating events
- Loading branch information
1 parent
1c34031
commit 4fc189f
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |