Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active January 25, 2018 18:43
Show Gist options
  • Save jywarren/fd31cb03abfac4012362109b4cc47573 to your computer and use it in GitHub Desktop.
Save jywarren/fd31cb03abfac4012362109b4cc47573 to your computer and use it in GitHub Desktop.
How many answers does each question have on PublicLab.org for a time period?
start = DateTime.parse('January 01, 2017')
end = start + 1.year
# How many answers does each question have on PublicLab.org for a time period?
Node.questions.where(created: start.to_i..end.to_i).collect do |q|
q.answers.count
end
# => [2, 0, 0, 1, 3, 1, 1, 2, 3, 0, 1, 2, 1, 3, 2, 0, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 0, 1, 1, 2, 1, 1, 1, 2, 1, 3, 1, 0, 1, 1, 0, 1, 1, 0, 2, 1, 4, 2, 0, 0, 1, 1, 0, 1, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 0, 0, 0, 7, 0, 1, 2, 4, 3, 0, 0, 6, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 4, 0, 4, 1, 1, 1, 2, 2, 2, 0, 1, 0, 2, 0, 0, 2, 1, 2, 1, 1, 1, 1, 3, 0, 1, 2, 0, 2, 0, 1, 4, 2, 2, 1, 1, 2, 1, 2, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 5, 0, 0, 4, 0, 2, 2, 2, 0, 1, 2, 0, 0, 1, 0, 1, 1, 4, 3, 0, 1, 2, 1, 1, 2, 1, 1, 0, 2, 0, 7, 1, 1, 1, 1, 0, 1, 3, 0, 3, 1, 2, 0, 1, 9, 0, 4, 1, 1, 1, 1, 3, 2, 1, 0, 0, 1, 1, 2, 1, 4, 1, 1, 2, 1, 0, 0, 3, 0, 0, 0, 1, 0, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 3, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 5, 0, 1, 0, 0, 1, 3, 2, 0, 1, 0, 2, 9, 0, 1, 1, 0, 1, 1, 1, 1, 2, 1, 4, 2, 1, 1, 3, 0, 0, 0, 0, 2, 1, 4, 3, 2, 1, 5, 0, 1, 2, 1, 1, 3, 2, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 4, 3, 2, 0, 0, 1, 0, 2, 1, 1, 1, 0, 3, 1, 0, 1, 0, 3, 0, 1, 1, 0, 0, 0, 0, 2, 2, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 1, 1, 1, 0, 0, 3, 0, 0, 2, 1, 2, 1, 0, 1, 2, 0, 1, 1, 0, 0]
# How many questions have at least one answer?
answered = 0
Node.questions.where(created: start.to_i..end.to_i).collect do |q|
answered += 1 if q.answers.length > 0
end
# => 246
# Percentage?
246/368.00 # of 368 total questions
# => 0.6684782608695652
# 66.85%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment