Skip to content

Commit

Permalink
Add beginning of repository score calculator #64
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jul 29, 2020
1 parent 70cf9b4 commit bdcec9f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def show

def collab_repositories
@page_title = 'Collaborator Repositories'
@scope = Repository.external
@scope = Repository.external.where('score >= 0')
@scope = @scope.org(params[:org]) if params[:org].present?
@scope = @scope.language(params[:language]) if params[:language].present?
@scope = @scope.fork(params[:fork]) if params[:fork].present?
Expand Down Expand Up @@ -64,7 +64,7 @@ def collab_repositories

def community
@page_title = 'Community Repositories'
@scope = Repository.community
@scope = Repository.community.where('score >= 0')
@scope = @scope.org(params[:org]) if params[:org].present?
@scope = @scope.language(params[:language]) if params[:language].present?
@scope = @scope.fork(params[:fork]) if params[:fork].present?
Expand Down
38 changes: 38 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,42 @@ def archive_all_issues!
def unarchive_all_issues!
issues.update_all(locked: false)
end

def calculate_score
new_score = 0
# Is it a fork?
new_score += -10 if fork?
# Is it archived?
new_score += -10 if archived?
# How many stars?
new_score += Math.log(stargazers_count, 10) if stargazers_count && stargazers_count > 0
# How many forks?
new_score += Math.log(forks_count, 10) if forks_count && forks_count > 0
# How many watchers?
new_score += Math.log(subscribers_count, 10) if subscribers_count && subscribers_count > 0
# How long has it existed?
new_score += Math.log((Date.today-created_at.to_date).to_i, 10) if (Date.today-created_at.to_date).to_i > 0
# When was it last updated?
new_score += -Math.log((Date.today-updated_at.to_date).to_i, 10) if (Date.today-updated_at.to_date).to_i > 0
# When was it last committed to?
new_score += -Math.log((Date.today-pushed_at.to_date).to_i, 10) if pushed_at && (Date.today-pushed_at.to_date).to_i > 0

# Is it owned by an internal org? (owner)
# Is it owned by a collab org? (owner)
# Is it owned by a collab contributor? (owner)
# Is it owned by a core contributor? (owner)
# Is it owned by a community contributor? (owner)

# does it have search results?

# Does it use go-ipfs as a library?
# Does it use js-ipfs as a library?
# Does it use go-ipfs via docker?

new_score
end

def update_score
update_column(:score, calculate_score)
end
end
5 changes: 4 additions & 1 deletion app/views/repositories/_repository.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<small class='text-muted'>
<%= repository.description %><br/>
Last pushed: <%= distance_of_time_in_words_to_now repository.pushed_at %> ago<br/>
Size: <%= number_to_human_size repository.size*1000 %>
Size: <%= number_to_human_size repository.size*1000 %><br/>
Stars: <%= repository.stargazers_count %><br/>
Forks: <%= repository.forks_count %><br/>
Score: <%= repository.score %>
</small>
</div>
</div>
4 changes: 3 additions & 1 deletion app/views/repositories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
Language: <%= @repository.language %><br/>
Last pushed: <%= distance_of_time_in_words_to_now @repository.pushed_at %> ago<br/>
Size: <%= number_to_human_size @repository.size*1000 %><br/>
Dependencies: <%= number_with_delimiter @manifests.map(&:repository_dependencies).flatten.length %>
Dependencies: <%= number_with_delimiter @manifests.map(&:repository_dependencies).flatten.length %><br/>
Created: <%= distance_of_time_in_words_to_now @repository.created_at %> ago<br/>
Updated: <%= distance_of_time_in_words_to_now @repository.updated_at %> ago<br/>
</small>
</p>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200729125520_add_score_to_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddScoreToRepositories < ActiveRecord::Migration[6.0]
def change
add_column :repositories, :score, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_07_23_123556) do
ActiveRecord::Schema.define(version: 2020_07_29_125520) do

# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
Expand Down Expand Up @@ -160,6 +160,7 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "etag"
t.integer "score", default: 0
end

create_table "repository_dependencies", force: :cascade do |t|
Expand Down

0 comments on commit bdcec9f

Please sign in to comment.