add patch number to summoner spells
Some checks are pending
ci / docker (push) Waiting to run

This commit is contained in:
Álvaro 2024-06-18 20:07:39 +02:00
parent e0aa1b2476
commit be2f02560c
3 changed files with 21 additions and 17 deletions

View File

@ -1,6 +1,7 @@
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
import Ecto.Query
alias LolAnalytics.Dimensions.Patch.PatchRepo
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo
alias LolAnalytics.Dimensions.Champion.ChampionSchema
@ -13,19 +14,19 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
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()
@spec insert(%{
:champion_id => String.t(),
:match_id => String.t(),
:patch_number => String.t(),
:puuid => any(),
:summoner_spell_id => String.t()
}) :: 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)
_patch = PatchRepo.get_or_create(attrs.patch_number)
prev =
from(f in Schema,
@ -41,10 +42,14 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|> Repo.insert_or_update()
end
def get_champion_picked_summoners(champion_id, team_position \\ "MIDDLE") do
@spec get_champion_picked_summoners(String.t(), String.t(), String.t()) :: list()
def get_champion_picked_summoners(champion_id, team_position, patch_number) do
query =
from f in Schema,
where: f.champion_id == ^champion_id and f.team_position == ^team_position,
where:
f.champion_id == ^champion_id and
f.team_position == ^team_position and
f.patch_number == ^patch_number,
join: c in ChampionSchema,
on: c.champion_id == f.champion_id,
join: s in SummonerSpellSchema,
@ -74,8 +79,4 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
Repo.all(query)
end
def list_facts() do
Repo.all(Schema)
end
end

View File

@ -7,6 +7,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Schema do
:champion_id,
:summoner_spell_id,
:match_id,
:patch_number,
:is_win,
:game_length_seconds,
:queue_id,
@ -18,6 +19,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Schema do
field :champion_id, :integer
field :summoner_spell_id, :integer
field :match_id, :string
field :patch_number, :string
field :is_win, :boolean
field :game_length_seconds, :integer
field :queue_id, :integer

View File

@ -20,7 +20,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Show do
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:champion, load_champion_info(id))
|> load_win_rates(id, team_position)
|> load_summoner_spells(id, team_position)
|> load_summoner_spells(id, team_position, patch)
|> load_items(id, team_position, patch)}
end
@ -40,13 +40,14 @@ defmodule LoLAnalyticsWeb.ChampionLive.Show do
end)
end
defp load_summoner_spells(socket, champion_id, team_position) do
defp load_summoner_spells(socket, champion_id, team_position, patch_number) do
socket
|> assign(:summoner_spells, %{status: :loading})
|> start_async(:get_summoners, fn ->
LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo.get_champion_picked_summoners(
champion_id,
team_position
team_position,
patch_number
)
|> ShowMapper.map_spells()
end)