From 039c910418ce9aaceabeaa2821fefcc827ae69e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 8 May 2024 17:44:16 +0200 Subject: [PATCH] Make it more obvious that we're using dates in charts The `shared_keys` and `k` variable names could mean anything, so it wasn't clear what these variables contained. --- app/models/ahoy/data_source.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/ahoy/data_source.rb b/app/models/ahoy/data_source.rb index f67bc288860..1041c159bba 100644 --- a/app/models/ahoy/data_source.rb +++ b/app/models/ahoy/data_source.rb @@ -13,19 +13,19 @@ def self.build(&block) # chart def add(name, collection) collections.push data: collection, name: name - shared_keys.merge(collection.keys) + dates.merge(collection.keys) end def build data = { x: [] } - shared_keys.each do |k| + dates.each do |date| # Add the key with a valid date format - data[:x].push k.strftime("%Y-%m-%d") + data[:x].push date.strftime("%Y-%m-%d") # Add the value for each column, or 0 if not present collections.each do |col| data[col[:name]] ||= [] - count = col[:data][k] || 0 + count = col[:data][date] || 0 data[col[:name]].push count end end @@ -39,8 +39,8 @@ def collections @collections ||= [] end - def shared_keys - @shared_keys ||= Set.new + def dates + @dates ||= Set.new end end end