Created
May 13, 2019 20:10
-
-
Save humphriesjm/3615acbc9a892d1ced168e89eca4633c to your computer and use it in GitHub Desktop.
Number of starred contacts presented in recommendations
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
def print_groups_with_contacts_for_user_id_and_contact_ids(user,contact_ids) | |
results = user | |
.contacts | |
.of_interest | |
.joins(:contact_groups) | |
.where('contact_groups.created_at >= ?', Time.now.beginning_of_year) | |
.pluck("people.id, contact_groups.name, contact_groups.created_at, contact_groups.id") | |
hit_count_for_user = 0 | |
results.each do |r| | |
contact_id = r[0] | |
next if !contact_ids.include?(contact_id) | |
group_name = r[1] | |
group_date = r[2] | |
group_id = r[3] | |
hit_count_for_user += 1 | |
# p = Person.find(contact_id) | |
# puts "#{user.full_name},#{p.full_name},#{group_name},#{group_date}" | |
end | |
puts "#{user.full_name},#{hit_count_for_user}" | |
return nil | |
end | |
# ---- | |
def three_star?(contact) | |
minimum_model_date = [Time.parse("November 1st, 2018"), 12.months.ago].max | |
return false unless contact.preferred_person_match.present? | |
return false unless contact.preferred_person_match.seller_scores.present? | |
score = contact.preferred_person_match.seller_scores.joins(:predictive_model) | |
.where("predictive_models.created_at >= ?", minimum_model_date) | |
.order("percentile desc, predictive_models.created_at asc").first | |
return false unless score.present? | |
return score.percentile >= 90 | |
end | |
def two_star?(contact) | |
minimum_model_date = [Time.parse("November 1st, 2018"), 12.months.ago].max | |
return false unless contact.preferred_person_match.present? | |
return false unless contact.preferred_person_match.seller_scores.present? | |
score = contact.preferred_person_match.seller_scores.joins(:predictive_model) | |
.where("predictive_models.created_at >= ?", minimum_model_date) | |
.order("percentile desc, predictive_models.created_at asc").first | |
return false unless score.present? | |
return score.percentile >= 85 && score.percentile < 90 | |
end | |
def one_star?(contact) | |
minimum_model_date = [Time.parse("November 1st, 2018"), 12.months.ago].max | |
return false unless contact.preferred_person_match.present? | |
return false unless contact.preferred_person_match.seller_scores.present? | |
score = contact.preferred_person_match.seller_scores.joins(:predictive_model) | |
.where("predictive_models.created_at >= ?", minimum_model_date) | |
.order("percentile desc, predictive_models.created_at asc").first | |
return false unless score.present? | |
return score.percentile >= 77 && score.percentile < 85 | |
end | |
def get_three_star_contacts(user) | |
three_stars = [] | |
user.contacts.of_interest.each do |contact| | |
if three_star?(contact) | |
three_stars << contact.id | |
end | |
end | |
three_stars | |
end | |
def get_two_star_contacts(user) | |
two_stars = [] | |
user.contacts.of_interest.each do |contact| | |
if two_star?(contact) | |
two_stars << contact.id | |
end | |
end | |
two_stars | |
end | |
def get_one_star_contacts(user) | |
one_stars = [] | |
user.contacts.of_interest.each do |contact| | |
if one_star?(contact) | |
one_stars << contact.id | |
end | |
end | |
one_stars | |
end | |
# ---- | |
def print_recommended_with_stars_for_user(num_stars,user) | |
stars_group = nil | |
if num_stars == 3 | |
stars_group = get_three_star_contacts(user) | |
elsif num_stars == 2 | |
stars_group = get_two_star_contacts(user) | |
elsif num_stars == 1 | |
stars_group = get_one_star_contacts(user) | |
end | |
print_groups_with_contacts_for_user_id_and_contact_ids(user,stars_group) | |
end | |
def print_recommended_with_stars_for_brokerage(num_stars,brokerage_name) | |
puts "agent_name,contacts_presented" | |
users = User | |
.live_customers | |
.not_admin | |
.where(brokerage: brokerage_name) | |
users.each do |user| | |
print_recommended_with_stars_for_user(num_stars,user) | |
end | |
return nil | |
end | |
print_recommended_with_stars_for_brokerage(3,'@properties') | |
print_recommended_with_stars_for_brokerage(3,'Ansley') | |
print_recommended_with_stars_for_brokerage(3,'Beverly-Hanks') | |
print_recommended_with_stars_for_brokerage(3,'C21 Advantage Gold') | |
print_recommended_with_stars_for_brokerage(3,'C21 Results') | |
print_recommended_with_stars_for_brokerage(3,'Climb') | |
print_recommended_with_stars_for_brokerage(3,'Dwellings') | |
print_recommended_with_stars_for_brokerage(3,'Hometown Advisor') | |
print_recommended_with_stars_for_brokerage(3,'KY Select') | |
print_recommended_with_stars_for_brokerage(3,'Moving The Mitten') | |
print_recommended_with_stars_for_brokerage(3,'One South') | |
print_recommended_with_stars_for_brokerage(3,'Savvy + Co.') | |
print_recommended_with_stars_for_brokerage(3,'Warburg') | |
print_recommended_with_stars_for_brokerage(3,'West + Main') | |
print_recommended_with_stars_for_brokerage(3,'PLG Estates') | |
# 2 stars | |
print_recommended_with_stars_for_brokerage(2,'@properties') | |
print_recommended_with_stars_for_brokerage(2,'Ansley') | |
print_recommended_with_stars_for_brokerage(2,'Beverly-Hanks') | |
print_recommended_with_stars_for_brokerage(2,'C21 Advantage Gold') | |
print_recommended_with_stars_for_brokerage(2,'C21 Results') | |
print_recommended_with_stars_for_brokerage(2,'Climb') | |
print_recommended_with_stars_for_brokerage(2,'Dwellings') | |
print_recommended_with_stars_for_brokerage(2,'Hometown Advisor') | |
print_recommended_with_stars_for_brokerage(2,'KY Select') | |
print_recommended_with_stars_for_brokerage(2,'Moving The Mitten') | |
print_recommended_with_stars_for_brokerage(2,'One South') | |
print_recommended_with_stars_for_brokerage(2,'Savvy + Co.') | |
print_recommended_with_stars_for_brokerage(2,'Warburg') | |
print_recommended_with_stars_for_brokerage(2,'West + Main') | |
print_recommended_with_stars_for_brokerage(2,'PLG Estates') | |
# 1 star | |
print_recommended_with_stars_for_brokerage(1,'@properties') | |
print_recommended_with_stars_for_brokerage(1,'Ansley') | |
print_recommended_with_stars_for_brokerage(1,'Beverly-Hanks') | |
print_recommended_with_stars_for_brokerage(1,'C21 Advantage Gold') | |
print_recommended_with_stars_for_brokerage(1,'C21 Results') | |
print_recommended_with_stars_for_brokerage(1,'Climb') | |
print_recommended_with_stars_for_brokerage(1,'Dwellings') | |
print_recommended_with_stars_for_brokerage(1,'Hometown Advisor') | |
print_recommended_with_stars_for_brokerage(1,'KY Select') | |
print_recommended_with_stars_for_brokerage(1,'Moving The Mitten') | |
print_recommended_with_stars_for_brokerage(1,'One South') | |
print_recommended_with_stars_for_brokerage(1,'Savvy + Co.') | |
print_recommended_with_stars_for_brokerage(1,'Warburg') | |
print_recommended_with_stars_for_brokerage(1,'West + Main') | |
print_recommended_with_stars_for_brokerage(1,'PLG Estates') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment