move storage and api to apps, create base analyzer

This commit is contained in:
2024-05-10 06:08:25 +02:00
parent 987339f517
commit 2e56c7105b
42 changed files with 403 additions and 48 deletions
@@ -0,0 +1,3 @@
defmodule LolAnalytics.Analyzer.BaseAnalyzer do
@callback analyze(:url, path :: String.t()) :: :ok
end
@@ -0,0 +1,32 @@
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
alias Hex.HTTP
@behaviour LolAnalytics.Analyzer.BaseAnalyzer
@doc """
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "https://na1.api.riotgames.com/lol/match/v4/match/234567890123456789")
:ok
"""
@impl true
@spec analyze(atom(), String.t()) :: :ok
def analyze(:url, path) do
data = HTTPoison.get!(path)
analyze(:data, data.body)
:ok
end
@doc """
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/14.9.580.2108/EUW1_6923309745.json")
"""
@impl true
@spec analyze(atom(), any()) :: list(LoLAPI.Model.Participant.t())
def analyze(:data, data) do
decoded = Poison.decode!(data)
%{"info" => %{"participants" => participants}} = decoded
participants
|> Enum.each(fn %{"win" => win, "championId" => champion_id} ->
IO.inspect(%{win: win, champion_id: champion_id})
end)
end
end
@@ -15,7 +15,9 @@ defmodule LolAnalytics.Player.PlayerRepo do
def get_player(puuid) do
query = from p in PlayerSchema, where: p.puuid == ^puuid
LoLAnalytics.Repo.one(query)
LoLAnalytics.Repo.all(query)
|> List.first()
end
@spec insert_player(String.t(), keyword()) :: %PlayerSchema{}
+4 -1
View File
@@ -40,7 +40,10 @@ defmodule LoLAnalytics.MixProject do
{:phoenix_pubsub, "~> 2.1"},
{:ecto_sql, "~> 3.10"},
{:postgrex, ">= 0.0.0"},
{:jason, "~> 1.2"}
{:jason, "~> 1.2"},
{:lol_api, in_umbrella: true},
{:httpoison, "~> 2.2"},
{:poison, "~> 5.0"}
]
end
@@ -10,6 +10,7 @@ defmodule LoLAnalytics.Repo.Migrations.Player do
timestamps()
end
unique_index("player", :puuid)
create index(:player, [:puuid])
end
end