|
|
require 'date'
csv = File.readlines('/media/apps/hestia/lib/csv_flatfiles/ra.csv')
csv.collect!{|c| c.gsub!(/1,0((?:,0)*?)(,0)?(?=,1)/,'1,x\1,y')}
puts csv
csv.each do |row|
cols = row.split(',')
start = Date.parse(cols[1])
reservations = Hash.new
cols.each_with_index do |c,i|
case c
when 'x'
@i = i
@r = start + i-1
reservations[@r]
when 'y'
reservations[@r] = i - (@i-1)
end
end
puts reservations.to_a
end
csv = File.readlines('ra.csv')
csv.each do |row|
cols = row.split(',')
cott = cols[0].gsub(/\"/,'').gsub(/\s/,'')
start = Date.parse(cols[1])
reservations = Hash.new
cols.each_with_index do |c,i|
if c == '0' && cols[i-1] != '0'
@i = i-1
@r = start + i-1
reservations[@r]
elsif c == '0' && cols[i+1] != '0'
reservations[@r] = i - @i
end
end
# csv = "QWERTY ",20071027,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,
#1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,
#1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
#1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
#1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
#1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
#1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
#0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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