Changeset 80745
- Timestamp:
- 07/16/11 12:19:16 (4 years ago)
- Location:
- branches/gsoc11-statistics/stats-server/app
- Files:
-
- 2 edited
-
controllers/submissions_controller.rb (modified) (1 diff)
-
models/submission.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb
r80731 r80745 20 20 end 21 21 22 # Populate an OsStatistics row based on submitted JSON data23 def add_os_data(user, os)24 logger.debug "In add_os_data"25 26 if os.nil?27 return28 end29 30 macports_version = os['macports_version']31 osx_version = os['osx_version']32 os_arch = os['os_arch']33 os_platform = os['os_platform']34 build_arch = os['build_arch']35 gcc_version = os['gcc_version']36 xcode_version = os['xcode_version']37 38 # Try to find an existing entry39 os_stats = OsStatistic.find_by_user_id(user.id)40 41 if os_stats.nil?42 # No entry for this user - create a new one43 os_stats = OsStatistic.new()44 end45 46 os_stats[:user_id] = user.id47 os_stats[:macports_version] = macports_version48 os_stats[:osx_version] = osx_version49 os_stats[:os_arch] = os_arch50 os_stats[:os_platform] = os_platform51 os_stats[:build_arch] = build_arch52 os_stats[:gcc_version] = gcc_version53 os_stats[:xcode_version] = xcode_version54 55 if not os_stats.save56 logger.debug "Unable to save os_stats"57 logger.debug "Error message: #{os_stats.errors.full_messages}"58 end59 end60 61 def add_port(user_id, macports_port, installed_port, month, year)62 logger.debug {"Adding installed port #{installed_port['name']}"}63 64 portEntry = InstalledPort.new(:user_id => user_id,65 :port_id => macports_port.id,66 :version => installed_port['version'],67 :variants => installed_port['variants'],68 :month => month,69 :year => year)70 71 if not portEntry.save72 logger.debug "Unable to save port #{port['name']}"73 logger.debug "Error message: #{portEntry.errors.full_messages}"74 end75 end76 77 def add_installed_ports(uuid, installed_ports)78 logger.debug "In add_installed_ports"79 80 if installed_ports.nil?81 return82 end83 84 current_time = Time.now85 month = current_time.month86 year = current_time.year87 88 installed_ports.each do |installed_port|89 # Find the reported port in the MacPorts repository90 macports_port = Port.find_by_name(installed_port['name'])91 92 if macports_port.nil?93 logger.debug {"Skipping unknown port #{installed_port['name']} - Not in MacPorts repository"}94 next95 end96 97 # Update installed port information98 add_port(uuid, macports_port, installed_port, month, year)99 end100 end101 102 22 # POST /submissions 103 23 def create 104 24 @submission = Submission.new(params[:submission]) 105 json = ActiveSupport::JSON.decode(@submission.data)106 os = json['os']107 active_ports = json['active_ports']108 25 109 user = User.find_or_create_by_uuid(json['id']) 110 111 add_os_data(user, os) 112 add_installed_ports(json['id'], active_ports) 113 26 @submission.save_data 27 114 28 respond_to do |format| 115 29 format.html { redirect_to(@submission, :notice => 'Submission was successfully created.') } -
branches/gsoc11-statistics/stats-server/app/models/submission.rb
r80511 r80745 1 1 class Submission < ActiveRecord::Base 2 3 # Populate an OsStatistics row based on submitted JSON data 4 def add_os_data(user, os) 5 logger.debug "In add_os_data" 6 7 if os.nil? 8 return 9 end 10 11 macports_version = os['macports_version'] 12 osx_version = os['osx_version'] 13 os_arch = os['os_arch'] 14 os_platform = os['os_platform'] 15 build_arch = os['build_arch'] 16 gcc_version = os['gcc_version'] 17 xcode_version = os['xcode_version'] 18 19 # Try to find an existing entry 20 os_stats = OsStatistic.find_by_user_id(user.id) 21 22 if os_stats.nil? 23 # No entry for this user - create a new one 24 os_stats = OsStatistic.new() 25 end 26 27 os_stats[:user_id] = user.id 28 os_stats[:macports_version] = macports_version 29 os_stats[:osx_version] = osx_version 30 os_stats[:os_arch] = os_arch 31 os_stats[:os_platform] = os_platform 32 os_stats[:build_arch] = build_arch 33 os_stats[:gcc_version] = gcc_version 34 os_stats[:xcode_version] = xcode_version 35 36 if not os_stats.save 37 logger.debug "Unable to save os_stats" 38 logger.debug "Error message: #{os_stats.errors.full_messages}" 39 end 40 end 41 42 def add_port(user, macports_port, installed_port, month, year) 43 logger.debug {"Adding installed port #{installed_port['name']}"} 44 45 portEntry = InstalledPort.new(:user_id => user.id, 46 :port_id => macports_port.id, 47 :version => installed_port['version'], 48 :variants => installed_port['variants'], 49 :month => month, 50 :year => year) 51 52 if not portEntry.save 53 logger.debug "Unable to save port #{port['name']}" 54 logger.debug "Error message: #{portEntry.errors.full_messages}" 55 end 56 end 57 58 def add_installed_ports(uuid, installed_ports) 59 logger.debug "In add_installed_ports" 60 61 if installed_ports.nil? 62 return 63 end 64 65 current_time = Time.now 66 month = current_time.month 67 year = current_time.year 68 69 installed_ports.each do |installed_port| 70 # Find the reported port in the MacPorts repository 71 macports_port = Port.find_by_name(installed_port['name']) 72 73 if macports_port.nil? 74 logger.debug {"Skipping unknown port #{installed_port['name']} - Not in MacPorts repository"} 75 next 76 end 77 78 # Update installed port information 79 add_port(uuid, macports_port, installed_port, month, year) 80 end 81 end 82 83 def save_data 84 json = ActiveSupport::JSON.decode(data) 85 os = json['os'] 86 active_ports = json['active_ports'] 87 #inactive_ports = json['inactive_ports'] 88 89 user = User.find_or_create_by_uuid(json['id']) 90 91 add_os_data(user, os) 92 add_installed_ports(user, active_ports) 93 end 2 94 end
Note: See TracChangeset
for help on using the changeset viewer.

