From 52c43bdd8592dcdca4edd28d0fdba406f0ca87f7 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Fri, 1 Mar 2024 23:11:33 -0800 Subject: [PATCH] fixed bug in ontology analytics population process --- lib/ncbo_cron/ontology_analytics.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ncbo_cron/ontology_analytics.rb b/lib/ncbo_cron/ontology_analytics.rb index c5a4de00..3a0f25ee 100644 --- a/lib/ncbo_cron/ontology_analytics.rb +++ b/lib/ncbo_cron/ontology_analytics.rb @@ -158,15 +158,15 @@ def merge_and_fill_missing_data(ga4_data) ua_ga4_intersecting_month = Date.parse(GA4_START_DATE).month.to_s # add up hits for June of 2023 (the only intersecting month between UA and GA4) - ua_data.each do |acronym, _| - if ga4_data.has_key?(acronym) - if ga4_data[acronym][ua_ga4_intersecting_year].has_key?(ua_ga4_intersecting_month) - ua_data[acronym][ua_ga4_intersecting_year][ua_ga4_intersecting_month] += - ga4_data[acronym][ua_ga4_intersecting_year][ua_ga4_intersecting_month] - # delete data for June of 2023 from ga4_data to avoid overwriting when merging - ga4_data[acronym][ua_ga4_intersecting_year].delete(ua_ga4_intersecting_month) - end - end + ua_data.each do |acronym| + next unless ga4_data.key?(acronym) + next unless ga4_data[acronym].key?(ua_ga4_intersecting_year) + next unless ga4_data[acronym][ua_ga4_intersecting_year].key?(ua_ga4_intersecting_month) + + ua_data[acronym][ua_ga4_intersecting_year][ua_ga4_intersecting_month] += + ga4_data[acronym][ua_ga4_intersecting_year][ua_ga4_intersecting_month] + # delete data for June of 2023 from ga4_data to avoid overwriting when merging + ga4_data[acronym][ua_ga4_intersecting_year].delete(ua_ga4_intersecting_month) end end