Created
July 12, 2013 07:35
-
-
Save thefron/5982600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$t = TransactionRecharge.order(:id).first.created_at + 1.month | |
WINNING_TABLE_LOOKUP = {} | |
def winning_rate_of(user) | |
WINNING_TABLE_LOOKUP[user.id] || begin | |
counts = MatchingResult.including(user).where('matching_id > ?', 1707043).group("winner_id = #{user.id}").count | |
WINNING_TABLE_LOOKUP[user.id] = counts.empty? ? 0 : (counts['t'] || 0).to_f / counts.values.sum | |
end | |
end | |
def initial_activeness_of(user) | |
first = Matching.by(user).order('id asc').first | |
Matching.by(user).order('id asc').where('created_at < ?', first.created_at + 1.day).count | |
end | |
results = {} | |
%w(boy girl).each do |gender| | |
results[gender] = [] | |
sample_users = User.unscoped.registered.where('created_at > ?', $t).where(gender: (gender == 'boy')).order('RANDOM()').limit(5000) | |
sample_users.each do |user| | |
first_matching = Matching.by(user).order('id asc').first | |
next if first_matching.nil? | |
opponent_ids = first_matching.result_hash.values.flatten.map(&:values).flatten.uniq | |
opponents = User.find opponent_ids | |
next if opponents.length < 1 | |
opponent_winning_rates = opponents.map { |opponent| winning_rate_of opponent } | |
top_winning_rate = opponent_winning_rates.sort[-2..-1].sum / 2 | |
results[gender].push [top_winning_rate, initial_activeness_of(user)] | |
end | |
end | |
aggr = {'boy' => {}, 'girl' => {}} | |
results.each do |k, v| | |
puts k | |
v.each do |vv| | |
if vv[0] < 0.65 | |
(aggr[k]['first'] ||= []).push vv | |
elsif vv[0] < 0.75 | |
(aggr[k]['second'] ||= []).push vv | |
else | |
(aggr[k]['third'] ||= []).push vv | |
end | |
end | |
end | |
aggr.each { |gender, result| puts gender; result.each { |category, rows| puts category; rows.each { |row| puts "#{row[0]}, #{row[1]}" }; puts "\n\n" }; puts "\n\n" } | |
=begin | |
r_aggr = {'boy' => {}, 'girl' => {}} | |
aggr.each do |k, v| | |
v.each do |kk, vv| | |
r_aggr[k][kk] = vv.sample v.values.map(&:length).min | |
end | |
end | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment