Commit 457c2dd6 authored by Peter van der meulen's avatar Peter van der meulen

Clean up reporting to make space for more reports 1/2

parent 2263af18
Pipeline #146 passed with stage
in 1 minute and 35 seconds
defmodule AuroraBot.Report.Live do
@moduledoc """
Live reports
This module serves to create reports from collected Live metrics and live
weather. It outputs the live report to:
- A json file that can be found at `/public/aurora_data.json`.
- A slack report when aurora's can be seen and when the time is between
19:00 and 23:59.
The main executor of this report is `run!()`. plain reports (without json or
Slack output can be generated through `create!()`
"""
alias AuroraBot.LiveMetrics
alias AuroraBot.Weather
alias AuroraBot.Report.Store
alias AuroraBot.Report.Slack
alias __MODULE__
@derive {Jason.Encoder, only: [:updated_at, :kp, :clouds, :chances]}
defstruct updated_at: nil, kp: nil, clouds: %{}, chances: %{}
@doc """
Generates a new report based on live data
## example:
iex> create_live!()
%AuroraBot.Report.Live{
clouds: %{harnosand: 83, ostersund: 35, sundsvall: 68, umea: 90},
kp: 0,
updated_at: #DateTime<2018-11-12 20:41:47.931814Z>
}
"""
def create! do
pkp_and_chances = LiveMetrics.get_kp_and_chances()
%Live{
updated_at: Timex.now(),
kp: pkp_and_chances.kp,
clouds: Weather.get_clouds(),
chances: pkp_and_chances.city_chances
}
end
@doc """
Generates a new report and safes it to different outlets like a JSON and
TXT end point as well as pings to Slack.
## example:
iex> run!()
:ok
"""
def run! do
report = create!()
Store.to_files(report)
Slack.run!(report)
:ok
end
end
......@@ -7,51 +7,34 @@ defmodule AuroraBot.Report do
html file sitting on the disk.
"""
alias AuroraBot.LiveMetrics
alias AuroraBot.Weather
alias AuroraBot.Report.Store
alias AuroraBot.Report.Slack
alias __MODULE__
@derive {Jason.Encoder, only: [:updated_at, :kp, :clouds, :chances]}
defstruct updated_at: nil, kp: nil, clouds: %{}, chances: %{}
alias AuroraBot.Report.Live
@doc """
Generates a new report based on live data
## example:
iex> generate!()
%AuroraBot.Report{
iex> create_live!()
%AuroraBot.Report.Live{
clouds: %{harnosand: 83, ostersund: 35, sundsvall: 68, umea: 90},
kp: 0,
updated_at: #DateTime<2018-11-12 20:41:47.931814Z>
}
"""
def generate_live! do
pkp_and_chances = LiveMetrics.get_kp_and_chances()
%Report{
updated_at: Timex.now(),
kp: pkp_and_chances.kp,
clouds: Weather.get_clouds(),
chances: pkp_and_chances.city_chances
}
def create_live! do
Live.create!()
end
@doc """
Generates a new report and safes it to different outlets like a JSON and
TXT end point as well as pings to Slack (WIP) and pings to a RabbitMQ queue (TODO)
TXT end point as well as pings to Slack.
## example:
iex> full_run!()
iex> run_live!()
:ok
"""
def live_run! do
report = generate_live!()
Store.to_files(report)
Slack.run!(report)
:ok
def run_live! do
Live.run!()
end
end
......@@ -2,7 +2,7 @@ defmodule ReportSpec do
use ESpec
alias AuroraBot.Report
describe "live_run!" do
describe "run_live!" do
it "runs without issues" do
# Mock incoming data and caches
mock_cache()
......@@ -16,8 +16,8 @@ defmodule ReportSpec do
# Storing data to public
mock_file_store()
expect Report.live_run!() |> to(eq :ok)
expect fn -> Report.live_run!() end |> to_not(raise_exception())
expect Report.run_live!() |> to(eq :ok)
expect fn -> Report.run_live!() end |> to_not(raise_exception())
end
end
......
Markdown is supported
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