Changeset 81854
- Timestamp:
- 08/05/11 22:24:53 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb
r80511 r81854 1 1 class OsStatisticsController < ApplicationController 2 2 3 def hash_to_google_json(hash, columns) 4 json = Hash.new 5 6 json['cols'] = columns 7 8 # Create rows array 9 rows = [] 10 hash.each do |key, frequency| 11 row = Hash.new 12 row['c'] = [{'v' => key}, {'v' => frequency}] 13 rows << row 14 end 15 16 json['rows'] = rows 17 18 return json.to_json.to_s 19 end 20 21 def to_json(frequencies) 22 first_col = {'id' => 'name', 'label' => 'name', 'type' => 'string'} 23 second_col = {'id' => 'frequency', 'label' => 'Frequency', 'type' => 'number'} 24 25 cols = [first_col, second_col] 26 27 json = Hash.new 28 frequencies.each do |name, hash| 29 json[name] = hash_to_google_json(frequencies[name], cols) 30 end 31 32 return json 33 end 34 3 35 def gather_frequencies(stats) 4 @macports_version = Hash.new(0)5 @osx_version = Hash.new(0)6 @os_arch = Hash.new(0)7 @os_platform = Hash.new(0)8 @build_arch = Hash.new(0)9 @gcc_version = Hash.new(0)10 @xcode_version = Hash.new(0)36 macports_version = Hash.new(0) 37 osx_version = Hash.new(0) 38 os_arch = Hash.new(0) 39 os_platform = Hash.new(0) 40 build_arch = Hash.new(0) 41 gcc_version = Hash.new(0) 42 xcode_version = Hash.new(0) 11 43 12 44 stats.each do |row| 13 45 key = row.macports_version.to_sym 14 @macports_version[key] = @macports_version[key] + 146 macports_version[key] = macports_version[key] + 1 15 47 16 48 key = row.osx_version.to_sym 17 @osx_version[key] = @osx_version[key] + 149 osx_version[key] = osx_version[key] + 1 18 50 19 51 key = row.os_arch.to_sym 20 @os_arch[key] = @os_arch[key] + 152 os_arch[key] = os_arch[key] + 1 21 53 22 54 key = row.os_platform.to_sym 23 @os_platform[key] = @os_platform[key] + 155 os_platform[key] = os_platform[key] + 1 24 56 25 57 key = row.build_arch.to_sym 26 @build_arch[key] = @build_arch[key] + 158 build_arch[key] = build_arch[key] + 1 27 59 28 60 key = row.gcc_version.to_sym 29 @gcc_version[key] = @gcc_version[key] + 161 gcc_version[key] = gcc_version[key] + 1 30 62 31 63 key = row.xcode_version.to_sym 32 @xcode_version[key] = @xcode_version[key] + 164 xcode_version[key] = xcode_version[key] + 1 33 65 end 34 66 67 frequencies = Hash.new 68 frequencies['macports_version'] = macports_version 69 frequencies['osx_version'] = osx_version 70 frequencies['os_arch'] = os_arch 71 frequencies['os_platform'] = os_platform 72 frequencies['build_arch'] = build_arch 73 frequencies['gcc_version'] = gcc_version 74 frequencies['xcode_version'] = xcode_version 75 76 return frequencies 35 77 end 36 78 … … 38 80 @stats = OsStatistic.all 39 81 40 gather_frequencies(@stats) 82 frequencies = gather_frequencies @stats 83 @chartjson = to_json frequencies 41 84 42 85 respond_to do |format|
Note: See TracChangeset
for help on using the changeset viewer.

