-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce Series and refactor aggregators, formatters and trans…
…ponders
- Loading branch information
1 parent
97769a4
commit 21e05a0
Showing
12 changed files
with
125 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Trifle | ||
module Stats | ||
class Formatter | ||
class Category | ||
Trifle::Stats::Series.register_formatter(:category, self) | ||
|
||
def format(series:, path:) | ||
keys = path.split('.') | ||
series[:at].each_with_object(Hash.new(0)).with_index do |(_at, map), i| | ||
series[:values][i].dig(*keys).each do |key, value| | ||
k, v = block_given? ? yield(key, value) : [key.to_s, value.to_f] | ||
map[k] += v | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
module Trifle | ||
module Stats | ||
class Series | ||
include Trifle::Stats::Mixins::Packer | ||
|
||
attr_accessor :series | ||
|
||
def initialize(series) | ||
@series = series | ||
@series[:values] = self.class.normalize(@series[:values]) | ||
end | ||
|
||
class Aggregator | ||
def initialize(series) | ||
@series = series | ||
end | ||
end | ||
|
||
def aggregate | ||
@aggregate ||= Aggregator.new(self) | ||
end | ||
|
||
def self.register_aggregator(name, klass) | ||
Aggregator.define_method(name) do |params| | ||
klass.new.aggregate(series: @series.series, **params) | ||
end | ||
end | ||
|
||
class Formatter | ||
def initialize(series) | ||
@series = series | ||
end | ||
end | ||
|
||
def format | ||
@format ||= Formatter.new(self) | ||
end | ||
|
||
def self.register_formatter(name, klass) | ||
Formatter.define_method(name) do |params, &block| | ||
klass.new.format(series: @series.series, **params, &block) | ||
end | ||
end | ||
|
||
class Transponder | ||
def initialize(series) | ||
@series = series | ||
end | ||
end | ||
|
||
def transpond | ||
@transpond ||= Transponder.new(self) | ||
end | ||
|
||
def self.register_transponder(name, klass) | ||
Transponder.define_method(name) do |params| | ||
@series.series = klass.new.transpond(series: @series.series, **params) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters