Last active
August 29, 2015 14:06
-
-
Save geapi/a33118788c72279b3164 to your computer and use it in GitHub Desktop.
manage workshop participant csv for Rocky Mountain Ruby
This file contains hidden or 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
require 'csv' | |
class FindOverlap | |
def initialize(file_name) | |
@file_name = file_name | |
end | |
def run | |
read_file | |
set_groups | |
compare_morning | |
compare_afternoon | |
check_railsbridge | |
get_counts | |
compare_all_against_all_day | |
end | |
def read_file | |
@csv = CSV.read(@file_name, {:headers => true}) | |
end | |
def get_counts | |
@workshops = {} | |
@morning.each do |ws| | |
@workshops[ws]=[] | |
@csv.each do |row| | |
if row['ticket_offer'] == ws | |
@workshops[ws] << row | |
end | |
end | |
end | |
@afternoon.each do |ws| | |
@workshops[ws]=[] | |
@csv.each do |row| | |
if row['ticket_offer'] == ws | |
@workshops[ws] << row | |
end | |
end | |
end | |
@workshops.each do |workshop_title, participants| | |
puts "~" * 30 | |
puts workshop_title | |
puts "participant count: #{participants.size}" | |
generate_participant_csv(workshop_title, participants) | |
end | |
end | |
def compare_morning | |
@morning_people =[] | |
@csv.each do |row| | |
if @morning.include?(row['ticket_offer']) && row['cancelled'].nil? | |
@morning_people << row["first_name"].downcase + " " + row['last_name'].downcase | |
end | |
end | |
puts "#" * 30 | |
overlap = @morning_people - @morning_people.uniq | |
puts "Registered for morning: #{@morning_people.size}" | |
puts "Double booked for morning: #{overlap.size}" | |
puts overlap unless overlap.empty? | |
puts "#" * 30 | |
end | |
def compare_afternoon | |
@afternoon_people =[] | |
@csv.each do |row| | |
if @afternoon.include?(row['ticket_offer']) && row['cancelled'].nil? | |
@afternoon_people << row["first_name"].downcase + " " + row['last_name'].downcase | |
end | |
end | |
puts "#" * 30 | |
overlap = @afternoon_people - @afternoon_people.uniq | |
puts "Registered for afternoon: #{@afternoon_people.size}" | |
puts "Double booked for afternoon: #{overlap.size}" | |
puts overlap unless overlap.empty? | |
puts "#" * 30 | |
end | |
def compare_all_against_all_day | |
in_railsbridge_and_other_ws = [] | |
@railsbridge_people.each do |railsbdrige_person| | |
@morning_people.each do |morning_person| | |
if railsbdrige_person["first_name"].downcase + " " + railsbdrige_person['last_name'].downcase == morning_person | |
in_railsbridge_and_other_ws << morning_person | |
end | |
end | |
@afternoon_people.each do |afternoon_person| | |
if railsbdrige_person["first_name"].downcase + " " + railsbdrige_person['last_name'].downcase == afternoon_person | |
in_railsbridge_and_other_ws << afternoon_person | |
end | |
end | |
end | |
puts "doubledbooked with Railsbridge #{in_railsbridge_and_other_ws}" | |
end | |
def set_groups | |
@morning=[] | |
@afternoon=[] | |
@all_day=[] | |
titles = [] | |
@csv.each do |row| | |
titles << row['ticket_offer'] | |
end | |
titles.uniq!.compact! | |
titles.each do |title| | |
puts title.downcase | |
["ruby", "ember", "roll your own"].each do |partial_title| | |
if title.downcase.include?(partial_title) | |
@morning << title | |
end | |
end | |
["agile", "angular", "soa"].each do |partial_title| | |
if title.downcase.include?(partial_title) | |
@afternoon << title | |
end | |
end | |
end | |
puts @morning | |
puts @afternoon | |
# @morning = ["Acceptance Testing In Ruby", "Building Web Apps with Ember.js", "Roll your own - how to build a business"] | |
# @afternoon = ["The Agile Engineer Manifesto", "Development in angular.js", "Adopting SOA from Day One"] | |
@all_day = ["RailsBridge"] | |
end | |
def check_railsbridge | |
@railsbridge_people =[] | |
@csv.each do |row| | |
if @all_day.include?(row['ticket_offer']) && row['cancelled'].nil? | |
@railsbridge_people << row | |
end | |
end | |
puts "#" * 30 | |
puts "Registered for railsbridge: #{@railsbridge_people.size}" | |
generate_participant_csv("railsbridge", @railsbridge_people, true) | |
puts "#" * 30 | |
end | |
def generate_participant_csv(file_name, participants, show_plus_one = false) | |
file = "#{file_name.downcase}.csv" | |
header = ["name", "email", "company", "job title", "twitter handle"] | |
header << "plus one" if show_plus_one | |
CSV.open(file, "w") do |csv| | |
csv << header | |
participants.each do |participant| | |
info = ["#{participant['first_name']} #{participant['last_name']}", participant['email'], participant['company'], participant['job_title'].to_s, participant['twitter_username'].to_s] | |
info << participant[21] if show_plus_one | |
csv << info | |
end | |
end | |
end | |
end | |
raise "missing file with csv" unless ARGV[0] | |
FindOverlap.new(ARGV[0]).run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment