Last active
October 29, 2020 11:55
-
-
Save OpakAlex/eb107406479a3f5f35d1f72eae6181dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Metric | |
module Formula | |
class Nps < Base | |
end | |
end | |
end | |
module Metric | |
module Formula | |
class AverageScore < Base | |
def build | |
end | |
private | |
def build_filters(filters) | |
end | |
end | |
end | |
end | |
module Metric | |
module Formula | |
class Base | |
end | |
end | |
end | |
module Metric | |
class Builder | |
def initialize(formula, params) | |
@formula = formula | |
@filters = params[:filters] | |
@group_by = params[:group_by] | |
@timeseries = params[:timeseries] | |
end | |
def build | |
add_formula(@formula) | |
add_filters | |
group_by | |
with_timeseries | |
split_by_date | |
self | |
end | |
private | |
end | |
end | |
module Metric | |
class MetricFactory | |
def initialize(type, params) | |
@type = type | |
@params = params | |
end | |
def data | |
result = builder.execute | |
formatter.call(result) | |
end | |
private | |
def formatter | |
# check shiich one you need | |
Metric::Formatter.new | |
end | |
def builder | |
return @builder if @builder | |
@formula = build_formula(@type, @params[:params]) | |
@builder = Metric::Builer.new(@formula, builder_params) | |
end | |
def build_formula(type, formula_params) | |
formula_class = "Metric::Formula::#{type.to_s.camelize}" if name.to_sym.in?(BUILTIN_FORMULAE) | |
(formula_class || "Metric::Formula::Custom").constantize.new(formula_params) | |
end | |
end | |
end | |
metric = Metric::MetricFactory.new(:nps, params) | |
metric.data # => already formatted data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment