- file = "{\"5.51.1501\" \"BSDPLATFORM end_to_end snmp ic_entity\" \"1281327622\" \"sv6-spb2\" \"NORESULT\"} {\"5.51.1501\" \"BSDPLATFORM end_to_end snmp ic_entity\" \"1281333653\" \"8210-spb2\" \"FAIL\"} {\"5.51.1501\" \"BSDPLATFORM end_to_end snmp ic_storage\" \"1281333665\" \"8210-spb2\" \"PASS\"} "
- #File.open("data.txt", "w") {|f| f.write(file)}
- start = Time.now
- #strip out pre/post whitespace
- file = file.strip
- #split the data into lines
- raw_data = file[1..-2].split("} {") #lines is an array.
- File.open("raw_data.txt", "w") {|f| f.write(raw_data)}
- data = [] #lets make an array of all the data.
- for line in raw_data[0..4]
- #the fields in each line are wrapped in "..." so pluck them out.
- #get rid of the " at the beginnig and end of the line. similar to the 1...-1 on line 7 we can do the same for strings.
- #in this case we want the 2nd (1 in 0-ordinal) to 2nd last characters.
- real_line = line[1..-2]
- puts "#{real_line}"
- #now our line has '" "' as a seperator.. split on it
- values = real_line.split('" "') #i could have used "\" \"" to use escaped double quotes inside a double quoted string.....
- suite = "#{values[1].split[0]} #{values[1].split[1]} #{values[1].split[2]}"
- ic = "#{values[1].split[3]}"
- #lets make a hash of the line for quick reference
- h = {:build => values[0], :suite => suite, :ic => ic, :date => Time.at(values[2].to_i), :platform => values[3], :result => values[4]}
- #lets add this hash to the array
- data << h
- end
- puts "parsed #{data.size} rows in #{Time.now - start}s\n\n"
- #puts "here is what each row of data looks like: #{data[0].inspect}\n\n" #inspect takes an object and gives it a nice string representation
- #END PARSING.
- # Goal is to create a list where each row is a unique build/platform pair, and each column is a build,
- # the contents of the cell are the results, appended in order, of the test run.
- #puts "build, platforms sorted data first: #{platform_data[0..5].inspect}\n\n"
- data_hash = {}
- for line in data.sort_by{|data_hash| [data_hash[:date]]}
- #for line in data.sort_by{|a,b| a[:date] <=> b[:date]}
- res = line[:result][0..0]
- suit = line[:suite]
- ic = line[:ic]
- plat = line[:platform]
- bld = line[:build]
- data_hash[suit] ||= {}
- data_hash[suit][ic] ||= {}
- data_hash[suit][ic][plat] ||= {}
- data_hash[suit][ic][plat][:all_builds] = "#{data_hash[suit][ic][plat][:all_builds]}#{res}"
- data_hash[suit][ic][:all_plat] = "#{data_hash[suit][ic][:all_plat]}#{res}"
- data_hash[suit][:all_ic] = "#{data_hash[suit][:all_ic]}#{res}"
- data_hash[suit][ic][plat][bld] = "#{data_hash[suit][ic][plat][bld]}#{res}"
- end
- #number_ICs_All_Pass = 0
- #number_ICs_All_Fail = 0
- for k in data_hash.keys
- #puts "#{data_hash[k].inspect}"
- #puts "#{k} :: Total Results: #{data_hash[k][:all_ic].size} :: Results: #{data_hash[k][:all_ic]}" if data_hash[k][:all_ic] != nil
- if data_hash[k][:all_ic] == nil
- puts "#{k} :: #{data_hash[k]}"
- end
- #number_ICs_All_Pass++ if data_hash[k][:all_ic] =~ /^[P]+$/
- #number_ICs_All_Fail++ if data_hash[k][:all_ic] =~ /^[F]+$/
- # ic_array = data_hash[k].keys - [:all_ic]
- # for l in ic_array.sort{|x,y| x.to_s <=> y.to_s}
- # puts ("\t%-30s :: %s" % [l, data_hash[k][l][:all_plat]])
- #if data_hash[k][l][:all_plat].match('/^[P]+$/')
- # puts ("\t%-30s :: %s" % [l, data_hash[k][l][:all_plat]])
- #end
- # end
- end
- #puts "Results Summary:\n--------------"
- #puts ("-30s :: %s" % ["Number of ICs with All Pass:", number_ICs_All_Pass])
- #puts ("-30s :: %s" % ["Number of ICs with All Fail:", number_ICs_All_Fail])
- #puts data_hash.keys.map{|k| "#{k} => #{data_hash[k].inspect}"}.join("\n")