Fix warnings, remove analyzers and create fact for champion played game
All checks were successful
ci / docker (push) Successful in 7m38s
All checks were successful
ci / docker (push) Successful in 7m38s
This commit is contained in:
parent
fe3d040978
commit
6dd8eea3d3
@ -1,3 +0,0 @@
|
||||
defmodule LolAnalytics.Analyzer do
|
||||
@callback analyze(:url, path :: String.t()) :: :ok
|
||||
end
|
@ -1,56 +0,0 @@
|
||||
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
||||
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
||||
@behaviour LolAnalytics.Analyzer
|
||||
|
||||
def analyze_all_matches do
|
||||
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
||||
|> Enum.each(fn %{key: path} ->
|
||||
LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://192.168.1.55:9000/ranked/#{path}")
|
||||
end)
|
||||
|
||||
# Storage.MatchStorage.S3MatchStorage.list_files("ranked")
|
||||
# |> Enum.map(& &1.key)
|
||||
# |> Enum.each(fn path ->
|
||||
# LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/#{path}")
|
||||
# end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/14.9.580.2108/EUW1_6923309745.json")
|
||||
"""
|
||||
@impl true
|
||||
def analyze(:url, path) do
|
||||
data = HTTPoison.get!(path)
|
||||
analyze(:data, data.body)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def analyze(:data, data) do
|
||||
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
|
||||
participants = decoded_match.info.participants
|
||||
version = extract_game_version(decoded_match)
|
||||
|
||||
participants
|
||||
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
||||
if participant.teamPosition != "" do
|
||||
attrs = %{
|
||||
champion_id: participant.championId,
|
||||
match_id: decoded_match.metadata.matchId,
|
||||
is_win: participant.win,
|
||||
game_length_seconds: decoded_match.info.gameDuration,
|
||||
queue_id: decoded_match.info.queueId,
|
||||
puuid: participant.puuid,
|
||||
team_position: participant.teamPosition
|
||||
}
|
||||
LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.insert(attrs)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
defp extract_game_version(game_data) do
|
||||
game_data.info.gameVersion
|
||||
|> String.split(".")
|
||||
|> Enum.take(2)
|
||||
|> Enum.join(".")
|
||||
end
|
||||
end
|
@ -46,7 +46,7 @@ defmodule LolAnalytics.ChampionWinRate.ChampionWinRateRepo do
|
||||
Repo.all(ChampionWinRateSchema)
|
||||
end
|
||||
|
||||
def get_champion_win_rate(champion_id, patch) do
|
||||
def get_champion_win_rate(champion_id, _patch) do
|
||||
champion_query =
|
||||
from cwr in LolAnalytics.ChampionWinRate.ChampionWinRateSchema,
|
||||
where: cwr.champion_id == ^champion_id
|
||||
|
@ -2,8 +2,6 @@ defmodule LolAnalytics.Dimensions.Champion.ChampionMetadata do
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
||||
@champions_data_url "https://ddragon.leagueoflegends.com/cdn/14.11.1/data/en_US/champion.json"
|
||||
|
||||
use GenServer
|
||||
|
||||
def update_metadata() do
|
||||
{:ok, %{"data" => data}} = get_champions()
|
||||
|
||||
@ -20,7 +18,7 @@ defmodule LolAnalytics.Dimensions.Champion.ChampionMetadata do
|
||||
end
|
||||
end
|
||||
|
||||
defp save_metadata({champion, info}) do
|
||||
defp save_metadata({_champion, info}) do
|
||||
%{
|
||||
"image" => %{
|
||||
"full" => full_image
|
||||
|
@ -1,6 +1,4 @@
|
||||
defmodule LolAnalytics.Dimensions.Champion.ChampionRepo do
|
||||
import Ecto.Query
|
||||
|
||||
alias LoLAnalytics.Repo
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
||||
|
||||
|
@ -1,28 +1,28 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo do
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
||||
import Ecto.Query
|
||||
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
||||
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
||||
alias LolAnalytics.Dimensions.Match.MatchRepo
|
||||
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
||||
alias LolAnalytics.Facts.ChampionPlayedGame.Schema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
def insert(attrs) do
|
||||
_match = MatchRepo.get_or_create(attrs.match_id)
|
||||
_champion = ChampionRepo.get_or_create(attrs.champion_id)
|
||||
_player = PlayerRepo.get_or_create(attrs.puuid)
|
||||
changeset = ChampionPlayedGameSchema.changeset(%ChampionPlayedGameSchema{}, attrs)
|
||||
changeset = Schema.changeset(%Schema{}, attrs)
|
||||
Repo.insert(changeset)
|
||||
end
|
||||
|
||||
def list_played_matches() do
|
||||
Repo.all(ChampionPlayedGameSchema)
|
||||
Repo.all(Schema)
|
||||
end
|
||||
|
||||
def get_win_rates do
|
||||
query =
|
||||
from m in ChampionPlayedGameSchema,
|
||||
from m in Schema,
|
||||
join: c in ChampionSchema,
|
||||
on: c.champion_id == m.champion_id,
|
||||
select: %{
|
||||
|
@ -1,4 +1,4 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema do
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.Schema do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
@ -0,0 +1,37 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
||||
def process_game_at_url(path) do
|
||||
data = HTTPoison.get!(path)
|
||||
process_game_data(data.body)
|
||||
end
|
||||
|
||||
def process_game_data(data) do
|
||||
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
|
||||
participants = decoded_match.info.participants
|
||||
version = extract_game_version(decoded_match)
|
||||
|
||||
participants
|
||||
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
||||
if participant.teamPosition != "" do
|
||||
attrs = %{
|
||||
champion_id: participant.championId,
|
||||
match_id: decoded_match.metadata.matchId,
|
||||
is_win: participant.win,
|
||||
game_length_seconds: decoded_match.info.gameDuration,
|
||||
queue_id: decoded_match.info.queueId,
|
||||
puuid: participant.puuid,
|
||||
team_position: participant.teamPosition,
|
||||
patch_number: version
|
||||
}
|
||||
|
||||
LolAnalytics.Facts.ChampionPlayedGame.Repo.insert(attrs)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
defp extract_game_version(game_data) do
|
||||
game_data.info.gameVersion
|
||||
|> String.split(".")
|
||||
|> Enum.take(2)
|
||||
|> Enum.join(".")
|
||||
end
|
||||
end
|
22
apps/lol_analytics/lib/lol_analytics/facts/facts_runner.ex
Normal file
22
apps/lol_analytics/lib/lol_analytics/facts/facts_runner.ex
Normal file
@ -0,0 +1,22 @@
|
||||
defmodule LolAnalytics.Facts.FactsRunner do
|
||||
alias LolAnalytics.Facts
|
||||
|
||||
def analyze_all_matches do
|
||||
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
||||
|> Enum.each(fn %{key: path} ->
|
||||
get_facts()
|
||||
|> Enum.each(fn fact_runner ->
|
||||
apply(fact_runner, ["http://192.168.1.55:9000/ranked/#{path}"])
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
def analyze_match() do
|
||||
end
|
||||
|
||||
def get_facts() do
|
||||
[
|
||||
&Facts.ChampionPickedSummonerSpell.FactProcessor.process_game_at_url/1
|
||||
]
|
||||
end
|
||||
end
|
@ -13,7 +13,7 @@ defmodule LolAnalytics.Match.MatchRepo do
|
||||
LoLAnalytics.Repo.one(query)
|
||||
end
|
||||
|
||||
@spec get_match(String.t()) :: %LolAnalytics.Match.MatchSchema{}
|
||||
@spec get_match(String.t()) :: %LolAnalytics.Match.MatchSchema{} | nil
|
||||
def get_match(match_id) do
|
||||
query = from m in MatchSchema, where: m.match_id == ^match_id
|
||||
|
||||
|
@ -1,90 +0,0 @@
|
||||
defmodule LoLAnalyticsWeb.ChampionLive.FormComponent do
|
||||
use LoLAnalyticsWeb, :live_component
|
||||
|
||||
alias LoLAnalytics.Accounts
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<.header>
|
||||
<%= @title %>
|
||||
<:subtitle>Use this form to manage champion records in your database.</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.simple_form
|
||||
for={@form}
|
||||
id="champion-form"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
|
||||
<:actions>
|
||||
<.button phx-disable-with="Saving...">Save Champion</.button>
|
||||
</:actions>
|
||||
</.simple_form>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def update(%{champion: champion} = assigns, socket) do
|
||||
changeset = Accounts.change_champion(champion)
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign_form(changeset)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate", %{"champion" => champion_params}, socket) do
|
||||
changeset =
|
||||
socket.assigns.champion
|
||||
|> Accounts.change_champion(champion_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
{:noreply, assign_form(socket, changeset)}
|
||||
end
|
||||
|
||||
def handle_event("save", %{"champion" => champion_params}, socket) do
|
||||
save_champion(socket, socket.assigns.action, champion_params)
|
||||
end
|
||||
|
||||
defp save_champion(socket, :edit, champion_params) do
|
||||
case Accounts.update_champion(socket.assigns.champion, champion_params) do
|
||||
{:ok, champion} ->
|
||||
notify_parent({:saved, champion})
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Champion updated successfully")
|
||||
|> push_patch(to: socket.assigns.patch)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign_form(socket, changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp save_champion(socket, :new, champion_params) do
|
||||
case Accounts.create_champion(champion_params) do
|
||||
{:ok, champion} ->
|
||||
notify_parent({:saved, champion})
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Champion created successfully")
|
||||
|> push_patch(to: socket.assigns.patch)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign_form(socket, changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
|
||||
assign(socket, :form, to_form(changeset))
|
||||
end
|
||||
|
||||
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||
end
|
@ -13,7 +13,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
champs = LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.get_win_rates()
|
||||
champs = LolAnalytics.Facts.ChampionPlayedGame.Repo.get_win_rates()
|
||||
|
||||
mapped =
|
||||
champs
|
||||
@ -73,7 +73,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
|
||||
end
|
||||
|
||||
champs =
|
||||
LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.get_win_rates()
|
||||
LolAnalytics.Facts.ChampionPlayedGame.Repo.get_win_rates()
|
||||
|> Enum.filter(fn %{name: name} ->
|
||||
String.downcase(name) |> String.contains?(query_name)
|
||||
end)
|
||||
@ -93,10 +93,6 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
|
||||
)}
|
||||
end
|
||||
|
||||
def handle_event("filter", unsigned_params, socket) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
@ -108,9 +104,4 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
|
||||
|
||||
# |> assign(:champion, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({LoLAnalyticsWeb.ChampionLive.FormComponent, {:saved, champion}}, socket) do
|
||||
{:noreply, stream_insert(socket, :champions, champion)}
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,6 @@
|
||||
defmodule LoLAnalyticsWeb.ChampionLive.Show do
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
alias LoLAnalytics.Accounts
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket}
|
||||
@ -13,7 +11,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Show do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:champion, Accounts.get_champion!(id))}
|
||||
|> assign(:champion, %{id: id})}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Champion"
|
||||
|
@ -1,25 +1,7 @@
|
||||
<.header>
|
||||
Champion <%= @champion.id %>
|
||||
<:subtitle>This is a champion record from your database.</:subtitle>
|
||||
<:actions>
|
||||
<.link patch={~p"/champions/#{@champion}/show/edit"} phx-click={JS.push_focus()}>
|
||||
<.button>Edit champion</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
<:actions></:actions>
|
||||
</.header>
|
||||
|
||||
<.list>
|
||||
</.list>
|
||||
|
||||
<.back navigate={~p"/champions"}>Back to champions</.back>
|
||||
|
||||
<.modal :if={@live_action == :edit} id="champion-modal" show on_cancel={JS.patch(~p"/champions/#{@champion}")}>
|
||||
<.live_component
|
||||
module={LoLAnalyticsWeb.ChampionLive.FormComponent}
|
||||
id={@champion.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
champion={@champion}
|
||||
patch={~p"/champions/#{@champion}"}
|
||||
/>
|
||||
</.modal>
|
||||
|
@ -1,8 +1,6 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
|
||||
use LoLAnalyticsWeb, :live_component
|
||||
|
||||
alias LoLAnalytics.Accounts
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
@ -19,7 +17,6 @@ defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
|
||||
<:actions>
|
||||
<.button phx-disable-with="Saving...">Save Role</.button>
|
||||
</:actions>
|
||||
@ -27,64 +24,4 @@ defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def update(%{role: role} = assigns, socket) do
|
||||
changeset = Accounts.change_role(role)
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign_form(changeset)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate", %{"role" => role_params}, socket) do
|
||||
changeset =
|
||||
socket.assigns.role
|
||||
|> Accounts.change_role(role_params)
|
||||
|> Map.put(:action, :validate)
|
||||
|
||||
{:noreply, assign_form(socket, changeset)}
|
||||
end
|
||||
|
||||
def handle_event("save", %{"role" => role_params}, socket) do
|
||||
save_role(socket, socket.assigns.action, role_params)
|
||||
end
|
||||
|
||||
defp save_role(socket, :edit, role_params) do
|
||||
case Accounts.update_role(socket.assigns.role, role_params) do
|
||||
{:ok, role} ->
|
||||
notify_parent({:saved, role})
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Role updated successfully")
|
||||
|> push_patch(to: socket.assigns.patch)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign_form(socket, changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp save_role(socket, :new, role_params) do
|
||||
case Accounts.create_role(role_params) do
|
||||
{:ok, role} ->
|
||||
notify_parent({:saved, role})
|
||||
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Role created successfully")
|
||||
|> push_patch(to: socket.assigns.patch)}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign_form(socket, changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
|
||||
assign(socket, :form, to_form(changeset))
|
||||
end
|
||||
|
||||
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
|
||||
end
|
||||
|
@ -1,9 +1,6 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLive.Index do
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
alias LoLAnalytics.Accounts
|
||||
alias LoLAnalytics.Accounts.Role
|
||||
|
||||
@roles ["ALL", "TOP", "MIDDLE", "JUNGLE", "UTILITY", "BOTTOM"]
|
||||
|
||||
@impl true
|
||||
|
@ -1,40 +1,4 @@
|
||||
<.header>
|
||||
Listing Roles
|
||||
<:actions>
|
||||
<.link patch={~p"/roles/new"}>
|
||||
<.button>New Role</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
<:actions></:actions>
|
||||
</.header>
|
||||
|
||||
<.table
|
||||
id="roles"
|
||||
rows={@streams.roles}
|
||||
row_click={fn {_id, role} -> JS.navigate(~p"/roles/#{role}") end}
|
||||
>
|
||||
<:action :let={{_id, role}}>
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/roles/#{role}"}>Show</.link>
|
||||
</div>
|
||||
<.link patch={~p"/roles/#{role}/edit"}>Edit</.link>
|
||||
</:action>
|
||||
<:action :let={{id, role}}>
|
||||
<.link
|
||||
phx-click={JS.push("delete", value: %{id: role.id}) |> hide("##{id}")}
|
||||
data-confirm="Are you sure?"
|
||||
>
|
||||
Delete
|
||||
</.link>
|
||||
</:action>
|
||||
</.table>
|
||||
|
||||
<.modal :if={@live_action in [:new, :edit]} id="role-modal" show on_cancel={JS.patch(~p"/roles")}>
|
||||
<.live_component
|
||||
module={LoLAnalyticsWeb.RoleLive.FormComponent}
|
||||
id={@role.id || :new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
role={@role}
|
||||
patch={~p"/roles"}
|
||||
/>
|
||||
</.modal>
|
||||
|
@ -1,19 +1,16 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLive.Show do
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
alias LoLAnalytics.Accounts
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
def handle_params(%{"id" => _id}, _, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:role, Accounts.get_role!(id))}
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Role"
|
||||
|
@ -1,25 +1,7 @@
|
||||
<.header>
|
||||
Role <%= @role.id %>
|
||||
<:subtitle>This is a role record from your database.</:subtitle>
|
||||
<:actions>
|
||||
<.link patch={~p"/roles/#{@role}/show/edit"} phx-click={JS.push_focus()}>
|
||||
<.button>Edit role</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
<:actions></:actions>
|
||||
</.header>
|
||||
|
||||
<.list>
|
||||
</.list>
|
||||
|
||||
<.back navigate={~p"/roles"}>Back to roles</.back>
|
||||
|
||||
<.modal :if={@live_action == :edit} id="role-modal" show on_cancel={JS.patch(~p"/roles/#{@role}")}>
|
||||
<.live_component
|
||||
module={LoLAnalyticsWeb.RoleLive.FormComponent}
|
||||
id={@role.id}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
role={@role}
|
||||
patch={~p"/roles/#{@role}"}
|
||||
/>
|
||||
</.modal>
|
||||
|
@ -18,7 +18,7 @@ defmodule LoLAPI.AccountApi do
|
||||
200 ->
|
||||
{:ok, Poison.decode(response.body)}
|
||||
|
||||
code ->
|
||||
_code ->
|
||||
Logger.error("Error getting puuid from player #{name} \##{tag}")
|
||||
{:err, response.status_code}
|
||||
end
|
||||
|
@ -1,11 +1,6 @@
|
||||
defmodule Scrapper.MatchClassifier do
|
||||
require Logger
|
||||
|
||||
@spec classify_match(%LoLAPI.Model.MatchResponse{}) :: nil
|
||||
def classify_match(match = %LoLAPI.Model.MatchResponse{}) do
|
||||
classify_match_by_queue(match.info.queueId)
|
||||
end
|
||||
|
||||
def stream_classify_matches_by_queue(queue \\ 420, bucket \\ "ranked") do
|
||||
Storage.MatchStorage.S3MatchStorage.stream_files("matches")
|
||||
|> Stream.each(fn match ->
|
||||
@ -28,35 +23,4 @@ defmodule Scrapper.MatchClassifier do
|
||||
match
|
||||
end)
|
||||
end
|
||||
|
||||
@spec classify_match_by_queue(String.t()) :: nil
|
||||
def classify_match_by_queue("420") do
|
||||
matches = Storage.MatchStorage.S3MatchStorage.list_files("matches")
|
||||
total_matches = Enum.count(matches)
|
||||
|
||||
matches
|
||||
|> Enum.with_index(fn match, index -> {match, index} end)
|
||||
|> Scrapper.Parallel.peach(fn {match, index} ->
|
||||
%{key: json_file} = match
|
||||
[key | _] = String.split(json_file, ".")
|
||||
|
||||
response =
|
||||
HTTPoison.get!("http://#{System.get_env("EX_AWS_ENDPOINT")}:9000/matches/#{key}.json", [],
|
||||
timeout: 5000
|
||||
)
|
||||
|
||||
%{"info" => %{"gameVersion" => gameVersion, "queueId" => queueId}} =
|
||||
Poison.decode!(response.body)
|
||||
|
||||
if queueId == 420 do
|
||||
Storage.MatchStorage.S3MatchStorage.store_match(key, response.body, "ranked", gameVersion)
|
||||
Logger.info("Match at #{index} of #{total_matches} is classified")
|
||||
end
|
||||
|
||||
match
|
||||
end)
|
||||
end
|
||||
|
||||
def classify_match_by_queue(_) do
|
||||
end
|
||||
end
|
||||
|
@ -66,6 +66,6 @@ defmodule Scrapper.Processor.MatchProcessor do
|
||||
end)
|
||||
end
|
||||
|
||||
def process_resp({:err, code}, match_id) do
|
||||
def process_resp({:err, _code}, _match_id) do
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,4 @@
|
||||
defmodule Scrapper.Processor.PlayerProcessor do
|
||||
alias Calendar.ISO
|
||||
use Broadway
|
||||
|
||||
def start_link(_opts) do
|
||||
|
@ -19,7 +19,7 @@ defmodule Scrapper.Queue.MatchQueue do
|
||||
LolAnalytics.Match.MatchRepo.get_match(match_id)
|
||||
|> case do
|
||||
nil -> GenServer.call(__MODULE__, {:queue_match, match_id})
|
||||
match -> :already_processed
|
||||
_match -> :already_processed
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
defmodule Storage.MatchStorage do
|
||||
@callback stream_files(String.t()) :: Enumerable.t()
|
||||
@callback get_match(String.t()) :: {:ok, Scrapper.Data.Match.t()} | {:error, :not_found}
|
||||
@callback save_match(String.t(), Scrapper.Data.Match.t()) :: :ok
|
||||
@callback list_matches() :: [map()]
|
||||
@callback store_match(match_id :: String.t(), match :: map(), path :: String.t()) :: String.t()
|
||||
@callback store_match(match_id :: String.t(), match_data :: String.t(), path :: String.t()) ::
|
||||
String.t()
|
||||
@callback store_match(
|
||||
match_id :: String.t(),
|
||||
match_data :: String.t(),
|
||||
bucket :: String.t(),
|
||||
path :: String.t()
|
||||
) ::
|
||||
String.t()
|
||||
end
|
||||
|
@ -2,50 +2,16 @@ defmodule Storage.MatchStorage.S3MatchStorage do
|
||||
require Logger
|
||||
@behaviour Storage.MatchStorage
|
||||
|
||||
def get_match(match_id) do
|
||||
""
|
||||
@impl true
|
||||
def get_match(_match_id) do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def stream_files(path) do
|
||||
ExAws.S3.list_objects_v2(path)
|
||||
|> ExAws.stream!()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Lists all files at the given path.
|
||||
|
||||
iex > Storage.MatchStorage.S3MatchStorage.list_files("matches")
|
||||
"""
|
||||
@impl true
|
||||
def list_files(path) do
|
||||
{:ok, %{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} =
|
||||
ExAws.S3.list_objects_v2(path)
|
||||
|> ExAws.request()
|
||||
|
||||
if next_continuation_token do
|
||||
list_files(path, contents, next_continuation_token)
|
||||
# |> Enum.map(fn %{key: key} -> key end)
|
||||
else
|
||||
contents
|
||||
# |> Enum.map(fn %{key: key} -> key end)
|
||||
end
|
||||
end
|
||||
|
||||
@spec list_files(String.t(), list(String.t()), String.t()) :: list(String.t())
|
||||
defp list_files(path, acc, continuation_token) do
|
||||
resp =
|
||||
{:ok,
|
||||
%{:body => %{:contents => contents, next_continuation_token: next_continuation_token}}} =
|
||||
ExAws.S3.list_objects_v2(path, continuation_token: continuation_token)
|
||||
|> ExAws.request()
|
||||
|
||||
if next_continuation_token == "" do
|
||||
acc ++ contents
|
||||
else
|
||||
list_files(path, acc ++ contents, next_continuation_token)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
iex> Scrapper.Storage.S3MatchStorage.store_match "1", "content", "matches"
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user