Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/archive_extensions/similar_users.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
module ArchiveExtensions
class SimilarUsers
def self.calculate(login: , language_threshold: 20.0, year: Time.now.year)
def self.calculate(login: , language_threshold: 20.0, year: Time.now.year, level: 1)
# 1st find users that he is connected to (by the repos he contributes to)
# 2nd calculate the language difference to those users
# If the calculated difference is above a certain threshold
# then add them to the results
if level > 1
similar = calculate_base(login: login, language_threshold: language_threshold, year: year)
similar_level = similar.map do |similar_user|
next if similar_user.login == login
SimilarUsers.calculate(login: similar_user.login, language_threshold: language_threshold, year: year, level: level - 1)
end.compact

similar | similar_level
else
calculate_base(login: login, language_threshold: language_threshold, year: year)
end.flatten
end

def self.calculate_base(login: , language_threshold: 20.0, year: Time.now.year)
ArchiveExtensions::TopContributedRepositories.for(login: login, count: 5).map do |contributed_repo|
repo = contributed_repo.fetch("repo")
repo.all_contributors.select do |contributor|
Expand Down