Skip to content

Instantly share code, notes, and snippets.

@rasoliveira
Created November 23, 2018 02:04
Show Gist options
  • Save rasoliveira/c8e4ebcf5a4f356ebfdec0e56e5eeb6e to your computer and use it in GitHub Desktop.
Save rasoliveira/c8e4ebcf5a4f356ebfdec0e56e5eeb6e to your computer and use it in GitHub Desktop.
A script to dump customers and their surveys info so that we can plan enabling the survey designer
def subdomains
[
#first batch
"insideview",
"surveydesignsandbox",
"di",
"dhhooli",
"hoolitest",
"cultureamp",
"airtasker",
"goforward",
"mobify",
"policygenius",
"chartboost",
"contactually",
"front",
"hireology",
"linode",
"mavencare",
"youvisit",
"compass",
"hinge",
"kinetix",
"milmeq",
"shippit",
"fortumo",
"thenamaris",
"berlinrosen",
"remix",
# candidates
"adhocpropertymanagement",
"brisbanefc",
"centertoadvancepalliativecare",
"cigroup",
"clearscore",
"clubw",
"coda",
"compudyne",
"covergenius",
"deakin",
"diaandco",
"dlabs",
"ecoenergy",
"elitesem",
"embroker",
"foolcom",
"freshminds",
"fueled",
"getaround",
"gfguk",
"girlswhocode",
"goodpractice",
"gracelockindustries",
"hearst",
"highwayequipment",
"holidayextras",
"indexexchange",
"instacart",
"jamf",
"jetblack",
"kabbage",
"kik",
"klarna",
"leanplum",
"lpf",
"match",
"mckenneys",
"medicanimal",
"melbournefc",
"mixpanel",
"morningconsult",
"mozillafoundation",
"nerdery",
"nerderyinclusion",
"neyber",
"oaktree",
"pantheon",
"percolate",
"periscopedata",
"persado",
"planetlabs",
"redballoxygen",
"reltio",
"revinate",
"richardcrookes",
"similarweb",
"sks365",
"smallimprovements",
"springworks",
"stoneandwood",
"sumerra",
"tamr",
"teamtreehouse",
"thankyou",
"theopenskyproject",
"theroyals",
"thewing",
"trusttoken",
"tskgroup",
"unicef",
"unswglobal",
"upshersmith",
"via",
"vidyo",
"vistacommunityclinic",
"voices",
"yieldmo"
]
end
headers = [:account, :account_locales, :survey, :survey_locales, :created_at, :active, :mandatory, :conditional_branching, :dependent_branching, :self_select, :orphan, :not_show_on_capture, :not_show_on_reports]
accounts = Account.in(subdomain: subdomains).uniq.to_a
CSV.open("/home/murmur/current/tmp/dlteam.csv", 'wb', headers: headers, write_headers: true) do |row|
accounts.each do |acc|
surveys = acc.surveys.to_a.select{|s| SurveyClassifier.product_type(survey: s) == :engagement }
surveys.each do |survey|
data = {
account: acc.subdomain,
account_locales: acc.config(Configs::SUPPORTED_LOCALES),
survey: survey.id.to_s,
survey_locales: survey.config(Configs::SUPPORTED_LOCALES),
created_at: survey.created_at,
active: 0,
mandatory: 0,
conditional_branching: 0,
dependent_branching: 0,
self_select: 0,
orphan: 0,
not_show_on_capture: 0,
not_show_on_reports: 0,
}
survey.survey_to_questions.active.each do |stq|
data[:active] += 1
data[:mandatory] += 1 if stq.mandatory
data[:conditional_branching] += 1 unless stq.conditions.empty?
data[:dependent_branching] += 1 unless stq.dependent_questions.empty?
data[:self_select] += 1 if stq.type == :segment && stq.theme_id && stq.theme.present?
data[:orphan] += 1 if stq.theme_id && !stq.theme.present?
data[:not_show_on_capture] += 1 unless stq.theme_id
data[:not_show_on_reports] += 1 if stq.factor_ids.empty?
end
row << data.values_at(*headers)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment