Commit fa5dc51f authored by Krister Viirsaar's avatar Krister Viirsaar
Browse files

Populate /example data

parent a2a6954f
Pipeline #142817999 passed with stages
in 8 minutes and 5 seconds
......@@ -15,7 +15,8 @@ config :bashboard, Bashboard.Scheduler,
debug_logging: false,
jobs: [
{{:extended, "*/10"}, {Bashboard.Dogfood, :system_info_running, []}},
{"@reboot", {Bashboard.Dogfood, :system_info_once, []}}
{"@reboot", {Bashboard.Dogfood, :system_info_once, []}},
{"@reboot", {Bashboard.ExampleData, :populate, []}}
]
config :bashboard, :environment, :dev
......@@ -19,7 +19,8 @@ config :bashboard, Bashboard.Scheduler,
debug_logging: false,
jobs: [
{{:extended, "*/1"}, {Bashboard.Dogfood, :system_info_running, []}},
{"@reboot", {Bashboard.Dogfood, :system_info_once, []}}
{"@reboot", {Bashboard.Dogfood, :system_info_once, []}},
{"@reboot", {Bashboard.ExampleData, :populate, []}}
]
config :bashboard, :environment, :prod
......@@ -43,16 +43,11 @@ defmodule Bashboard.ContinuousAggregator do
PubSub.publish(:cagg, {:cagg, :done})
end
def minute() do
end
def hour() do
end
def day() do
end
def month() do
def get_combinations() do
for t <- @transforms,
b <- @buckets do
"messages_#{t}_#{b}"
end
end
defp update_query(transform, bucket, source_table) do
......
defmodule Bashboard.ExampleData do
import Ecto.Query
alias Bashboard.Repo, as: Repo
alias Bashboard.Message, as: Message
@user "examples"
def populate() do
delete_old()
data = gen_data()
[
last: data,
series: [
numbers: data.numbers,
maps: data.maps
],
timeseries: [
{"numbers-sum-minute", data.numbers},
{"maps-sum-hour", data.maps},
{"strings-sum-month", data.numbers}
],
avg: [
{"numbers-minute", data.numbers},
{"maps-minute", data.maps}
],
sum: [
{"numbers-minute", data.numbers},
{"maps-minute", data.maps}
],
categorize: [
{"strings-minute", data.strings}
],
count: [
{"numbers-minute", data.numbers},
{"strings-hour", data.strings},
{"maps-day", data.maps}
]
]
|> save_batch()
end
defp save_batch(agg_list, interval \\ 30) do
latest_dt = Timex.now()
for {agg, type_list} <- agg_list,
{type, body_list} <- type_list,
{body, index} <-
Enum.with_index(body_list) do
%{
user: @user,
dash: Atom.to_string(agg),
widget: if(is_atom(type), do: Atom.to_string(type), else: type),
body: body,
inserted_at:
Timex.shift(latest_dt, seconds: interval * index)
|> DateTime.truncate(:second)
}
end
|> (&Repo.insert_all(Message, &1)).()
end
defp delete_old do
for table <- Bashboard.ContinuousAggregator.get_combinations() ++ [Message] do
from(m in table,
where: m.user == ^@user
)
|> Repo.delete_all()
end
end
defp gen_data do
%{
numbers: Enum.map(1..30, fn _ -> :rand.uniform(10) end),
strings: ["home", "examples", "price", "price", "home", "price"],
maps:
Enum.map(1..15, fn _ ->
%{price: Enum.random(1..10), amount: Enum.random(1..10), age: Enum.random(18..30)}
end)
}
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment