Skip to content

Commit

Permalink
Fix aggregations in Metric.Helper
Browse files Browse the repository at this point in the history
Use Map.put/2 instead of Map.put_new/3 in order to respect the order of
the modules. The Clickhouse.MetricAdapter must take precedence over the
SocialData.MetricAdapter
  • Loading branch information
IvanIvanoff committed Nov 13, 2024
1 parent 3bdedb9 commit 6def5f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/sanbase/metric/helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ defmodule Sanbase.Metric.Helper do
# If there is a metric that has a different set of aggregations compared to
# the other metrics in the module, this needs to be reworked to call
# module.metadata(metric)
Map.put_new(acc, metric, [nil] ++ module.available_aggregations())
Map.put(acc, metric, [nil] ++ module.available_aggregations())
end
end

Expand Down Expand Up @@ -199,7 +199,7 @@ defmodule Sanbase.Metric.Helper do
metric <- module.available_metrics(),
reduce: %{} do
acc ->
Map.put_new(acc, metric, module)
Map.put(acc, metric, module)
end
end

Expand All @@ -218,7 +218,7 @@ defmodule Sanbase.Metric.Helper do
metric <- module.available_timeseries_metrics(),
reduce: %{} do
acc ->
Map.put_new(acc, metric, module)
Map.put(acc, metric, module)
end
end

Expand All @@ -237,7 +237,7 @@ defmodule Sanbase.Metric.Helper do
metric <- module.available_histogram_metrics(),
reduce: %{} do
acc ->
Map.put_new(acc, metric, module)
Map.put(acc, metric, module)
end
end

Expand All @@ -256,7 +256,7 @@ defmodule Sanbase.Metric.Helper do
metric <- module.available_table_metrics(),
reduce: %{} do
acc ->
Map.put_new(acc, metric, module)
Map.put(acc, metric, module)
end
end

Expand Down
11 changes: 9 additions & 2 deletions lib/sanbase/social_data/metric_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Sanbase.SocialData.MetricAdapter do
alias Sanbase.SocialData.SocialHelper
alias Sanbase.Project

@aggregations [:sum]
@aggregations [:sum, :avg]
@sources ["total"] ++ SocialHelper.sources()
@social_volume_timeseries_metrics ["nft_social_volume"] ++
Enum.map(@sources, fn source ->
Expand Down Expand Up @@ -323,13 +323,20 @@ defmodule Sanbase.SocialData.MetricAdapter do
_ -> "5m"
end

default_aggregation =
cond do
String.contains?(metric, "social_dominance") -> :avg
String.contains?(metric, "volume_consumed") -> :avg
true -> :sum
end

{:ok,
%{
metric: metric,
internal_metric: metric,
has_incomplete_data: has_incomplete_data?(metric),
min_interval: min_interval,
default_aggregation: :sum,
default_aggregation: default_aggregation,
available_aggregations: @aggregations,
available_selectors: selectors,
required_selectors: [],
Expand Down

0 comments on commit 6def5f9

Please sign in to comment.