Skip to content

Instantly share code, notes, and snippets.

@dwilkie
Last active November 2, 2021 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwilkie/4314c770281b715a9a12992dcc3ea0eb to your computer and use it in GitHub Desktop.
Save dwilkie/4314c770281b715a9a12992dcc3ea0eb to your computer and use it in GitHub Desktop.
UNICEF Metrics
start_time = Time.new(2020, 10, 1).beginning_of_day
end_time = Time.new(2020, 12, 31).end_of_day
completed_calls = PhoneCall.completed.where(created_at: start_time..end_time).joins(:call_data_record)
number_of_unpaid_users = User.count # SCFM only for now
number_of_calls = completed_calls.count
number_of_minutes = completed_calls.sum("call_data_records.bill_sec") / 60
number_of_users = (completed_calls.pluck(:to) + completed_calls.pluck(:from)).uniq.count
puts "Number of calls: #{number_of_calls}\nNumber of minutes: #{number_of_minutes}\nNumber of users: #{number_of_users}"
## SCFM Metrics (EWS 1294)
account = Account.find(4)
number_of_registrations = account.contacts.count
number_of_answered_alerts = account.phone_calls.where(remote_direction: "outbound-api").completed.count
number_of_people_who_received_alerts = account.contacts.joins(:phone_calls).merge(PhoneCall.where(remote_direction: "outbound-api").completed).distinct.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment