[82832] branches/gsoc11-statistics/stats-server/app/controllers/ ports_controller.rb

derek at macports.org derek at macports.org
Sat Aug 20 18:30:43 PDT 2011


Revision: 82832
          http://trac.macports.org/changeset/82832
Author:   derek at macports.org
Date:     2011-08-20 18:30:43 -0700 (Sat, 20 Aug 2011)
Log Message:
-----------
- Use month name and year as hash table key rather than first day of the month

- When iterating over the past 12 months count away from current month rather than towards it.

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

Modified: branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb
===================================================================
--- branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb	2011-08-21 01:27:26 UTC (rev 82831)
+++ branches/gsoc11-statistics/stats-server/app/controllers/ports_controller.rb	2011-08-21 01:30:43 UTC (rev 82832)
@@ -17,7 +17,7 @@
   # Populate the versions over time chart
   def populate_monthly_versions(chart_name, chart)
     chart.string "Month"
-    
+      
     # Add version columns
     column_order = []
     @top_versions.each do |version, count|
@@ -81,9 +81,9 @@
     
     now = Time.now
     now_d = now.to_date
-    month_range = (0..11)
-        
-    for i in month_range
+    
+    # Iterate over months from 11 months ago to 0 months ago (current month)
+    11.downto(0) do |i|
       month = now.months_ago(i).to_date
       
       # Find InstalledPort entries for month
@@ -103,7 +103,8 @@
       return
     end
     
-    key = month.at_beginning_of_month.to_s
+    # Key is the abbreviated month name and the year (eg: Aug 2011)
+    key = month.to_time.strftime("%b %Y")
     monthly_installs[key] = entries.size
   end
     
@@ -113,7 +114,8 @@
     @top_versions.each do |version, count|
       version_entries = entries.where("version = ?", version)
       
-      key = month.at_beginning_of_month.to_s
+      # Key is the abbreviated month name and the year (eg: Aug 2011)
+      key = month.to_time.strftime("%b %Y")
       
       if monthly_versions[key].nil?
         monthly_versions[key] = Hash.new
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20110820/4ed4bf7b/attachment.html>


More information about the macports-changes mailing list