Skip to content

Instantly share code, notes, and snippets.

@Jimgerneer
Last active December 15, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jimgerneer/5266812 to your computer and use it in GitHub Desktop.
Save Jimgerneer/5266812 to your computer and use it in GitHub Desktop.
Fail sauce
class Canoe
class CommitValue < Struct.new(:email, :committed_date); end
def self.weight(commit_values)
sorted_by_email_list = commit_values.group_by(&:email)
scored_by = sorted_by_email_list.each_with_object({}) do |(email, commit), hsh|
hsh[email] = sorted_by_email_list[email].count
hsh
end.sort {|(k1,v1), (k2,v2)| v2 <=> v1 }
scored_by_timeliness = sorted_by_email_list.each_with_object({}) do |(email, commits), hsh|
hsh[email] = timeliness_score_for(commits)
hsh
end.sort {|(k1,v1), (k2,v2)| v2 <=> v1 }
binding.pry
end
def self.timeliness_score_for(commits)
commits.reduce(0) {|acc, commit| date_relevance_function(commit.committed_date) }
end
@JacobNinja
Copy link

class Score

  ScoreResult = Struct.new(:email, :score, :commits)

  def initialize(commit_values)
    @commit_values = commit_values
  end

  def weight
    grouped_commits_by_email.map do |(email, commits)|
      ScoreResult.new(email, score(commits), commits)
    end.sort_by(&:score)
  end

  private

  def score(commit_values)
    commit_values.map {|c| c.authored_date}.map {|date| score_time(date) }.reduce(:+)
  end

  def score_time(date)
    # implement time algo here
    rand(0..1)
  end

  def grouped_commits_by_email
    @commit_values.group_by(&:email)
  end

end

@JacobNinja
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment