Skip to content

Commit

Permalink
Store version and download counts. Add a script to recalculate score.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred committed Oct 22, 2010
1 parent c919ad2 commit a9f58af
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
@@ -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
5 changes: 4 additions & 1 deletion site/db/schema.rb
Expand Up @@ -9,7 +9,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "rocks", :force => true do |t|
t.string "name" t.string "name"
Expand All @@ -18,6 +18,9 @@
t.float "score" t.float "score"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "downloads"
t.integer "version_downloads"
t.string "version"
end end


add_index "rocks", ["name"], :name => "index_rocks_on_name", :unique => true add_index "rocks", ["name"], :name => "index_rocks_on_name", :unique => true
Expand Down
2 changes: 1 addition & 1 deletion site/lib/mine/gem.rb
@@ -1,7 +1,7 @@
module Mine module Mine
class Gem class Gem
DISQUALIFIED = 0.0 DISQUALIFIED = 0.0
USED_TOO_MUCH = 1000 USED_TOO_MUCH = 3000


include Attributes include Attributes


Expand Down
10 changes: 10 additions & 0 deletions site/script/recalculate
@@ -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
21 changes: 17 additions & 4 deletions site/script/update
@@ -1,7 +1,20 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../../config/environment', __FILE__)


Mine.all(1).each do |gem| page = 1
rock = Rock.find_or_initialize_by_name(gem.name) while(page)
rock.update_attributes(:description => gem.info, :authors => gem.authors, :score => gem.score) puts "Fetching page ##{page}"
end 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.