Skip to content

Commit

Permalink
Make it more obvious that we're using dates in charts
Browse files Browse the repository at this point in the history
The `shared_keys` and `k` variable names could mean anything, so it
wasn't clear what these variables contained.
  • Loading branch information
javierm committed May 8, 2024
1 parent 64d3b58 commit d74d900
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/models/ahoy/data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,8 +39,8 @@ def collections
@collections ||= []
end

def shared_keys
@shared_keys ||= Set.new
def dates
@dates ||= Set.new
end
end
end

0 comments on commit d74d900

Please sign in to comment.