Last active
December 22, 2015 20:49
-
-
Save jonstorer/6528907 to your computer and use it in GitHub Desktop.
Admin Tickets
This file contains hidden or 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
output/* |
This file contains hidden or 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
# encoding: utf-8 | |
class ActionDataPullBase | |
def initialize(slug) | |
@slug = slug | |
end | |
def progress(name, count, &block) | |
progress = ProgressBar.create(:title => name, :total => count, :format => '%t |%b[%P%%]%i| %c/%C [%E]') | |
block.call(progress) | |
progress.finish | |
end | |
private | |
def action | |
@action ||= BrandAction.find @slug | |
end | |
def output_path | |
File.expand_path(File.join(self.class.path, "#{slug}_#{version}_#{Time.now.to_s(:number)}.csv")) | |
end | |
def self.path | |
path = File.join(File.dirname(File.expand_path(__FILE__)), 'output') | |
FileUtils.mkdir_p(path) unless File.directory?(path) | |
path | |
end | |
def version | |
'v8' | |
end | |
def slug | |
@slug | |
end | |
def sanatize(string) | |
string.to_s.try(:gsub, /[,“”]/, '') | |
end | |
def csvify(string) | |
"\"#{string}\"" | |
end | |
end |
This file contains hidden or 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
# [Emergency Bug] - Need all the crowd members for Newtons, Verizon, and Kraft Lunchables crowds. | |
# Whether by email or memberid, we need these lists by eod. Thanks. | |
class CrowdMemberPull < ActionDataPullBase | |
def run! | |
progress(slug, crowd_members.count) do |bar| | |
File.open(output_path, 'a+') do |file| | |
fields = {} | |
fields['ID'] = lambda {|cm| cm.member_id } | |
fields['Full Name'] = lambda {|cm| "#{cm.member.first_name} #{cm.member.last_name}" } | |
fields['Shipping Address'] = lambda {|cm| cm.member.full_shipping_address } | |
file.puts fields.keys.join(', ') | |
crowd_members.each do |crowd_member| | |
values = fields.values.map do |fn| | |
# this is long hand for debugging | |
value = fn.call(crowd_member) | |
value = sanatize(value) | |
value = csvify(value) | |
value | |
end | |
row = values.join(', ') | |
file.puts row | |
bar.increment | |
end | |
end | |
end | |
end | |
private | |
def brand | |
@brand ||= Brand.find @slug | |
end | |
def crowd_members | |
brand.crowd_members.only(:member_id).where(:public_crowd_member => true) | |
end | |
end |
This file contains hidden or 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
# encoding: utf-8 | |
class DiscussionScreenerPull < ActionDataPullBase | |
def run! | |
File.open(output_path, 'a+') do |file| | |
members.each do |member| | |
row = [] | |
row << "\"#{member.first_name} #{member.last_name}\"" | |
row << "\"#{member.email}\"" | |
action.screener_polls.each do |screener| | |
answer = answer_for(screener, member) | |
answer = answer.gsub(',','') | |
answer = answer.gsub('“','') | |
answer = answer.gsub('”','') | |
row << answer | |
end | |
#puts row.join(', ') | |
file.puts row.join(', ') | |
end | |
end | |
end | |
private | |
def members | |
Member.find(action.moderation_queue) | |
end | |
def answer_for(screener, member) | |
id = ScreenerPollParticipation.where({ :long_action_quick_hit_id => screener.id, :member_id => member.id }).only(:poll_option_id).first.poll_option_id.to_s | |
screener.poll_options.detect{|o| o.id.to_s == id}.try :value | |
end | |
end |
This file contains hidden or 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
# Need fiance data for each of the following brand actions. | |
# We need a CSV file for each brand action, | |
# with the following data: | |
# a column for each type of engagement: like, comment, retweet, reply, favorite. | |
# For each type of engagement, | |
# we need to know the number of Facebook friends of the user who engaged. | |
# For example, if a facebook user liked a crowdtap member's content share, | |
# we need the # of facebook friends of that liker in the CSV. | |
# All brand action links are in the comments | |
class FiancePull < ActionDataPullBase | |
INDEX = { | |
'likes' => 'production_likes_post_on_facebooks', | |
'comments' => 'production_comments_on_facebook_posts', | |
'retweets' => 'production_retweets', | |
'replies' => 'production_replies_to_tweets' | |
} | |
VALUE_FIELD = { | |
'likes' => 'likes_post_on_facebook_friend_count', | |
'comments' => 'comments_on_facebook_post_friend_count', | |
'retweets' => 'retweets_followers_count', | |
'replies' => 'replies_to_tweet_followers_count' | |
} | |
def run! | |
without_promiscuous do | |
progress(slug, participations.count) do |bar| | |
File.open(output_path, 'a+') do |file| | |
values = [] | |
values << 'Full Name' | |
values << 'Email' | |
values << 'Avg Number of friends for everyone that Liked this post' | |
values << 'Avg Number of friends for everyone that Commented this post' | |
values << 'Avg Number of friends for everyone that Retweeted this tweet' | |
values << 'Avg Number of friends for everyone that Replied this tweet' | |
row = values.map{|v| csvify(sanatize(v))}.join(', ') | |
file.puts row | |
participations.each do |participation| | |
participation.social_network_shares.each do |social_network_share| | |
id = participation.member_id.to_s | |
values = [] | |
values << "#{participation.member.first_name} #{participation.member.last_name}" | |
values << participation.member.email | |
values << likes_avg_friends(id) | |
values << comments_avg_friends(id) | |
values << retweets_avg_followers(id) | |
values << replies_avg_followers(id) | |
row = values.join(', ') | |
file.puts row | |
end | |
bar.increment | |
end | |
end | |
end | |
end | |
end | |
private | |
def participations | |
action.participations.no_timeout | |
end | |
def likes_avg_friends(member_id) | |
memo('likes')[member_id.to_s] | |
end | |
def comments_avg_friends(member_id) | |
memo('comments')[member_id.to_s] | |
end | |
def retweets_avg_followers(member_id) | |
memo('retweets')[member_id.to_s] | |
end | |
def replies_avg_followers(member_id) | |
memo('replies')[member_id.to_s] | |
end | |
def memo(type) | |
@memo ||= {} | |
@memo[type] ||= begin | |
curl(type, params(type))['facets']['average']['terms'].inject({}) do |mem, term| | |
mem[term['term']] = term['mean'] | |
mem | |
end | |
end | |
@memo[type] | |
end | |
def params(type) | |
{ 'filter' => { 'term' => { 'brand_action_id' => action.id } }, | |
'facets' => { | |
'average' => { | |
'terms_stats' => { | |
'key_field' => 'member_id', | |
'value_field' => VALUE_FIELD[type], | |
'size' => action.participations.count | |
} | |
} | |
} | |
} | |
end | |
def curl(type, params) | |
command = "curl -XGET -u crowdtap:tapthat2011 'http://internal-fiance-es-internal-1836159529.us-east-1.elb.amazonaws.com:9200/#{INDEX[type]}/_search?search_type=count' -d '#{params.to_json}'" | |
puts command | |
JSON.parse `#{command}` | |
end | |
end |
This file contains hidden or 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
class CVSPhotoChallenge < ActionDataPullBase | |
def run! | |
File.open(output_path, 'a+') do |file| | |
responses.each do |response| | |
member = response.member | |
row = [] | |
row << member.display_name | |
row << member.gender | |
row << member.age | |
row << member.ethnicity | |
row << member.residence_city | |
row << member.residence_state | |
row << Rails.application.routes.url_helpers.challenge_response_url(response) | |
file.puts row.join(', ') | |
end | |
end | |
end | |
private | |
def responses | |
action.participations.where(:media_url.ne => nil) | |
end | |
end |
This file contains hidden or 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
require 'ruby-progressbar' | |
load File.join(File.dirname(File.expand_path(__FILE__)), 'base.rb') | |
load File.join(File.dirname(File.expand_path(__FILE__)), 'crowd_members_pull.rb') | |
slugs = %w{ campbell-s } | |
slugs.each do |slug| | |
CrowdMemberPull.new(slug).run! | |
end |
This file contains hidden or 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
#!/bin/zsh | |
curl -XGET -u crowdtap:tapthat2011 'http://internal-fiance-es-internal-1836159529.us-east-1.elb.amazonaws.com:9200/production_likes_post_on_facebooks,production_comments_on_facebook_posts,production_retweets,production_replies_to_tweets/_search?pretty=true' -d ' | |
{ | |
"query" : { | |
"bool" : { | |
"must" : [ | |
{ "term" : { "brand_action_id": "5204fc58671a4bb339000028" } }, | |
{ "term" : { "member_id": "51466504948c816aa1000099" } } | |
] | |
} | |
}, | |
"facets" : { | |
"likes": { | |
"terms_stats": { | |
"key_field": "member_id", | |
"value_field": "likes_post_on_facebook_friend_count" | |
} | |
} | |
} | |
' |
This file contains hidden or 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
#!/bin/zsh | |
curl -XGET -u crowdtap:tapthat2011 'http://internal-fiance-es-internal-1836159529.us-east-1.elb.amazonaws.com:9200/production_likes_post_on_facebooks/_search?search_type=count&pretty=true' -d ' | |
{ | |
"filter" : { | |
"term" : { "brand_action_id": "5204fc58671a4bb339000028" } | |
}, | |
"facets" : { | |
"average" : { | |
"terms_stats" : { | |
"key_field" : "member_id", | |
"value_field" : "likes_post_on_facebook_friend_count", | |
"size":6350 | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment