Ruby CSV enumeration confusion -
how come not work? csv there , has values, , have 'require "csv" , time @ top, there. problem seems csv.each
doing anything.
it returns
=> [] common registration hour => [] common registration day (sunday being 0, mon => 1 ... sat => 7)
if there more info can provide, please let me know.
@x = csv.open \ 'event_attendees.csv', headers: true, header_converters: :symbol def time_target y = [] @x.each |line| if line[:regdate].to_s.length > 0 y << datetime.strptime(line[:regdate], "%m/%d/%y %h:%m").hour y = y.sort_by {|i| grep(i).length }.last end end puts "#{y} common registration hour" y = [] @x.each |line| if line[:regdate].to_s.length > 0 y << datetime.strptime(line[:regdate], "%m/%d/%y %h:%m").wday y = y.sort_by {|i| grep(i).length }.last end end puts "#{y} common registration day \ (sunday being 0, mon => 1 ... sat => 7)" end
making 'y's '@y's has not fixed it.
here sample csv i'm using:
,regdate,first_name,last_name,email_address,homephone,street,city,state,zipcode
1,11/12/08 10:47,allison,nguyen,arannon@jumpstartlab.com,6154385000,3155 19th st nw,washington,dc,20010
2,11/12/08 13:23,sarah,hankins,pinalevitsky@jumpstartlab.com,414-520-5000,2022 15th street nw,washington,dc,20009
3,11/12/08 13:30,sarah,xx,lqrm4462@jumpstartlab.com,(941)979-2000,4175 3rd street north,saint petersburg,fl,33703
try load data:
def database_load(arg='event_attendees.csv') @contents = csv.open(arg, headers: true, header_converters: :symbol) @people = [] @contents.each |row| person = {} person["id"] = row[0] person["regdate"] = row[:regdate] person["first_name"] = row[:first_name].downcase.capitalize person["last_name"] = row[:last_name].downcase.capitalize person["email_address"] = row[:email_address] person["homephone"] = phonenumber.new(row[:homephone].to_s) person["street"] = row[:street] person["city"] = city.new(row[:city]).clean person["state"] = row[:state] person["zipcode"] = zipcode.new(row[:zipcode]).clean @people << person end puts "loaded #{@people.count} records file: '#{arg}'..." end
Comments
Post a Comment