Compare commits
No commits in common. "f79f0db8625370efbf8cab9034e8bb207f7d66e9" and "0987290dca6433c268f8a1c192f3b58bedb391ed" have entirely different histories.
f79f0db862
...
0987290dca
@ -2,12 +2,10 @@ defmodule LolAnalytics.Dimensions.Item.ItemRepo do
|
|||||||
alias LolAnalytics.Dimensions.Item.ItemSchema
|
alias LolAnalytics.Dimensions.Item.ItemSchema
|
||||||
alias LoLAnalytics.Repo
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
def get_or_create(item_id) do
|
def get_or_create(item_id) do
|
||||||
query = from i in ItemSchema, where: i.item_id == ^item_id
|
item = Repo.get(ItemSchema, item_id: item_id)
|
||||||
|
|
||||||
case Repo.one(query) do
|
case item do
|
||||||
nil ->
|
nil ->
|
||||||
item_changeset = ItemSchema.changeset(%ItemSchema{}, %{item_id: item_id})
|
item_changeset = ItemSchema.changeset(%ItemSchema{}, %{item_id: item_id})
|
||||||
Repo.insert(item_changeset)
|
Repo.insert(item_changeset)
|
||||||
|
|||||||
@ -1,2 +0,0 @@
|
|||||||
defmodule LolAnalytics.Facts.ChhampionPickedItem.FactProcessor do
|
|
||||||
end
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
alias LolAnalytics.Dimensions.Item.ItemSchema
|
|
||||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
|
||||||
alias LolAnalytics.Facts.ChhampionPickedItem.Schema
|
|
||||||
alias LolAnalytics.Dimensions.Item.ItemRepo
|
|
||||||
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
|
||||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
|
||||||
alias LolAnalytics.Dimensions.Match.MatchRepo
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Inserts a new entry for the campion_picked_item fact.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
iex> item_picked = %{champion_id: 90, item_id: 1, match_id: "123", patch_number: "14.9", puuid: "1223", slot_number: 1, queue_id: 420, team_position: "JUNGLE", slot_number: 1, is_win: true}
|
|
||||||
iex> LolAnalytics.Facts.ChampionPickedItem.Repo.insert(item_picked)
|
|
||||||
"""
|
|
||||||
@spec insert(%{
|
|
||||||
:champion_id => integer(),
|
|
||||||
:item_id => integer(),
|
|
||||||
:match_id => binary(),
|
|
||||||
:patch_number => String.t(),
|
|
||||||
:puuid => String.t(),
|
|
||||||
:is_win => boolean(),
|
|
||||||
:queue_id => integer(),
|
|
||||||
:team_position => String.t(),
|
|
||||||
:slot_number => integer()
|
|
||||||
}) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
|
|
||||||
def insert(attrs) do
|
|
||||||
IO.inspect(attrs)
|
|
||||||
_match = MatchRepo.get_or_create(attrs.match_id)
|
|
||||||
_champion = ChampionRepo.get_or_create(attrs.champion_id)
|
|
||||||
_player = PlayerRepo.get_or_create(attrs.puuid)
|
|
||||||
_patch = PlayerRepo.get_or_create(attrs.patch_number)
|
|
||||||
_item_id = ItemRepo.get_or_create(attrs.item_id)
|
|
||||||
|
|
||||||
prev =
|
|
||||||
from(f in Schema,
|
|
||||||
where:
|
|
||||||
f.match_id == ^attrs.match_id and
|
|
||||||
f.puuid == ^attrs.puuid and
|
|
||||||
f.item_id == ^attrs.item_id and
|
|
||||||
f.slot_number == ^attrs.slot_number
|
|
||||||
)
|
|
||||||
|> Repo.one()
|
|
||||||
|
|
||||||
Schema.changeset(prev || %Schema{}, attrs)
|
|
||||||
|> Repo.insert_or_update()
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec get_champion_picked_items(String.t(), String.t()) :: list()
|
|
||||||
def get_champion_picked_items(champion_id, team_position) do
|
|
||||||
query =
|
|
||||||
from f in Schema,
|
|
||||||
where:
|
|
||||||
f.champion_id == ^champion_id and
|
|
||||||
f.team_position == ^team_position,
|
|
||||||
join: c in ChampionSchema,
|
|
||||||
on: c.champion_id == f.champion_id,
|
|
||||||
join: i in ItemSchema,
|
|
||||||
on: i.item_id == f.item_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
|
|
||||||
),
|
|
||||||
item_id: i.item_id,
|
|
||||||
champion_id: c.champion_id,
|
|
||||||
team_position: f.team_position,
|
|
||||||
total_games: count("*")
|
|
||||||
},
|
|
||||||
group_by: [
|
|
||||||
i.item_id,
|
|
||||||
c.champion_id,
|
|
||||||
f.team_position
|
|
||||||
]
|
|
||||||
|
|
||||||
Repo.all(query)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
defmodule LolAnalytics.Facts.ChhampionPickedItem.Schema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
@casting_args [
|
|
||||||
:champion_id,
|
|
||||||
:item_id,
|
|
||||||
:match_id,
|
|
||||||
:is_win,
|
|
||||||
:queue_id,
|
|
||||||
:patch_number,
|
|
||||||
:team_position,
|
|
||||||
:puuid,
|
|
||||||
:slot_number
|
|
||||||
]
|
|
||||||
|
|
||||||
schema "fact_champion_picked_item" do
|
|
||||||
field :champion_id, :integer
|
|
||||||
field :item_id, :integer
|
|
||||||
field :match_id, :string
|
|
||||||
field :is_win, :boolean
|
|
||||||
field :queue_id, :integer
|
|
||||||
field :patch_number, :string
|
|
||||||
field :team_position, :string
|
|
||||||
field :puuid, :string
|
|
||||||
field :slot_number, :integer
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(fact, attrs) do
|
|
||||||
fact
|
|
||||||
|> cast(attrs, @casting_args)
|
|
||||||
|> validate_required(@casting_args)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,12 +1,8 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
||||||
@behaviour LolAnalytics.Facts.FactBehaviour
|
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
||||||
|
|
||||||
@impl true
|
|
||||||
@spec process_game_at_url(String.t()) :: any()
|
|
||||||
def process_game_at_url(url) do
|
def process_game_at_url(url) do
|
||||||
data = HTTPoison.get!(url)
|
data = HTTPoison.get!(url)
|
||||||
process_game_data(data.body)
|
process_game_data(data.body)
|
||||||
|
|||||||
@ -37,14 +37,15 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
|||||||
)
|
)
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
|
|
||||||
Schema.changeset(prev || %Schema{}, attrs)
|
changeset = Schema.changeset(prev || %Schema{}, attrs)
|
||||||
|> Repo.insert_or_update()
|
|
||||||
|
Repo.insert_or_update(changeset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_champion_picked_summoners(champion_id, team_position \\ "MIDDLE") do
|
def get_champion_picked_summoners(championId, team_position \\ "MIDDLE") do
|
||||||
query =
|
query =
|
||||||
from f in Schema,
|
from f in Schema,
|
||||||
where: f.champion_id == ^champion_id and f.team_position == ^team_position,
|
where: f.champion_id == ^championId and f.team_position == ^team_position,
|
||||||
join: c in ChampionSchema,
|
join: c in ChampionSchema,
|
||||||
on: c.champion_id == f.champion_id,
|
on: c.champion_id == f.champion_id,
|
||||||
join: s in SummonerSpellSchema,
|
join: s in SummonerSpellSchema,
|
||||||
@ -58,8 +59,10 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
|||||||
)",
|
)",
|
||||||
f.is_win
|
f.is_win
|
||||||
),
|
),
|
||||||
|
id: f.champion_id,
|
||||||
spell_id: f.summoner_spell_id,
|
spell_id: f.summoner_spell_id,
|
||||||
metadata: s.metadata,
|
metadata: s.metadata,
|
||||||
|
champion_name: c.name,
|
||||||
champion_id: c.champion_id,
|
champion_id: c.champion_id,
|
||||||
team_position: f.team_position,
|
team_position: f.team_position,
|
||||||
total_games: count("*")
|
total_games: count("*")
|
||||||
@ -68,6 +71,8 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
|||||||
f.champion_id,
|
f.champion_id,
|
||||||
f.summoner_spell_id,
|
f.summoner_spell_id,
|
||||||
s.metadata,
|
s.metadata,
|
||||||
|
c.image,
|
||||||
|
c.name,
|
||||||
c.champion_id,
|
c.champion_id,
|
||||||
f.team_position
|
f.team_position
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@behaviour LolAnalytics.Facts.FactBehaviour
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
@spec process_game_at_url(String.t()) :: none()
|
|
||||||
def process_game_at_url(path) do
|
def process_game_at_url(path) do
|
||||||
data = HTTPoison.get!(path)
|
data = HTTPoison.get!(path)
|
||||||
process_game_data(data.body)
|
process_game_data(data.body)
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
defmodule LolAnalytics.Facts.FactBehaviour do
|
|
||||||
@callback process_game_at_url(String.t()) :: any()
|
|
||||||
end
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
defmodule LoLAnalytics.Repo.Migrations.ChampionPickedItem do
|
|
||||||
use Ecto.Migration
|
|
||||||
|
|
||||||
def change do
|
|
||||||
create table("fact_champion_picked_item") do
|
|
||||||
add :champion_id, references("dim_champion", column: :champion_id, type: :integer)
|
|
||||||
add :item_id, references("dim_item", column: :item_id, type: :integer)
|
|
||||||
add :slot_number, :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)
|
|
||||||
end
|
|
||||||
|
|
||||||
create index("fact_champion_picked_item", [:champion_id])
|
|
||||||
create index("fact_champion_picked_item", [:puuid, :match_id, :slot_number, :item_id], unique: true)
|
|
||||||
create index("fact_champion_picked_item", [
|
|
||||||
:item_id,
|
|
||||||
:queue_id,
|
|
||||||
:is_win,
|
|
||||||
:patch_number,
|
|
||||||
:team_position
|
|
||||||
])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user