This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
||||
alias Hex.HTTP
|
||||
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
||||
@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}")
|
||||
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
||||
|> Enum.each(fn %{key: path} ->
|
||||
IO.inspect(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 """
|
||||
@@ -30,12 +36,16 @@ defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
||||
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
|
||||
)
|
||||
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
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
defmodule LolAnalytics.Dimensions.Champion.ChampionRepo do
|
||||
import Ecto.Query
|
||||
|
||||
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 list_champions() do
|
||||
Repo.all(ChampionSchema)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule LolAnalytics.Dimensions.Champion.ChampionSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_champion" do
|
||||
field :champion_id, :integer
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(champion = %__MODULE__{}, attrs \\ %{}) do
|
||||
champion
|
||||
|> cast(attrs, [:champion_id])
|
||||
|> 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
|
||||
@@ -0,0 +1,26 @@
|
||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo do
|
||||
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
|
||||
alias LoLAnalytics.Repo
|
||||
|
||||
def get_or_create(spell_id) do
|
||||
spell = Repo.get(SummonerSpellSchema, spell_id: spell_id)
|
||||
|
||||
case spell do
|
||||
nil ->
|
||||
spell_changeset =
|
||||
SummonerSpellSchema.changeset(
|
||||
%SummonerSpellSchema{},
|
||||
%{spell_id: spell_id}
|
||||
)
|
||||
|
||||
Repo.insert(spell_changeset)
|
||||
|
||||
spell ->
|
||||
spell
|
||||
end
|
||||
end
|
||||
|
||||
def list_spells() do
|
||||
Repo.all(SummonerSpellSchema)
|
||||
end
|
||||
end
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "dim_summoner_spell" do
|
||||
field :spell_id, :integer
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def changeset(summoner_spell = %__MODULE__{}, attrs) do
|
||||
summoner_spell
|
||||
|> cast(attrs, [:spell_id])
|
||||
|> validate_required([:spell_id])
|
||||
end
|
||||
end
|
||||
+24
@@ -1,3 +1,27 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo do
|
||||
import Ecto.Query
|
||||
|
||||
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
||||
alias LolAnalytics.Dimensions.Match.MatchRepo
|
||||
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
||||
alias LolAnalytics.Facts.ChampionPlayedGame
|
||||
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)
|
||||
IO.puts(">>>>")
|
||||
IO.inspect(attrs)
|
||||
changeset = ChampionPlayedGameSchema.changeset(%ChampionPlayedGameSchema{}, attrs)
|
||||
|
||||
IO.inspect(changeset)
|
||||
Repo.insert(changeset)
|
||||
# Repo.insert(match)
|
||||
end
|
||||
|
||||
def list_played_matches() do
|
||||
Repo.all(ChampionPlayedGameSchema)
|
||||
end
|
||||
end
|
||||
|
||||
+23
-1
@@ -1,11 +1,33 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema 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, :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
|
||||
|
||||
Reference in New Issue
Block a user