Skip to content

Commit d0fa4c3

Browse files
committed
feat: implement method of calculating which instructors to prompt
After a professor has deployed a case in their classroom, we want to invite them to write up a retrospective of their experience as a post in the instructors-only community “CaseLog.” We look for deployments whose members were much more active in the case 14 to 7 days ago than they were in the last 7 days. This is defined as an 80% drop-off of use from wee to week, where the previous week measured over 500 events. We exclude any deployments with fewer than five readers as a sanity check. These magic numbers were chosen empirically based on recorded data at an early stage and should be subject to review.
1 parent 2a56022 commit d0fa4c3

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# frozen_string_literal: true
2+
3+
# After a professor has deployed a case in their classroom, we want to invite
4+
# them to write up a retrospective of their experience as a post in the
5+
# instructors-only community “CaseLog.” This service sends such notifications.
6+
#
7+
# Running once a week, on Wednesdays at noon (Eastern), we look for deployments
8+
# whose members were much more active in the case 14 to 7 days ago than they
9+
# were in the last 7 days. This is defined as an 80% drop-off of use from week
10+
# to week, where the previous week measured over 500 events. This was chosen
11+
# empirically based on recorded data at an early stage and should be subject to
12+
# review. We exclude any deployments with fewer than five readers as a sanity
13+
# check. When we send prompts to the instructors, we set the
14+
# `retrospective_prompt_sent` flag so never to bug people more than once.
15+
class SendRetrospectivePrompts
16+
def self.call(time_basis: Time.zone.now)
17+
new(time_basis).call
18+
end
19+
20+
def initialize(now)
21+
@now = now
22+
end
23+
24+
def call
25+
deployments_needing_prompts.map { |x| [x.group.name, x.case.slug] }
26+
# deployments_needing_prompts.each do |deployment|
27+
# deployment.update retrospective_prompt_set: true
28+
# DeploymentMailer.retrospective_prompt(deployment).deliver
29+
# end
30+
end
31+
32+
private
33+
34+
def deployments_needing_prompts
35+
candidate_deployments_with_enough_readers
36+
.select { |d| much_more_use_two_weeks_ago d }
37+
end
38+
39+
def candidate_deployments_with_enough_readers
40+
count_readers_by_group = GroupMembership.group(:group_id).count(:reader_id)
41+
Deployment.where(retrospective_prompt_sent_at: nil)
42+
.select { |d| count_readers_by_group[d.group_id] > 5 }
43+
end
44+
45+
def much_more_use_two_weeks_ago(deployment)
46+
two_weeks_ago = count_interesting_events(
47+
deployment,
48+
(@now - 2.weeks)..(@now - 1.week)
49+
)
50+
last_week = count_interesting_events(
51+
deployment,
52+
(@now - 1.week)..@now
53+
)
54+
55+
two_weeks_ago > 500 && (two_weeks_ago - last_week) / two_weeks_ago > -0.8
56+
end
57+
58+
def count_interesting_events(deployment, range)
59+
Ahoy::Event.interesting
60+
.where(user_id: deployment.group.readers.pluck(:id))
61+
.where_properties(case_slug: deployment.case.slug)
62+
.where(time: range)
63+
.count
64+
end
65+
end

0 commit comments

Comments
 (0)