Changeset 82155
- Timestamp:
- 08/08/11 20:03:21 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-statistics/stats-server/app/controllers/os_statistics_controller.rb
r81854 r82155 1 class OsStatisticsController < ApplicationController1 class OsStatisticsController < ChartController 2 2 3 def hash_to_google_json(hash, columns) 4 json = Hash.new 3 # Populate charts with data 4 def populate(chart_name, chart) 5 # This is the column's label 6 chart.string "Item" 5 7 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 8 # This is the numerical value associated with the label 9 chart.number "Frequency" 10 11 # Add rows of data 12 dataset = chart_dataset chart_name 13 dataset.each do |item, count| 14 chart.add_row([item, count]) 14 15 end 15 16 json['rows'] = rows17 18 return json.to_json.to_s19 16 end 20 17 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 18 # Gather all needed data from the model 35 19 def gather_frequencies(stats) 36 20 macports_version = Hash.new(0) … … 42 26 xcode_version = Hash.new(0) 43 27 28 # For each column in OsStatistics count the number of unique entries 44 29 stats.each do |row| 45 30 key = row.macports_version.to_sym … … 65 50 end 66 51 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 52 populate = method(:populate) 75 53 76 return frequencies 54 add_chart :macports_version, macports_version, populate 55 add_chart :osx_version, osx_version, populate 56 add_chart :os_arch, os_arch, populate 57 add_chart :os_platform, os_platform, populate 58 add_chart :build_arch, build_arch, populate 59 add_chart :macports_version, macports_version, populate 60 add_chart :gcc_version, gcc_version, populate 61 add_chart :xcode_version, xcode_version, populate 77 62 end 78 63 79 64 def index 80 65 @stats = OsStatistic.all 81 82 frequencies = gather_frequencies @stats 83 @chartjson = to_json frequencies 66 @charts = Hash.new 67 gather_frequencies @stats 84 68 85 69 respond_to do |format|
Note: See TracChangeset
for help on using the changeset viewer.

