[116790] branches/gsoc11-statistics/stats-server/app/controllers/ installed_ports_controller.rb

cal at macports.org cal at macports.org
Fri Feb 7 11:30:37 PST 2014


Revision: 116790
          https://trac.macports.org/changeset/116790
Author:   cal at macports.org
Date:     2014-02-07 11:30:37 -0800 (Fri, 07 Feb 2014)
Log Message:
-----------
macports stat: fix errors when no ports/stats available

Modified Paths:
--------------
    branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb

Modified: branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb	2014-02-07 19:29:46 UTC (rev 116789)
+++ branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb	2014-02-07 19:30:37 UTC (rev 116790)
@@ -21,7 +21,8 @@
       sum = sum + user.installed_ports.count
     end
     
-    average = sum / users.count
+    return 0 unless users.count > 0
+    average = sum / users.count unless users.count == 0
   end
   
   # Find the port that has been installed most this year
@@ -39,8 +40,12 @@
                                
    # most populator port this year
    popular_port_year = top.first
-   @popular_port_year = Port.find(popular_port_year[0])
-   @popular_port_year_count = popular_port_year[1]
+   @popular_port_year = nil
+   @popular_port_year_count = 0
+   unless popular_port_year == nil
+     @popular_port_year = Port.find(popular_port_year[0])
+     @popular_port_year_count = popular_port_year[1]
+   end
   end
   
   # Most popular port this month
@@ -110,4 +115,4 @@
     end
   end
   
-end
\ No newline at end of file
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140207/4ba97821/attachment.html>


More information about the macports-changes mailing list