Compare commits
11 Commits
deploy
...
3ef7861f22
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ef7861f22 | |||
| 968c2634b7 | |||
| 6dd8eea3d3 | |||
| fe3d040978 | |||
| 9b955641d0 | |||
| 77b292e47e | |||
| 22b79f5376 | |||
| 520c234a94 | |||
| dacb9ad8fc | |||
| 6053cfcdac | |||
| 5ce7ce0542 |
@@ -1,3 +0,0 @@
|
||||
defmodule LolAnalytics.Analyzer do
|
||||
@callback analyze(:url, path :: String.t()) :: :ok
|
||||
end
|
||||
@@ -1,50 +0,0 @@
|
||||
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
||||
alias Hex.HTTP
|
||||
@behaviour LolAnalytics.Analyzer
|
||||
|
||||
def analyze_all_matches do
|
||||
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
|
||||
@spec analyze(atom(), String.t()) :: :ok
|
||||
def analyze(:url, path) do
|
||||
data = HTTPoison.get!(path)
|
||||
analyze(:data, data.body)
|
||||
:ok
|
||||
end
|
||||
|
||||
@impl true
|
||||
@spec analyze(atom(), any()) :: list(LoLAPI.Model.Participant.t())
|
||||
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
|
||||
LolAnalytics.ChampionWinRate.ChampionWinRateRepo.add_champion_win_rate(
|
||||
participant.championId,
|
||||
version,
|
||||
participant.teamPosition,
|
||||
participant.win
|
||||
)
|
||||
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
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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"
|
||||
|
||||
def update_metadata() do
|
||||
{:ok, %{"data" => data}} = get_champions()
|
||||
|
||||
data
|
||||
|> Enum.each(&save_metadata/1)
|
||||
end
|
||||
|
||||
defp get_champions() do
|
||||
with {:ok, resp} <- HTTPoison.get(@champions_data_url),
|
||||
data <- Poison.decode(resp.body) do
|
||||
data
|
||||
else
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
end
|
||||
|
||||
defp save_metadata({_champion, info}) do
|
||||
%{
|
||||
"image" => %{
|
||||
"full" => full_image
|
||||
},
|
||||
"name" => name,
|
||||
"key" => key_string
|
||||
} = info
|
||||
|
||||
attrs = %{
|
||||
image: full_image,
|
||||
name: name
|
||||
}
|
||||
|
||||
{champion_id, _} = Integer.parse(key_string)
|
||||
|
||||
ChampionRepo.update(champion_id, attrs)
|
||||
|
||||
info
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
defmodule LolAnalytics.Dimensions.Champion.ChampionRepo do
|
||||
alias LoLAnalytics.Repo
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
||||
|
||||
@spec get_or_create(String.t()) :: struct()
|
||||
def get_or_create(champion_id) do
|
||||
champion = Repo.get_by(ChampionSchema, champion_id: champion_id)
|
||||
|
||||
case champion do
|
||||
nil ->
|
||||
changeset = ChampionSchema.changeset(%ChampionSchema{}, %{champion_id: champion_id})
|
||||
Repo.insert(changeset)
|
||||
|
||||
champion ->
|
||||
champion
|
||||
end
|
||||
end
|
||||
|
||||
def update(champion_id, attrs) do
|
||||
get_or_create(champion_id)
|
||||
|> ChampionSchema.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@spec list_champions() :: any()
|
||||
def list_champions() do
|
||||
Repo.all(ChampionSchema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
defmodule LolAnalytics.Dimensions.Champion.ChampionSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_champion" do
|
||||
field :champion_id, :integer
|
||||
field :name, :string
|
||||
field :image, :string
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(champion = %__MODULE__{}, attrs \\ %{}) do
|
||||
champion
|
||||
|> cast(attrs, [:champion_id, :name, :image])
|
||||
|> validate_required([:champion_id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
defmodule LolAnalytics.Dimensions.Item.ItemRepo do
|
||||
alias LolAnalytics.Dimensions.Item.ItemSchema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
def get_or_create(item_id) do
|
||||
item = Repo.get(ItemSchema, item_id: item_id)
|
||||
|
||||
case item do
|
||||
nil ->
|
||||
item_changeset = ItemSchema.changeset(%ItemSchema{}, %{item_id: item_id})
|
||||
Repo.insert(item_changeset)
|
||||
|
||||
item ->
|
||||
item
|
||||
end
|
||||
end
|
||||
|
||||
def list_items() do
|
||||
Repo.all(ItemSchema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule LolAnalytics.Dimensions.Item.ItemSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_item" do
|
||||
field :item_id, :integer
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(item = %__MODULE__{}, attrs \\ %{}) do
|
||||
item
|
||||
|> cast(attrs, [:item_id])
|
||||
|> validate_required([:item_id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
defmodule LolAnalytics.Dimensions.Match.MatchRepo do
|
||||
alias LolAnalytics.Dimensions.Match.MatchSchema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
@spec get_or_create(String.t()) :: %MatchSchema{}
|
||||
def get_or_create(match_id) do
|
||||
query = from m in MatchSchema, where: m.match_id == ^match_id
|
||||
match = Repo.one(query)
|
||||
|
||||
case match do
|
||||
nil ->
|
||||
match_changeset =
|
||||
MatchSchema.changeset(
|
||||
%MatchSchema{},
|
||||
%{match_id: match_id}
|
||||
)
|
||||
|
||||
Repo.insert(match_changeset)
|
||||
|
||||
match ->
|
||||
match
|
||||
end
|
||||
end
|
||||
|
||||
def list_matches() do
|
||||
Repo.all(MatchSchema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule LolAnalytics.Dimensions.Match.MatchSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_match" do
|
||||
field :match_id, :string
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(match = %__MODULE__{}, attrs \\ %{}) do
|
||||
match
|
||||
|> cast(attrs, [:match_id])
|
||||
|> validate_required([:match_id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
defmodule LolAnalytics.Dimensions.Patch.PatchRepo do
|
||||
alias LolAnalytics.Dimensions.Patch.PatchSchema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
def get_or_create(patch_number) do
|
||||
patch = Repo.get(PatchSchema, patch_number: patch_number)
|
||||
|
||||
case patch do
|
||||
nil ->
|
||||
patch_changeset =
|
||||
PatchSchema.changeset(
|
||||
%PatchSchema{},
|
||||
%{patch_number: patch_number}
|
||||
)
|
||||
|
||||
Repo.insert(patch_changeset)
|
||||
|
||||
patch ->
|
||||
patch
|
||||
end
|
||||
end
|
||||
|
||||
def list_patches() do
|
||||
Repo.all(PatchSchema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule LolAnalytics.Dimensions.Patch.PatchSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_patch" do
|
||||
field :patch_number, :string
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(patch = %__MODULE__{}, attrs \\ %{}) do
|
||||
patch
|
||||
|> cast(attrs, [:patch_number])
|
||||
|> validate_required([:patch_number])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,28 @@
|
||||
defmodule LolAnalytics.Dimensions.Player.PlayerRepo do
|
||||
import Ecto.Query
|
||||
|
||||
alias LolAnalytics.Dimensions.Player.PlayerSchema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
def get_or_create(puuid) do
|
||||
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
||||
player = Repo.one(query)
|
||||
|
||||
case player do
|
||||
nil ->
|
||||
player_changeset =
|
||||
PlayerSchema.changeset(
|
||||
%PlayerSchema{},
|
||||
%{puuid: puuid}
|
||||
)
|
||||
Repo.insert(player_changeset)
|
||||
|
||||
player ->
|
||||
player
|
||||
end
|
||||
end
|
||||
|
||||
def list_players() do
|
||||
Repo.all(PlayerSchema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule LolAnalytics.Dimensions.Player.PlayerSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_player" do
|
||||
field :puuid, :string
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(player = %__MODULE__{}, attrs \\ %{}) do
|
||||
player
|
||||
|> cast(attrs, [:puuid])
|
||||
|> validate_required([:puuid])
|
||||
end
|
||||
end
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellMetadata do
|
||||
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo
|
||||
@spells_url "https://ddragon.leagueoflegends.com/cdn/14.11.1/data/en_US/summoner.json"
|
||||
|
||||
def update_metadata() do
|
||||
get_spells()
|
||||
|> Enum.each(&save_metadata/1)
|
||||
end
|
||||
|
||||
defp get_spells() do
|
||||
case HTTPoison.get(@spells_url) do
|
||||
{:ok, resp} ->
|
||||
Poison.decode!(resp.body)["data"]
|
||||
end
|
||||
end
|
||||
|
||||
defp save_metadata({name, metadata}) do
|
||||
%{"key" => spell_id} = metadata
|
||||
|
||||
SummonerSpellRepo.update(spell_id, %{metadata: metadata})
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo do
|
||||
import Ecto.Query
|
||||
|
||||
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
@spec get_or_create(String.t()) :: any()
|
||||
def get_or_create(spell_id) do
|
||||
query = from s in SummonerSpellSchema, where: s.spell_id == ^spell_id
|
||||
spell = Repo.one(query)
|
||||
|
||||
case spell do
|
||||
nil ->
|
||||
spell_changeset =
|
||||
SummonerSpellSchema.changeset(
|
||||
%SummonerSpellSchema{},
|
||||
%{spell_id: spell_id}
|
||||
)
|
||||
|
||||
Repo.insert(spell_changeset)
|
||||
|
||||
spell ->
|
||||
spell
|
||||
end
|
||||
end
|
||||
|
||||
@spec update(spell_id :: String.t(), attrs :: map()) :: any()
|
||||
def update(spell_id, attrs) do
|
||||
get_or_create(spell_id)
|
||||
|> SummonerSpellSchema.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def list_spells() do
|
||||
Repo.all(SummonerSpellSchema)
|
||||
end
|
||||
end
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_summoner_spell" do
|
||||
field :spell_id, :integer
|
||||
field :metadata, :map
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(summoner_spell = %__MODULE__{}, attrs) do
|
||||
summoner_spell
|
||||
|> cast(attrs, [:spell_id, :metadata])
|
||||
|> validate_required([:spell_id])
|
||||
end
|
||||
end
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
||||
alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
||||
|
||||
def process_game_at_url(url) do
|
||||
data = HTTPoison.get!(url)
|
||||
process_game_data(data.body)
|
||||
end
|
||||
|
||||
defp 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_spell_1 = %{
|
||||
champion_id: participant.championId,
|
||||
match_id: decoded_match.metadata.matchId,
|
||||
is_win: participant.win,
|
||||
summoner_spell_id: participant.summoner1Id,
|
||||
game_length_seconds: decoded_match.info.gameDuration,
|
||||
queue_id: decoded_match.info.queueId,
|
||||
puuid: participant.puuid,
|
||||
team_position: participant.teamPosition,
|
||||
patch_number: version
|
||||
}
|
||||
attrs_spell_2 = %{
|
||||
champion_id: participant.championId,
|
||||
match_id: decoded_match.metadata.matchId,
|
||||
is_win: participant.win,
|
||||
summoner_spell_id: participant.summoner2Id,
|
||||
game_length_seconds: decoded_match.info.gameDuration,
|
||||
queue_id: decoded_match.info.queueId,
|
||||
puuid: participant.puuid,
|
||||
team_position: participant.teamPosition,
|
||||
patch_number: version
|
||||
}
|
||||
ChampionPickedSummonerSpell.Repo.insert(attrs_spell_1)
|
||||
ChampionPickedSummonerSpell.Repo.insert(attrs_spell_2)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
defp extract_game_version(game_data) do
|
||||
game_data.info.gameVersion
|
||||
|> String.split(".")
|
||||
|> Enum.take(2)
|
||||
|> Enum.join(".")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,93 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
||||
import Ecto.Query
|
||||
|
||||
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
|
||||
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
||||
|
||||
alias LolAnalytics.Facts.ChampionPickedSummonerSpell.Schema
|
||||
|
||||
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
||||
alias LolAnalytics.Dimensions.Match.MatchRepo
|
||||
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
@type insert_attrs :: %{
|
||||
match_id: String.t(),
|
||||
champion_id: String.t(),
|
||||
puuid: String.t(),
|
||||
summoner_spell_id: :integer
|
||||
}
|
||||
|
||||
@spec insert(insert_attrs()) :: any()
|
||||
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)
|
||||
_spell = SummonerSpellRepo.get_or_create(attrs.summoner_spell_id)
|
||||
|
||||
prev =
|
||||
from(f in Schema,
|
||||
where:
|
||||
f.match_id == ^attrs.match_id and
|
||||
f.champion_id == ^attrs.champion_id and
|
||||
f.summoner_spell_id ==
|
||||
^attrs.summoner_spell_id
|
||||
)
|
||||
|> Repo.one!()
|
||||
|
||||
changeset = Schema.changeset(prev, attrs)
|
||||
|
||||
IO.inspect(attrs)
|
||||
|
||||
Repo.insert_or_update(changeset)
|
||||
|> IO.inspect()
|
||||
end
|
||||
|
||||
@spec get_champion_spells_by_win_rate(String.t()) :: list()
|
||||
def get_champion_spells_by_win_rate(championId) do
|
||||
end
|
||||
|
||||
def get_champion_picked_summoners() do
|
||||
query =
|
||||
from f in Schema,
|
||||
join: c in ChampionSchema,
|
||||
on: c.champion_id == f.champion_id,
|
||||
join: s in SummonerSpellSchema,
|
||||
on: s.spell_id == f.summoner_spell_id,
|
||||
select: %{
|
||||
wins: fragment("count(CASE WHEN ? THEN 1 END)", f.is_win),
|
||||
win_rate:
|
||||
fragment(
|
||||
"
|
||||
((cast(count(CASE WHEN ? THEN 1 END) as float) / cast(count(*) as float)) * 100.0
|
||||
)",
|
||||
f.is_win
|
||||
),
|
||||
id: f.champion_id,
|
||||
spell_id: f.summoner_spell_id,
|
||||
metadata: s.metadata,
|
||||
champion_name: c.name,
|
||||
champion_id: c.champion_id,
|
||||
image: c.image,
|
||||
team_position: f.team_position,
|
||||
total_games: count("*")
|
||||
},
|
||||
group_by: [
|
||||
f.champion_id,
|
||||
f.summoner_spell_id,
|
||||
s.metadata,
|
||||
c.image,
|
||||
c.name,
|
||||
c.champion_id,
|
||||
f.team_position
|
||||
]
|
||||
|
||||
Repo.all(query)
|
||||
end
|
||||
|
||||
def list_facts() do
|
||||
Repo.all(Schema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Schema do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
@params [
|
||||
:champion_id,
|
||||
:summoner_spell_id,
|
||||
:match_id,
|
||||
:is_win,
|
||||
:game_length_seconds,
|
||||
:queue_id,
|
||||
:team_position,
|
||||
:puuid
|
||||
]
|
||||
|
||||
schema "fact_champion_picked_summoner_spell" do
|
||||
field :champion_id, :integer
|
||||
field :summoner_spell_id, :integer
|
||||
field :match_id, :string
|
||||
field :is_win, :boolean
|
||||
field :game_length_seconds, :integer
|
||||
field :queue_id, :integer
|
||||
field :team_position, :string
|
||||
field :puuid, :string
|
||||
end
|
||||
|
||||
def changeset(fact = %__MODULE__{}, attrs \\ %{}) do
|
||||
fact
|
||||
|> cast(attrs, @params)
|
||||
|> validate_required(@params)
|
||||
|> unique_constraint([:puuid, :match_id, :summoner_spell_id])
|
||||
end
|
||||
end
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
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.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 = Schema.changeset(%Schema{}, attrs)
|
||||
Repo.insert(changeset)
|
||||
end
|
||||
|
||||
def list_played_matches() do
|
||||
Repo.all(Schema)
|
||||
end
|
||||
|
||||
def get_win_rates do
|
||||
query =
|
||||
from m in Schema,
|
||||
join: c in ChampionSchema,
|
||||
on: c.champion_id == m.champion_id,
|
||||
select: %{
|
||||
wins: fragment("count(CASE WHEN ? THEN 1 END)", m.is_win),
|
||||
win_rate:
|
||||
fragment(
|
||||
"
|
||||
((cast(count(CASE WHEN ? THEN 1 END) as float) / cast(count(*) as float)) * 100.0
|
||||
)",
|
||||
m.is_win
|
||||
),
|
||||
id: m.champion_id,
|
||||
name: c.name,
|
||||
image: c.image,
|
||||
team_position: m.team_position,
|
||||
total_games: count("*")
|
||||
},
|
||||
group_by: [m.champion_id, c.image, c.name, m.team_position]
|
||||
|
||||
Repo.all(query)
|
||||
end
|
||||
|
||||
def get_win_rates_by_roles() do
|
||||
end
|
||||
end
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.Schema do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
@casting_attrs [
|
||||
:champion_id,
|
||||
:match_id,
|
||||
:is_win,
|
||||
:game_length_seconds,
|
||||
:team_position,
|
||||
:puuid,
|
||||
:queue_id
|
||||
]
|
||||
|
||||
schema "fact_champion_played_game" do
|
||||
field :champion_id, :integer
|
||||
field :match_id, :string
|
||||
field :is_win, :boolean
|
||||
field :game_length_seconds, :integer
|
||||
field :team_position, :string
|
||||
field :puuid, :string
|
||||
field :queue_id, :integer
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(fact = %__MODULE__{}, attrs \\ %{}) do
|
||||
fact
|
||||
|> cast(attrs, @casting_attrs)
|
||||
|> validate_required(@casting_attrs)
|
||||
|> unique_constraint([:id, :champion_id, :queue_id])
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ defmodule LoLAnalytics.MixProject do
|
||||
{:postgrex, ">= 0.0.0"},
|
||||
{:jason, "~> 1.2"},
|
||||
{:lol_api, in_umbrella: true},
|
||||
{:storage, in_umbrella: true},
|
||||
{:httpoison, "~> 2.2"},
|
||||
{:poison, "~> 5.0"}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
defmodule LoLAnalytics.Repo.Migrations.AnalyticsTables do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table("dim_champion") do
|
||||
add :champion_id, :integer, primary_key: true, null: false
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("dim_champion", [:champion_id], unique: true)
|
||||
|
||||
create table("dim_item") do
|
||||
add :item_id, :integer, primary_key: true, null: false
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("dim_item", [:item_id], unique: true)
|
||||
|
||||
create table("dim_match") do
|
||||
add :match_id, :string, primary_key: true, null: false
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("dim_match", [:match_id], unique: true)
|
||||
|
||||
create table("dim_patch") do
|
||||
add :patch_number, :string, primary_key: true, null: false
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("dim_patch", [:patch_number], unique: true)
|
||||
|
||||
create table("dim_player") do
|
||||
add :puuid, :string, primary_key: true, null: false
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("dim_player", [:puuid], unique: true)
|
||||
|
||||
create table("dim_summoner_spell") do
|
||||
add :spell_id, :integer, primary_key: true, null: false
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("dim_summoner_spell", [:spell_id], unique: true)
|
||||
|
||||
create table("fact_champion_played_game") do
|
||||
add :champion_id, references("dim_champion", column: :champion_id, type: :integer)
|
||||
add :match_id, references("dim_match", column: :match_id, type: :string)
|
||||
add :is_win, :boolean
|
||||
add :game_length_seconds, :integer
|
||||
add :queue_id, :integer
|
||||
add :patch_number, references("dim_patch", column: :patch_number, type: :string)
|
||||
add :team_position, :string
|
||||
add :puuid, references("dim_player", column: :puuid, type: :string)
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index("fact_champion_played_game", [:id, :champion_id, :queue_id])
|
||||
create index("fact_champion_played_game", [:puuid, :match_id], unique: true)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule LoLAnalytics.Repo.Migrations.ChampionDimName do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table("dim_champion") do
|
||||
add :name, :string
|
||||
add :image, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
defmodule LoLAnalytics.Repo.Migrations.SummonerSpellWinRate do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table("fact_champion_picked_summoner_spell") do
|
||||
add :champion_id, references("dim_champion", column: :champion_id, type: :integer)
|
||||
add :summoner_spell_id, references("dim_summoner_spell", column: :spell_id, type: :integer)
|
||||
add :match_id, references("dim_match", column: :match_id, type: :string)
|
||||
add :is_win, :boolean
|
||||
add :game_length_seconds, :integer
|
||||
add :queue_id, :integer
|
||||
add :team_position, :string
|
||||
add :puuid, references("dim_player", column: :puuid, type: :string)
|
||||
add :patch_number, references("dim_patch", column: :patch_number, type: :string)
|
||||
end
|
||||
|
||||
create index(
|
||||
"fact_champion_picked_summoner_spell",
|
||||
[:puuid, :match_id, :summoner_spell_id],
|
||||
unique: true
|
||||
)
|
||||
|
||||
create index("fact_champion_picked_summoner_spell", [
|
||||
:is_win,
|
||||
:team_position,
|
||||
:queue_id,
|
||||
:summoner_spell_id,
|
||||
:patch_number
|
||||
])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
defmodule LoLAnalytics.Repo.Migrations.SummonerSpellMetadata do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table("dim_summoner_spell") do
|
||||
add :metadata, :map
|
||||
end
|
||||
end
|
||||
end
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
defmodule LoLAnalytics.Repo.Migrations.SummonerSpellMetadataIndex do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
execute("CREATE INDEX dim_summoner_spell_metadata ON dim_summoner_spell USING GIN(metadata)")
|
||||
end
|
||||
|
||||
def down do
|
||||
execute("DROP INDEX dim_summoner_spell_metadata")
|
||||
end
|
||||
end
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells.SummonerSpell do
|
||||
defstruct [:id, :win_rate, :total_games]
|
||||
|
||||
@type t :: %{
|
||||
id: integer(),
|
||||
win_rate: float(),
|
||||
total_games: integer()
|
||||
}
|
||||
end
|
||||
|
||||
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props do
|
||||
alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.SummonerSpell
|
||||
|
||||
defstruct spell1: %SummonerSpell{},
|
||||
spell2: %SummonerSpell{}
|
||||
|
||||
@type t :: %{
|
||||
spell1: SummonerSpell.t(),
|
||||
spell2: SummonerSpell.t()
|
||||
}
|
||||
end
|
||||
|
||||
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells do
|
||||
alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props
|
||||
use Phoenix.Component
|
||||
|
||||
attr :spells, Props, default: %Props{}
|
||||
|
||||
def summoner_spells(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
Spells
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
|
||||
</script>
|
||||
</head>
|
||||
<body class="bg-white antialiased">
|
||||
<body class="bg-slate-700 antialiased">
|
||||
<%= @inner_content %>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
defmodule LolAnalyticsWeb.ChampionLive.ChampionSummary do
|
||||
defstruct [:id, :win_rate, :image, :name, :team_position, :wins, :total_games]
|
||||
end
|
||||
@@ -0,0 +1,107 @@
|
||||
defmodule LoLAnalyticsWeb.ChampionLive.Index do
|
||||
alias LolAnalyticsWeb.ChampionLive.Mapper
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
@roles [
|
||||
%{title: "All", value: "all"},
|
||||
%{title: "Top", value: "TOP"},
|
||||
%{title: "Jungle", value: "JUNGLE"},
|
||||
%{title: "Mid", value: "MIDDLE"},
|
||||
%{title: "Bot", value: "BOTTOM"},
|
||||
%{title: "Support", value: "UTILITY"}
|
||||
]
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
champs = LolAnalytics.Facts.ChampionPlayedGame.Repo.get_win_rates()
|
||||
|
||||
mapped =
|
||||
champs
|
||||
|> Mapper.map_champs()
|
||||
|> Enum.sort(&(&1.win_rate >= &2.win_rate))
|
||||
|
||||
roles =
|
||||
@roles
|
||||
|> Enum.reduce(%{}, fn role, acc ->
|
||||
Map.merge(acc, %{"#{role.value}" => false})
|
||||
end)
|
||||
|> Map.merge(%{"all" => true})
|
||||
|
||||
form =
|
||||
Map.merge(
|
||||
%{"name" => ""},
|
||||
roles
|
||||
)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> stream(
|
||||
:champions,
|
||||
mapped
|
||||
)
|
||||
|> assign(:form, to_form(form))
|
||||
|> assign(:roles, @roles)
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("filter", params, socket) do
|
||||
%{
|
||||
"name" => query_name,
|
||||
"all" => all,
|
||||
"TOP" => top,
|
||||
"JUNGLE" => jungle,
|
||||
"MIDDLE" => mid,
|
||||
"BOTTOM" => bot,
|
||||
"UTILITY" => utility
|
||||
} = params
|
||||
|
||||
filter =
|
||||
if all == "true" do
|
||||
nil
|
||||
else
|
||||
%{
|
||||
"TOP" => top == "true",
|
||||
"JUNGLE" => jungle == "true",
|
||||
"MIDDLE" => mid == "true",
|
||||
"BOTTOM" => bot == "true",
|
||||
"UTILITY" => utility == "true"
|
||||
}
|
||||
|> Enum.filter(fn {_k, v} -> v end)
|
||||
|> Enum.map(fn {k, _v} -> k end)
|
||||
end
|
||||
|
||||
champs =
|
||||
LolAnalytics.Facts.ChampionPlayedGame.Repo.get_win_rates()
|
||||
|> Enum.filter(fn %{name: name} ->
|
||||
String.downcase(name) |> String.contains?(query_name)
|
||||
end)
|
||||
|> Enum.filter(fn champ ->
|
||||
if filter != nil do
|
||||
Enum.any?(filter, fn f -> f == champ.team_position end)
|
||||
end
|
||||
end)
|
||||
|> Mapper.map_champs()
|
||||
|> Enum.sort(&(&1.win_rate >= &2.win_rate))
|
||||
|
||||
{:noreply,
|
||||
stream(
|
||||
socket,
|
||||
:champions,
|
||||
champs
|
||||
)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "Listing Champions")
|
||||
|
||||
# |> assign(:champion, nil)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,54 @@
|
||||
<.header>
|
||||
Listing Champions
|
||||
</.header>
|
||||
|
||||
<h1>Champions</h1>
|
||||
<.form for={@form} phx-change="filter" phx-submit="save">
|
||||
<div class="flex flex-col gap-2">
|
||||
<.input type="text" field={@form["name"]} />
|
||||
<div class="flex flex-row justify-between">
|
||||
<%= for role <- @roles do %>
|
||||
<div class="flex flex-row gap-2 align-middle">
|
||||
<.input type="checkbox" field={@form[role.value]} />
|
||||
<p><%= role.title %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%!-- <button>Save</button> --%>
|
||||
</.form>
|
||||
|
||||
<div id="champions" class="grid grid-cols-4 gap-4">
|
||||
<%= for {_, champion} <- @streams.champions do %>
|
||||
<div class="flex flex-col max-w-sm bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700">
|
||||
<img src={"https://ddragon.leagueoflegends.com/cdn/14.11.1/img/champion/#{champion.image}"} />
|
||||
<div class="flex-auto flex-col p-4 ">
|
||||
<p><%= champion.name %></p>
|
||||
<p><%= champion.wins %> / <%= champion.total_games %></p>
|
||||
<p><%= champion.win_rate %>%</p>
|
||||
<p><%= champion.team_position %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/champions/#{champion}"}>Show</.link>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<.modal
|
||||
:if={@live_action in [:new, :edit]}
|
||||
id="champion-modal"
|
||||
show
|
||||
on_cancel={JS.patch(~p"/champions")}
|
||||
>
|
||||
<.live_component
|
||||
module={LoLAnalyticsWeb.ChampionLive.FormComponent}
|
||||
id={@champion.champion_id || :new}
|
||||
title={@page_title}
|
||||
action={@live_action}
|
||||
champion={@champion}
|
||||
patch={~p"/champions"}
|
||||
/>
|
||||
</.modal>
|
||||
@@ -0,0 +1,13 @@
|
||||
defmodule LolAnalyticsWeb.ChampionLive.Mapper do
|
||||
alias LolAnalyticsWeb.ChampionLive.ChampionSummary
|
||||
|
||||
def map_champs(champs) do
|
||||
champs
|
||||
|> Enum.map(fn champ ->
|
||||
%{
|
||||
Kernel.struct!(%ChampionSummary{}, champ)
|
||||
| win_rate: :erlang.float_to_binary(champ.win_rate, decimals: 2)
|
||||
}
|
||||
end)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
defmodule LoLAnalyticsWeb.ChampionLive.Show do
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
import LolAnalyticsWeb.ChampionComponents.SummonerSpells
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => id}, _, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))
|
||||
|> assign(:champion, %{id: id})
|
||||
|> assign(:summoner_spells, %{summoner_spells: load_summoner_spells()})}
|
||||
end
|
||||
|
||||
defp load_summoner_spells() do
|
||||
%LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props{
|
||||
spell1: %LolAnalyticsWeb.ChampionComponents.SummonerSpells.SummonerSpell{
|
||||
id: 1,
|
||||
win_rate: 51.7,
|
||||
total_games: 400
|
||||
},
|
||||
spell2: %LolAnalyticsWeb.ChampionComponents.SummonerSpells.SummonerSpell{
|
||||
id: 2,
|
||||
win_rate: 51.7,
|
||||
total_games: 500
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Champion"
|
||||
defp page_title(:edit), do: "Edit Champion"
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
<.header>
|
||||
Champion <%= @champion.id %>
|
||||
<:subtitle>This is a champion record from your database.</:subtitle>
|
||||
<:actions></:actions>
|
||||
</.header>
|
||||
|
||||
<.summoner_spells spells={@summoner_spells} />
|
||||
|
||||
<.back navigate={~p"/champions"}>
|
||||
Back to champions
|
||||
</.back>
|
||||
@@ -0,0 +1,27 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
|
||||
use LoLAnalyticsWeb, :live_component
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<.header>
|
||||
<%= @title %>
|
||||
<:subtitle>Use this form to manage role records in your database.</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.simple_form
|
||||
for={@form}
|
||||
id="role-form"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-submit="save"
|
||||
>
|
||||
<:actions>
|
||||
<.button phx-disable-with="Saving...">Save Role</.button>
|
||||
</:actions>
|
||||
</.simple_form>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLive.Index do
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
@roles ["ALL", "TOP", "MIDDLE", "JUNGLE", "UTILITY", "BOTTOM"]
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, stream(socket, :roles, @roles)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "Listing Roles")
|
||||
|> assign(:role, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info({LoLAnalyticsWeb.RoleLive.FormComponent, {:saved, role}}, socket) do
|
||||
{:noreply, stream_insert(socket, :roles, role)}
|
||||
end
|
||||
|
||||
# @impl true
|
||||
# def handle_event("delete", %{"id" => id}, socket) do
|
||||
# role = Accounts.get_role!(id)
|
||||
# {:ok, _} = Accounts.delete_role(role)
|
||||
|
||||
# {:noreply, stream_delete(socket, :roles, role)}
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
<.header>
|
||||
Listing Roles
|
||||
<:actions></:actions>
|
||||
</.header>
|
||||
@@ -0,0 +1,18 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLive.Show do
|
||||
use LoLAnalyticsWeb, :live_view
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"id" => _id}, _, socket) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:page_title, page_title(socket.assigns.live_action))}
|
||||
end
|
||||
|
||||
defp page_title(:show), do: "Show Role"
|
||||
defp page_title(:edit), do: "Edit Role"
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
<.header>
|
||||
Role <%= @role.id %>
|
||||
<:subtitle>This is a role record from your database.</:subtitle>
|
||||
<:actions></:actions>
|
||||
</.header>
|
||||
@@ -18,6 +18,12 @@ defmodule LoLAnalyticsWeb.Router do
|
||||
pipe_through :browser
|
||||
|
||||
get "/", PageController, :home
|
||||
live "/champions", ChampionLive.Index, :index
|
||||
live "/champions/new", ChampionLive.Index, :new
|
||||
live "/champions/:id/edit", ChampionLive.Index, :edit
|
||||
|
||||
live "/champions/:id", ChampionLive.Show, :show
|
||||
live "/champions/:id/show/edit", ChampionLive.Show, :edit
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
defmodule LoLAnalyticsWeb.ChampionLiveTest do
|
||||
use LoLAnalyticsWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import LoLAnalytics.AccountsFixtures
|
||||
|
||||
@create_attrs %{}
|
||||
@update_attrs %{}
|
||||
@invalid_attrs %{}
|
||||
|
||||
defp create_champion(_) do
|
||||
champion = champion_fixture()
|
||||
%{champion: champion}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_champion]
|
||||
|
||||
test "lists all champions", %{conn: conn} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/champions")
|
||||
|
||||
assert html =~ "Listing Champions"
|
||||
end
|
||||
|
||||
test "saves new champion", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/champions")
|
||||
|
||||
assert index_live |> element("a", "New Champion") |> render_click() =~
|
||||
"New Champion"
|
||||
|
||||
assert_patch(index_live, ~p"/champions/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#champion-form", champion: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#champion-form", champion: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/champions")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Champion created successfully"
|
||||
end
|
||||
|
||||
test "updates champion in listing", %{conn: conn, champion: champion} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/champions")
|
||||
|
||||
assert index_live |> element("#champions-#{champion.id} a", "Edit") |> render_click() =~
|
||||
"Edit Champion"
|
||||
|
||||
assert_patch(index_live, ~p"/champions/#{champion}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#champion-form", champion: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#champion-form", champion: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/champions")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Champion updated successfully"
|
||||
end
|
||||
|
||||
test "deletes champion in listing", %{conn: conn, champion: champion} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/champions")
|
||||
|
||||
assert index_live |> element("#champions-#{champion.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#champions-#{champion.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_champion]
|
||||
|
||||
test "displays champion", %{conn: conn, champion: champion} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/champions/#{champion}")
|
||||
|
||||
assert html =~ "Show Champion"
|
||||
end
|
||||
|
||||
test "updates champion within modal", %{conn: conn, champion: champion} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/champions/#{champion}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Champion"
|
||||
|
||||
assert_patch(show_live, ~p"/champions/#{champion}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#champion-form", champion: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#champion-form", champion: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/champions/#{champion}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Champion updated successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,108 @@
|
||||
defmodule LoLAnalyticsWeb.RoleLiveTest do
|
||||
use LoLAnalyticsWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import LoLAnalytics.AccountsFixtures
|
||||
|
||||
@create_attrs %{}
|
||||
@update_attrs %{}
|
||||
@invalid_attrs %{}
|
||||
|
||||
defp create_role(_) do
|
||||
role = role_fixture()
|
||||
%{role: role}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_role]
|
||||
|
||||
test "lists all roles", %{conn: conn} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/roles")
|
||||
|
||||
assert html =~ "Listing Roles"
|
||||
end
|
||||
|
||||
test "saves new role", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/roles")
|
||||
|
||||
assert index_live |> element("a", "New Role") |> render_click() =~
|
||||
"New Role"
|
||||
|
||||
assert_patch(index_live, ~p"/roles/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#role-form", role: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#role-form", role: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/roles")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Role created successfully"
|
||||
end
|
||||
|
||||
test "updates role in listing", %{conn: conn, role: role} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/roles")
|
||||
|
||||
assert index_live |> element("#roles-#{role.id} a", "Edit") |> render_click() =~
|
||||
"Edit Role"
|
||||
|
||||
assert_patch(index_live, ~p"/roles/#{role}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#role-form", role: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#role-form", role: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/roles")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Role updated successfully"
|
||||
end
|
||||
|
||||
test "deletes role in listing", %{conn: conn, role: role} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/roles")
|
||||
|
||||
assert index_live |> element("#roles-#{role.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#roles-#{role.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_role]
|
||||
|
||||
test "displays role", %{conn: conn, role: role} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/roles/#{role}")
|
||||
|
||||
assert html =~ "Show Role"
|
||||
end
|
||||
|
||||
test "updates role within modal", %{conn: conn, role: role} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/roles/#{role}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Role"
|
||||
|
||||
assert_patch(show_live, ~p"/roles/#{role}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#role-form", role: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#role-form", role: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/roles/#{role}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Role updated successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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,19 +1,9 @@
|
||||
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
|
||||
|
||||
@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} ->
|
||||
def stream_classify_matches_by_queue(queue \\ 420, bucket \\ "ranked") do
|
||||
Storage.MatchStorage.S3MatchStorage.stream_files("matches")
|
||||
|> Stream.each(fn match ->
|
||||
%{key: json_file} = match
|
||||
[key | _] = String.split(json_file, ".")
|
||||
|
||||
@@ -25,15 +15,12 @@ defmodule Scrapper.MatchClassifier do
|
||||
%{"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")
|
||||
if queueId == queue do
|
||||
Storage.MatchStorage.S3MatchStorage.store_match(key, response.body, bucket, gameVersion)
|
||||
Logger.info("Match #{key} processed")
|
||||
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,43 +2,14 @@ defmodule Storage.MatchStorage.S3MatchStorage do
|
||||
require Logger
|
||||
@behaviour Storage.MatchStorage
|
||||
|
||||
def get_match(match_id) do
|
||||
""
|
||||
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
|
||||
def get_match(_match_id) do
|
||||
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
|
||||
@impl true
|
||||
def stream_files(path) do
|
||||
ExAws.S3.list_objects_v2(path)
|
||||
|> ExAws.stream!()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import Config
|
||||
config :lol_analytics_web, LoLAnalyticsWeb.Endpoint,
|
||||
server: true,
|
||||
http: [ip: {0, 0, 0, 0}, port: 4000],
|
||||
url: [host: "lol-analytics.kaizer.cloud", port: 80],
|
||||
url: [host: "localhost", port: 80],
|
||||
cache_static_manifest: "priv/static/cache_manifest.json"
|
||||
|
||||
# Do not print debug messages in production
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import Config
|
||||
# and secrets from environment variables or elsewhere. Do not define
|
||||
# any compile-time configuration in here, as it won't be applied.
|
||||
# The block below contains prod specific runtime configuration.
|
||||
if config_env() == :prod do
|
||||
if config_env() == :prod || true do
|
||||
database_url =
|
||||
System.get_env("DATABASE_URL") ||
|
||||
raise """
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
version: '3.8'
|
||||
services:
|
||||
db:
|
||||
image: postgres:latest
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
environment:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_DB: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
rabbitmq:
|
||||
image: rabbitmq:3-management-alpine
|
||||
container_name: 'rabbitmq'
|
||||
ports:
|
||||
- "15671:15671"
|
||||
- "15672:15672"
|
||||
- "15691:15691"
|
||||
- "15692:15692"
|
||||
- "25672:25672"
|
||||
- "4639:4639"
|
||||
- "5671:5671"
|
||||
- "5672:5672"
|
||||
volumes:
|
||||
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
|
||||
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
|
||||
networks:
|
||||
- rabbitmq_go_net
|
||||
volumes:
|
||||
postgres-data:
|
||||
|
||||
|
||||
networks:
|
||||
rabbitmq_go_net:
|
||||
driver: bridge
|
||||
@@ -21,7 +21,7 @@
|
||||
"gen_stage": {:hex, :gen_stage, "1.2.1", "19d8b5e9a5996d813b8245338a28246307fd8b9c99d1237de199d21efc4c76a1", [:mix], [], "hexpm", "83e8be657fa05b992ffa6ac1e3af6d57aa50aace8f691fcf696ff02f8335b001"},
|
||||
"gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"},
|
||||
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
|
||||
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
|
||||
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
|
||||
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
|
||||
"httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"},
|
||||
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
```
|
||||
SELECT
|
||||
(cast(count(CASE WHEN is_win THEN 1 END) as float) / cast(count(*) as float)) * 100.0 as win_rate,
|
||||
count(CASE WHEN is_win THEN 1 END) as games_won,
|
||||
count(*) as total_games,
|
||||
champion_id
|
||||
FROM fact_champion_played_game
|
||||
GROUP BY champion_id
|
||||
ORDER BY win_rate desc;
|
||||
```
|
||||
|
||||
```
|
||||
SELECT
|
||||
(cast(count(CASE WHEN is_win THEN 1 END) as float) / cast(count(*) as float)) * 100.0 as win_rate,
|
||||
count(CASE WHEN is_win THEN 1 END) as games_won,
|
||||
count(*) as total_games,
|
||||
champion_id,
|
||||
team_position
|
||||
FROM fact_champion_played_game
|
||||
GROUP BY champion_id, team_position
|
||||
ORDER BY win_rate desc;
|
||||
```
|
||||
Reference in New Issue
Block a user