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 defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
import Ecto.Query import Ecto.Query
alias LolAnalytics.Dimensions.Patch.PatchRepo
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo
alias LolAnalytics.Dimensions.Champion.ChampionSchema alias LolAnalytics.Dimensions.Champion.ChampionSchema
@ -13,19 +14,19 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
alias LoLAnalytics.Repo alias LoLAnalytics.Repo
@type insert_attrs :: %{ @spec insert(%{
match_id: String.t(), :champion_id => String.t(),
champion_id: String.t(), :match_id => String.t(),
puuid: String.t(), :patch_number => String.t(),
summoner_spell_id: :integer :puuid => any(),
} :summoner_spell_id => String.t()
}) :: any()
@spec insert(insert_attrs()) :: any()
def insert(attrs) do def insert(attrs) do
_match = MatchRepo.get_or_create(attrs.match_id) _match = MatchRepo.get_or_create(attrs.match_id)
_champion = ChampionRepo.get_or_create(attrs.champion_id) _champion = ChampionRepo.get_or_create(attrs.champion_id)
_player = PlayerRepo.get_or_create(attrs.puuid) _player = PlayerRepo.get_or_create(attrs.puuid)
_spell = SummonerSpellRepo.get_or_create(attrs.summoner_spell_id) _spell = SummonerSpellRepo.get_or_create(attrs.summoner_spell_id)
_patch = PatchRepo.get_or_create(attrs.patch_number)
prev = prev =
from(f in Schema, from(f in Schema,
@ -41,10 +42,14 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|> Repo.insert_or_update() |> Repo.insert_or_update()
end 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 = 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 == ^champion_id and
f.team_position == ^team_position and
f.patch_number == ^patch_number,
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,
@ -74,8 +79,4 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
Repo.all(query) Repo.all(query)
end end
def list_facts() do
Repo.all(Schema)
end
end end

View File

@ -7,6 +7,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Schema do
:champion_id, :champion_id,
:summoner_spell_id, :summoner_spell_id,
:match_id, :match_id,
:patch_number,
:is_win, :is_win,
:game_length_seconds, :game_length_seconds,
:queue_id, :queue_id,
@ -18,6 +19,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Schema do
field :champion_id, :integer field :champion_id, :integer
field :summoner_spell_id, :integer field :summoner_spell_id, :integer
field :match_id, :string field :match_id, :string
field :patch_number, :string
field :is_win, :boolean field :is_win, :boolean
field :game_length_seconds, :integer field :game_length_seconds, :integer
field :queue_id, :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(:page_title, page_title(socket.assigns.live_action))
|> assign(:champion, load_champion_info(id)) |> assign(:champion, load_champion_info(id))
|> load_win_rates(id, team_position) |> 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)} |> load_items(id, team_position, patch)}
end end
@ -40,13 +40,14 @@ defmodule LoLAnalyticsWeb.ChampionLive.Show do
end) end)
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 socket
|> assign(:summoner_spells, %{status: :loading}) |> assign(:summoner_spells, %{status: :loading})
|> start_async(:get_summoners, fn -> |> start_async(:get_summoners, fn ->
LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo.get_champion_picked_summoners( LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo.get_champion_picked_summoners(
champion_id, champion_id,
team_position team_position,
patch_number
) )
|> ShowMapper.map_spells() |> ShowMapper.map_spells()
end) end)