Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 3.60 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. 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\"} "
  2. #File.open("data.txt", "w") {|f| f.write(file)}
  3. start = Time.now
  4. #strip out pre/post whitespace
  5. file = file.strip
  6. #split the data into lines
  7. raw_data = file[1..-2].split("} {") #lines is an array.
  8. File.open("raw_data.txt", "w") {|f| f.write(raw_data)}
  9. data = [] #lets make an array of all the data.
  10. for line in raw_data[0..4]
  11.   #the fields in each line are wrapped in "..." so pluck them out.
  12.   #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.
  13.   #in this case we want the 2nd (1 in 0-ordinal) to 2nd last characters.
  14.   real_line = line[1..-2]
  15.   puts "#{real_line}"
  16.   #now our line has '" "' as a seperator.. split on it
  17.   values = real_line.split('" "') #i could have used "\" \"" to use escaped double quotes inside a double quoted string.....
  18.  
  19.   suite = "#{values[1].split[0]} #{values[1].split[1]} #{values[1].split[2]}"
  20.   ic = "#{values[1].split[3]}"
  21.  
  22.   #lets make a hash of the line for quick reference
  23.   h = {:build => values[0], :suite => suite, :ic => ic, :date => Time.at(values[2].to_i), :platform => values[3], :result => values[4]}
  24.  
  25.   #lets add this hash to the array
  26.   data << h
  27. end
  28. puts "parsed #{data.size} rows in #{Time.now - start}s\n\n"
  29. #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
  30. #END PARSING.
  31.  
  32. # Goal is to create a list where each row is a unique build/platform pair, and each column is a build,
  33. #  the contents of the cell are the results, appended in order, of the test run.
  34. #puts "build, platforms sorted data first: #{platform_data[0..5].inspect}\n\n"
  35. data_hash = {}
  36. for line in data.sort_by{|data_hash| [data_hash[:date]]}
  37. #for line in data.sort_by{|a,b| a[:date] <=> b[:date]}
  38.   res = line[:result][0..0]
  39.  
  40.   suit = line[:suite]
  41.   ic = line[:ic]
  42.   plat = line[:platform]
  43.   bld = line[:build]
  44.  
  45.   data_hash[suit] ||= {}
  46.   data_hash[suit][ic] ||= {}
  47.   data_hash[suit][ic][plat] ||= {}
  48.  
  49.   data_hash[suit][ic][plat][:all_builds] = "#{data_hash[suit][ic][plat][:all_builds]}#{res}"
  50.   data_hash[suit][ic][:all_plat] = "#{data_hash[suit][ic][:all_plat]}#{res}"
  51.   data_hash[suit][:all_ic] = "#{data_hash[suit][:all_ic]}#{res}"
  52.   data_hash[suit][ic][plat][bld] = "#{data_hash[suit][ic][plat][bld]}#{res}"
  53. end
  54.  
  55. #number_ICs_All_Pass = 0
  56. #number_ICs_All_Fail = 0
  57. for k in data_hash.keys
  58.   #puts "#{data_hash[k].inspect}"
  59.   #puts "#{k} :: Total Results: #{data_hash[k][:all_ic].size} :: Results: #{data_hash[k][:all_ic]}" if data_hash[k][:all_ic] != nil
  60.   if data_hash[k][:all_ic] == nil
  61.     puts "#{k} :: #{data_hash[k]}"
  62.   end
  63.   #number_ICs_All_Pass++ if data_hash[k][:all_ic] =~ /^[P]+$/
  64.   #number_ICs_All_Fail++ if data_hash[k][:all_ic] =~ /^[F]+$/
  65.  
  66. #  ic_array = data_hash[k].keys - [:all_ic]
  67.  # for l in ic_array.sort{|x,y| x.to_s <=> y.to_s}
  68.  #   puts ("\t%-30s :: %s" % [l, data_hash[k][l][:all_plat]])
  69.     #if data_hash[k][l][:all_plat].match('/^[P]+$/')
  70.     #  puts ("\t%-30s :: %s" % [l, data_hash[k][l][:all_plat]])
  71.     #end
  72.  # end
  73. end
  74.  
  75. #puts "Results Summary:\n--------------"
  76. #puts ("-30s :: %s" % ["Number of ICs with All Pass:", number_ICs_All_Pass])
  77. #puts ("-30s :: %s" % ["Number of ICs with All Fail:", number_ICs_All_Fail])
  78.  
  79.  
  80. #puts data_hash.keys.map{|k| "#{k} => #{data_hash[k].inspect}"}.join("\n")