2
我想對一系列值的組合進行一些分析。帶解析的範圍問題
我有以下的功能,但由於某些原因,經過推導完成,並在函數體結束,該變量analytics
仍然是一個空的列表,而這不是在每次迭代
有什麼建議嗎?
def handle_cast({:start}, state) do
intervals = [7, 30, 90]
groupings = ["day_of_week", "time_of_day"]
aggregators = [
%{
domain: "support",
metric: "new_conversations",
func: &App.get_new_conversations/2
},
%{
domain: "support",
metric: "closed_conversations",
func: &App.get_closed_conversations/2
},
%{
domain: "support",
metric: "median_response_time",
func: &App.get_median_response_time/2
},
]
Repo.transaction(fn ->
Repo.delete_all(Analytic)
analytics = []
for interval <- intervals do
for grouping <- groupings do
for %{domain: domain, metric: metric, func: func} <- aggregators do
analytic =
func.(grouping, interval)
|> Enum.map(fn %{"app_id" => app_id, "data" => data} = result ->
%Analytic{app_id: app_id, domain: domain, metric: metric, grouping: grouping, interval_in_days: interval, data: data}
end)
analytics = [analytic|analytics]
end
end
end
end)
{:noreply, state}
end
完美,非常感謝! – Tarlen