Permalink
Browse files

Store version and download counts. Add a script to recalculate score.

  • Loading branch information...
1 parent c919ad2 commit a9f58af603b7428e2e98e9457dc4a11aa1929d11 @Manfred Manfred committed Oct 22, 2010
@@ -0,0 +1,13 @@
+class AddDownloadsVersionDownloadsAndVersionToRocks < ActiveRecord::Migration
+ def self.up
+ add_column :rocks, :downloads, :integer
+ add_column :rocks, :version_downloads, :integer
+ add_column :rocks, :version, :string
+ end
+
+ def self.down
+ remove_column :rocks, :version
+ remove_column :rocks, :version_downloads
+ remove_column :rocks, :downloads
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20101022124656) do
+ActiveRecord::Schema.define(:version => 20101022130929) do
create_table "rocks", :force => true do |t|
t.string "name"
@@ -18,6 +18,9 @@
t.float "score"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "downloads"
+ t.integer "version_downloads"
+ t.string "version"
end
add_index "rocks", ["name"], :name => "index_rocks_on_name", :unique => true
View
@@ -1,7 +1,7 @@
module Mine
class Gem
DISQUALIFIED = 0.0
- USED_TOO_MUCH = 1000
+ USED_TOO_MUCH = 3000
include Attributes
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+require File.expand_path('../../config/environment', __FILE__)
+
+Rock.find_in_batches do |clump|
+ clump.each do |rock|
+ rock.update_attributes(
+ :score => Mine::Gem.new(:downloads => rock.downloads, :version_downloads => rock.version_downloads).score
+ )
+ end
+end
View
@@ -1,7 +1,20 @@
#!/usr/bin/env ruby
require File.expand_path('../../config/environment', __FILE__)
-Mine.all(1).each do |gem|
- rock = Rock.find_or_initialize_by_name(gem.name)
- rock.update_attributes(:description => gem.info, :authors => gem.authors, :score => gem.score)
-end
+page = 1
+while(page)
+ puts "Fetching page ##{page}"
+ gems = Mine.all(page)
+ gems.each do |gem|
+ rock = Rock.find_or_initialize_by_name(gem.name)
+ rock.update_attributes(
+ :description => gem.info,
+ :authors => gem.authors,
+ :version => gem.version,
+ :downloads => gem.downloads,
+ :version_downloads => gem.version_downloads,
+ :score => gem.score
+ )
+ end
+ page = gems.empty? ? nil : page + 1
+end

0 comments on commit a9f58af

Please sign in to comment.