Created
October 16, 2014 18:21
-
-
Save tkalimov/b3f43e7eb9a57ea4d67c to your computer and use it in GitHub Desktop.
Calculating average user article activity
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 'maintenance' | |
| maintenance = DatabaseMaintainer.new() | |
| maintenance.destroy_duplicate_articles if options["destroy_duplicate_articles"] | |
| maintenance.destroy_duplicate_logs if options["destroy_duplicate_logs"] | |
| maintenance.fix_reading_logs_counter | |
| users = User.where("reading_logs_count > ? AND claimed_profile = ?", 0, true) | |
| reading_log_count_array = users.pluck(:reading_logs_count) | |
| average_per_user = reading_log_count_array.inject{ |sum, el| sum + el }.to_f / reading_log_count_array.size | |
| average_logs_per_month_array =[] | |
| date_today = Date.today | |
| users.each do |user| | |
| first_log = user.first_reading_log_for_topic("lifetime", "All") | |
| if first_log | |
| first_day_of_reading = first_log.time_read.to_date | |
| lifetime_days_reading = date_today - first_day_of_reading | |
| lifetime_months_reading = (lifetime_days_reading.to_f / 30) | |
| unless lifetime_months_reading < 1 | |
| average_logs_per_month = user.reading_logs.size / lifetime_months_reading | |
| average_logs_per_month_array.push(average_logs_per_month) | |
| end | |
| end | |
| end | |
| average_per_month = average_logs_per_month_array.inject{ |sum, el| sum + el } / average_logs_per_month_array.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment