Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update returning users data dates #749

Merged
merged 18 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/data/high_fail_questions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def high_fail_questions
total_count = question_attempts[[module_name, question_name]]
fail_rate = fail_count / total_count

if fail_rate > average_fail_rate
if fail_rate >= average_fail_rate
high_fail_questions[[module_name, question_name]] = fail_rate.to_f
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/data/module_overview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def dashboard
mods.map do |mod|
{
module_name: mod.name,
total_users: User.count,
total_users: User.registration_complete.count,
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
not_started: not_started(mod),
started: started(mod),
in_progress: in_progress(mod),
Expand Down
34 changes: 10 additions & 24 deletions app/models/data/returning_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@ class ReturningUsers
class << self
# @return [Array<String>]
def column_names
[
'Weekly Returning Users',
'Monthly Returning Users',
'Bimonthly Returning Users',
'Quarterly Returning Users',
]
['Weekly Returning Users', 'Monthly Returning Users', 'Quarterly Returning Users']
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
end

# @return [Array<Hash{Symbol => Mixed}>]
def dashboard
[
{
weekly: weekly,
monthly: monthly,
bimonthly: bimonthly,
quarterly: quarterly,
weekly_returning_users: weekly,
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
monthly_returning_users: monthly,
quarterly_returning_users: quarterly,
},
]
end
Expand All @@ -30,33 +24,25 @@ def dashboard
# @param previous [Range]
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
# @param current [Range]
# @return [Integer]
def count(previous:, current:)
previous_visits = Ahoy::Visit.where(started_at: previous)
current_visits = Ahoy::Visit.where(started_at: current)

previous_visits.where(user_id: current_visits.pluck(:user_id)).distinct.count(:user_id)
def count(time_range)
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
visits = Ahoy::Visit.where(started_at: time_range)
visits.group(:user_id).having('count(user_id) > 1').count.size
end

# @return [Integer]
def weekly
count(previous: 2.weeks.ago..1.week.ago, current: 1.week.ago..Time.zone.now)
count(Time.zone.today.last_week.beginning_of_week..Time.zone.today.last_week.end_of_week)
end

# @return [Integer]
def monthly
count(previous: 2.months.ago..1.month.ago, current: 1.month.ago..Time.zone.now)
end

# @return [Integer]
def bimonthly
count(previous: 4.months.ago..2.months.ago, current: 2.months.ago..Time.zone.now)
count(Time.zone.today.last_month.beginning_of_month..Time.zone.today.last_month.end_of_month)
end

# @return [Integer]
def quarterly
current = Time.zone.today.beginning_of_quarter
previous = current - 3.months
count(previous: previous..current, current: current..Time.zone.today)
count(current..Time.zone.now)
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/data/user_module_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def dashboard
# @param mod_name [String]
# @return [Integer]
def module_count(mod_name)
User.all.count { |user| user.module_completed?(mod_name) }
User.registration_complete.count { |user| user.module_completed?(mod_name) }
peterdavidhamilton marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/data/user_module_completion_count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def module_count
# @param count [Integer]
# @return [Integer]
def completed_count(count)
User.all.count { |user| user.modules_completed.eql?(count) }
User.registration_complete.count { |user| user.modules_completed.eql?(count) }
end
end
end
Expand Down
27 changes: 10 additions & 17 deletions spec/models/data/returning_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,28 @@

RSpec.describe Data::ReturningUsers do
let(:headers) do
[
'Weekly Returning Users',
'Monthly Returning Users',
'Bimonthly Returning Users',
'Quarterly Returning Users',
]
['Weekly Returning Users', 'Monthly Returning Users', 'Quarterly Returning Users']
end

let(:rows) do
[
{
weekly: 1,
monthly: 1,
bimonthly: 1,
quarterly: 1,
weekly_returning_users: 1,
monthly_returning_users: 1,
quarterly_returning_users: 1,
},
]
end

let(:user) { create :user, :registered }

before do
Ahoy::Visit.create! id: 1, user_id: user.id, started_at: Time.zone.now
Ahoy::Visit.create! id: 9, user_id: user.id, started_at: 1.day.ago
Ahoy::Visit.create! id: 2, user_id: user.id, started_at: 1.week.ago
Ahoy::Visit.create! id: 3, user_id: user.id, started_at: 2.weeks.ago
Ahoy::Visit.create! id: 4, user_id: user.id, started_at: 1.month.ago
Ahoy::Visit.create! id: 5, user_id: user.id, started_at: 2.months.ago
Ahoy::Visit.create! id: 8, user_id: user.id, started_at: 3.months.ago.beginning_of_quarter
Ahoy::Visit.create!(id: 1, user_id: 1, started_at: Time.zone.today.last_week)
Ahoy::Visit.create!(id: 2, user_id: 1, started_at: Time.zone.today.last_week)
Ahoy::Visit.create!(id: 3, user_id: 1, started_at: Time.zone.today.last_month)
Ahoy::Visit.create!(id: 4, user_id: 1, started_at: Time.zone.today.last_month)
Ahoy::Visit.create!(id: 5, user_id: 1, started_at: Time.zone.today.beginning_of_quarter)
Ahoy::Visit.create!(id: 6, user_id: 1, started_at: Time.zone.today.beginning_of_quarter)
end

it_behaves_like 'a data export model'
Expand Down