From ee6c76dc911dfd63687df668f91b4f48d060cfdd Mon Sep 17 00:00:00 2001 From: John Pinto Date: Mon, 14 Oct 2024 13:38:38 +0100 Subject: [PATCH] Fix to exclude downloads of public plans with no user id associated with download, as most of these downloads are associated with robots. Change: - We exclude the count of downloads in export_plans table for which user_id is nil. --- CHANGELOG.md | 3 +++ app/models/stat_exported_plan/create_or_update.rb | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aeeb4e2f3..cec6c5642a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Fix +- Fix for removing from statistics the count of the download of plans that lack an user id in exported_plans table. Most of such downloads will have been associated with robots harvesting. + ## v4.2.0 **Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.** diff --git a/app/models/stat_exported_plan/create_or_update.rb b/app/models/stat_exported_plan/create_or_update.rb index 0ef504976c..b3fde3fb57 100644 --- a/app/models/stat_exported_plan/create_or_update.rb +++ b/app/models/stat_exported_plan/create_or_update.rb @@ -40,9 +40,11 @@ def org_plan_ids(org_id:, filtered:) .uniq end + # Exclude plans harvested by robots, by excluding plans that have a user_id nil. def exported_plans(start_date:, end_date:, org_id:, filtered:) ExportedPlan.where(plan_id: org_plan_ids(org_id: org_id, filtered: filtered)) .where(created_at: start_date..end_date) + .where.not(user_id: nil) .count end end