Revision
116790
Author
cal@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

Diff

Modified: branches/gsoc11-statistics/stats-server/app/controllers/installed_ports_controller.rb (116789 => 116790)


--- 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