Skip to content

Commit 30b7045

Browse files
authored
Merge pull request code-dot-org#15152 from code-dot-org/emails
Prep for 2017-05-17 EOY emails.
2 parents de5b83d + f7da952 commit 30b7045

File tree

7 files changed

+210
-0
lines changed

7 files changed

+210
-0
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative '../mailing-common/mailing-list-utils'
4+
5+
PEGASUS_REPORTING_DB_READONLY = sequel_connect(
6+
CDO.pegasus_reporting_db_reader,
7+
CDO.pegasus_reporting_db_reader
8+
)
9+
10+
# EMAIL 1 (csf_pd): Code Studio teachers who attended a K5 PD.
11+
query_1_csf_pd = "
12+
SELECT email
13+
FROM contact_rollups
14+
WHERE opted_out IS NULL
15+
AND roles LIKE '%Teacher%'
16+
AND professional_learning_attended LIKE '%CS Fundamentals%'
17+
"
18+
results_1_csf_pd = {}
19+
PEGASUS_REPORTING_DB_READONLY.fetch(query_1_csf_pd).
20+
reject {|row| UNSUBSCRIBERS.include? row[:email]}.
21+
each do |row|
22+
results_1_csf_pd[row[:email]] = {email: row[:email]}
23+
end
24+
25+
puts "LIST 1 (CSF PD) SIZE: #{results_1_csf_pd.size}."
26+
export_contacts_to_csv results_1_csf_pd, 'email_1_csf_pd.csv'
27+
28+
# EMAIL 2: Code Studio teachers in (US or unknown location) and
29+
# (sections where grade is K5 or ages of students taught is 4 to 11)
30+
# minus EMAIL 1.
31+
32+
query_2_csf_no_pd = "
33+
SELECT email
34+
FROM contact_rollups
35+
WHERE opted_out IS NULL
36+
AND roles LIKE '%Teacher%'
37+
AND (country = 'United States' OR country IS NULL)
38+
AND (
39+
(
40+
FIND_IN_SET('K', grades_taught) > 0
41+
OR FIND_IN_SET('1', grades_taught) > 0
42+
OR FIND_IN_SET('2', grades_taught) > 0
43+
OR FIND_IN_SET('3', grades_taught) > 0
44+
OR FIND_IN_SET('4', grades_taught) > 0
45+
OR FIND_IN_SET('5', grades_taught) > 0
46+
) OR (
47+
FIND_IN_SET('4', ages_taught) > 0
48+
OR FIND_IN_SET('5', ages_taught) > 0
49+
OR FIND_IN_SET('6', ages_taught) > 0
50+
OR FIND_IN_SET('7', ages_taught) > 0
51+
OR FIND_IN_SET('8', ages_taught) > 0
52+
OR FIND_IN_SET('9', ages_taught) > 0
53+
OR FIND_IN_SET('10', ages_taught) > 0
54+
OR FIND_IN_SET('11', ages_taught) > 0
55+
)
56+
)
57+
"
58+
results_2_csf_no_pd = {}
59+
PEGASUS_REPORTING_DB_READONLY.fetch(query_2_csf_no_pd).
60+
reject {|row| UNSUBSCRIBERS.include? row[:email]}.
61+
reject {|row| results_1_csf_pd.key? row[:email]}.
62+
each do |row|
63+
results_2_csf_no_pd[row[:email]] = {email: row[:email]}
64+
end
65+
66+
puts "LIST 2 (CSF NO PD) SIZE: #{results_2_csf_no_pd.size}."
67+
export_contacts_to_csv results_2_csf_no_pd, 'email_2_csf_no_pd.csv'
68+
# Split up for 2 A/B test formats at 10% each, leaving 80% for the final mail.
69+
puts `../mailing-common/split ./email_2_csf_no_pd.csv #{' 10' * 2}`
70+
71+
# EMAIL 3: Code Studio teachers in (US or unknown location) and
72+
# (sections where grade is 9 to 12 or ages of students taught is 14 to 18)
73+
# minus EMAIL 1 and EMAIL 2.
74+
75+
query_3_csp = "
76+
SELECT email
77+
FROM contact_rollups
78+
WHERE opted_out IS NULL
79+
AND roles LIKE '%Teacher%'
80+
AND (country = 'United States' OR country IS NULL)
81+
AND (
82+
(
83+
FIND_IN_SET('9', grades_taught) > 0
84+
OR FIND_IN_SET('10', grades_taught) > 0
85+
OR FIND_IN_SET('11', grades_taught) > 0
86+
OR FIND_IN_SET('12', grades_taught) > 0
87+
) OR (
88+
FIND_IN_SET('14', ages_taught) > 0
89+
OR FIND_IN_SET('15', ages_taught) > 0
90+
OR FIND_IN_SET('16', ages_taught) > 0
91+
OR FIND_IN_SET('17', ages_taught) > 0
92+
OR FIND_IN_SET('18', ages_taught) > 0
93+
)
94+
)
95+
"
96+
results_3_csp = {}
97+
PEGASUS_REPORTING_DB_READONLY.fetch(query_3_csp).
98+
reject {|row| UNSUBSCRIBERS.include? row[:email]}.
99+
reject {|row| results_1_csf_pd.key?(row[:email]) || results_2_csf_no_pd.key?(row[:email])}.
100+
each do |row|
101+
results_3_csp[row[:email]] = {email: row[:email]}
102+
end
103+
104+
puts "LIST 3 (CSP) SIZE: #{results_3_csp.size}."
105+
export_contacts_to_csv results_3_csp, 'email_3_csp.csv'
106+
107+
# EMAIL 4: Code Studio teachers in (US or unknown location) and
108+
# (sections where grade is 6 to 8 or ages of students taught is 12 to 13)
109+
# minus EMAIL 1 and EMAIL 2 and EMAIL 3.
110+
111+
query_4_csd = "
112+
SELECT email
113+
FROM contact_rollups
114+
WHERE opted_out IS NULL
115+
AND roles LIKE '%Teacher%'
116+
AND (country = 'United States' OR country IS NULL)
117+
AND (
118+
(
119+
FIND_IN_SET('6', grades_taught) > 0
120+
OR FIND_IN_SET('7', grades_taught) > 0
121+
OR FIND_IN_SET('8', grades_taught) > 0
122+
) OR (
123+
FIND_IN_SET('12', ages_taught) > 0
124+
OR FIND_IN_SET('13', ages_taught) > 0
125+
)
126+
)
127+
"
128+
results_4_csd = {}
129+
PEGASUS_REPORTING_DB_READONLY.fetch(query_4_csd).
130+
reject {|row| UNSUBSCRIBERS.include? row[:email]}.
131+
reject {|row| results_1_csf_pd.key?(row[:email]) || results_2_csf_no_pd.key?(row[:email]) || results_3_csp.key?(row[:email])}.
132+
each do |row|
133+
results_4_csd[row[:email]] = {email: row[:email]}
134+
end
135+
136+
puts "LIST 4 (CSD) SIZE: #{results_4_csd.size}."
137+
export_contacts_to_csv results_4_csd, 'email_4_csd.csv'
138+
139+
# EMAIL 5: Code Studio teachers in (US or unknown location)
140+
# minus EMAIL 1 and EMAIL 2 and EMAIL 3 and EMAIL 4.
141+
142+
query_5_unknown = "
143+
SELECT email
144+
FROM contact_rollups
145+
WHERE opted_out IS NULL
146+
AND roles LIKE '%Teacher%'
147+
AND (country = 'United States' OR country IS NULL)
148+
"
149+
results_5_unknown = {}
150+
PEGASUS_REPORTING_DB_READONLY.fetch(query_5_unknown).
151+
reject {|row| UNSUBSCRIBERS.include? row[:email]}.
152+
reject {|row| results_1_csf_pd.key?(row[:email]) || results_2_csf_no_pd.key?(row[:email]) || results_3_csp.key?(row[:email]) || results_4_csd.key?(row[:email])}.
153+
each do |row|
154+
results_5_unknown[row[:email]] = {email: row[:email]}
155+
end
156+
157+
puts "LIST 5 (UNKNOWN) SIZE: #{results_5_unknown.size}."
158+
export_contacts_to_csv results_5_unknown, 'email_5_unknown.csv'
159+
160+
# EMAIL 6: Code Studio teachers
161+
# minus EMAIL 1 and EMAIL 2 and EMAIL 3 and EMAIL 4 and EMAIL 5.
162+
163+
query_6_international = "
164+
SELECT email
165+
FROM contact_rollups
166+
WHERE opted_out IS NULL
167+
AND roles LIKE '%Teacher%'
168+
"
169+
results_6_international = {}
170+
PEGASUS_REPORTING_DB_READONLY.fetch(query_6_international).
171+
reject {|row| UNSUBSCRIBERS.include? row[:email]}.
172+
reject {|row| results_1_csf_pd.key?(row[:email]) || results_2_csf_no_pd.key?(row[:email]) || results_3_csp.key?(row[:email]) || results_4_csd.key?(row[:email]) || results_5_unknown.key?(row[:email])}.
173+
each do |row|
174+
results_6_international[row[:email]] = {email: row[:email]}
175+
end
176+
177+
puts "LIST 6 (INTERNATIONAL) SIZE: #{results_6_international.size}."
178+
export_contacts_to_csv results_6_international, 'email_6_international.csv'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdA ./email_2_csf_no_pd-experiment-1.csv
4+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdB ./email_2_csf_no_pd-experiment-2.csv
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdA ./test-params.csv
4+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdB ./test-params.csv
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdC ./email_2_csf_no_pd-experiment-3.csv
4+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdD ./email_2_csf_no_pd-experiment-4.csv
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdC ./test-params.csv
4+
../send-to-mailing-list 2017-05-17-endofyear-k5nopdD ./test-params.csv
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
../send-to-mailing-list 2017-05-17-endofyear-k5pd ./email_1_csf_pd.csv
4+
../send-to-mailing-list 2017-05-17-endofyear-k5nopd ./email_2_csf_no_pd-remainder.csv
5+
../send-to-mailing-list 2017-05-17-endofyear-high ./email_3_csp.csv
6+
../send-to-mailing-list 2017-05-17-endofyear-middle ./email_4_csd.csv
7+
../send-to-mailing-list 2017-05-17-endofyear-unknownage ./email_5_unknown.csv
8+
../send-to-mailing-list 2017-05-17-endofyear-international ./email_6_international.csv
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
../send-to-mailing-list 2017-05-17-endofyear-k5pd ./test-params.csv
4+
../send-to-mailing-list 2017-05-17-endofyear-k5nopd ./test-params.csv
5+
../send-to-mailing-list 2017-05-17-endofyear-high ./test-params.csv
6+
../send-to-mailing-list 2017-05-17-endofyear-middle ./test-params.csv
7+
../send-to-mailing-list 2017-05-17-endofyear-unknownage ./test-params.csv
8+
../send-to-mailing-list 2017-05-17-endofyear-international ./test-params.csv

0 commit comments

Comments
 (0)