Skip to content

Instantly share code, notes, and snippets.

@SeanDunford
Created December 12, 2017 21:11
Show Gist options
  • Save SeanDunford/c5ec0ee70535d20268ceb4e8f77b19ae to your computer and use it in GitHub Desktop.
Save SeanDunford/c5ec0ee70535d20268ceb4e8f77b19ae to your computer and use it in GitHub Desktop.
Get missing/matched/mismatched/correct render count for renders found in the survey_response collection
desc 'DO REALLY AWESOME STUFF'
task :awesome_stff do
survey_count = 0;
response_count = 0;
missing_renders = 0;
matched_renders = 0;
mismatched_renders = 0;
puts 'Fetching all dem responses'
docs = LegacyDB.survey_stats[:knotch_responses].aggregate([
{ "$group": {
_id: "$s",
survey_id: { '$first': '$s' },
renders: { "$addToSet": "$r" }
}},
]).to_a;
puts 'Fetched all dem responses'
survey_count = docs.length
docs.map do |doc|
response_survey_id = doc[:survey_id]
puts "Counting all that awesome data for survey_id: #{response_survey_id}"
doc[:renders].map do |render|
response_count += 1;
puts "Still counting for survey_id: #{response_survey_id}" if response_count % 10000 == 0
render_docs = LegacyDB.survey_stats[:survey_renders].find(_id: render).to_a
render_doc = render_docs.first
unless render_doc
binding.pry
next missing_renders += 1
end
if (render_doc[:s] == response_survey_id && render_docs.length == 1)
next matched_renders += 1
end
if (render_doc[:s] != response_survey_id || render_docs.length > 1)
binding.pry
next mismatched_renders += 1
end
end
end
puts 'RESULTSSSSSSSSSSSSSSSS!'
pp ({
survey_count: survey_count,
response_count: response_count,
missing_renders: missing_renders,
matched_renders: matched_renders,
mismatched_renders: mismatched_renders,
})
puts 'RESULTSSSSSSSSSSSSSSSS!'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment