New Ticket     Tickets     Wiki     Browse Source     Timeline     Roadmap     Ticket Reports     Search

Changeset 80569


Ignore:
Timestamp:
07/14/11 23:13:50 (4 years ago)
Author:
derek@…
Message:
  • Add uuid to users table if it is not already there
  • use user_id rather than uuid when saving os_statistics
  • A user can have only one os_statistics entry for a given uuid. Attempt to find an existing entry and update that before creating a new one
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc11-statistics/stats-server/app/controllers/submissions_controller.rb

    r80511 r80569  
    2121 
    2222  # Populate an OsStatistics row based on submitted JSON data 
    23   def add_os_data(uuid, os) 
     23  def add_os_data(user, os) 
    2424    logger.debug "In add_os_data" 
    2525     
     
    3636    xcode_version    = os['xcode_version'] 
    3737    
    38     @os_stats = OsStatistic.new(:uuid => uuid, 
    39                             :macports_version => macports_version, 
    40                             :osx_version      => osx_version, 
    41                             :os_arch          => os_arch, 
    42                             :os_platform      => os_platform, 
    43                             :build_arch       => build_arch, 
    44                             :gcc_version      => gcc_version, 
    45                             :xcode_version    => xcode_version) 
    46     if not @os_stats.save 
     38    # Try and find an existing entry 
     39    os_stats = OsStatistic.find_by_user_id(user.id) 
     40      
     41    if os_stats.nil? 
     42      # No entry for this user - create a new one 
     43      os_stats = OsStatistic.new() 
     44    end 
     45     
     46    os_stats[:user_id]          = user.id 
     47    os_stats[:macports_version] = macports_version 
     48    os_stats[:osx_version]      = osx_version 
     49    os_stats[:os_arch]          = os_arch 
     50    os_stats[:os_platform]      = os_platform 
     51    os_stats[:build_arch]       = build_arch 
     52    os_stats[:gcc_version]      = gcc_version 
     53    os_stats[:xcode_version]    = xcode_version 
     54     
     55    if not os_stats.save 
    4756      logger.debug "Unable to save os_stats" 
    48       logger.debug "Error message: #{@os_stats.errors.full_messages}" 
     57      logger.debug "Error message: #{os_stats.errors.full_messages}" 
    4958    end 
    5059  end 
     
    8493    os = json['os'] 
    8594    active_ports = json['active_ports'] 
    86     add_os_data(json['id'], os) 
     95     
     96    user = User.find_or_create_by_uuid(json['id']) 
     97     
     98    add_os_data(user, os) 
    8799    add_port_data(json['id'], active_ports) 
    88100 
Note: See TracChangeset for help on using the changeset viewer.