add processing info to match
This commit is contained in:
parent
2768e4434a
commit
667bf76591
@ -11,20 +11,44 @@ defmodule LolAnalytics.Dimensions.Match.MatchRepo do
|
|||||||
|
|
||||||
case match do
|
case match do
|
||||||
nil ->
|
nil ->
|
||||||
match_changeset =
|
%MatchSchema{}
|
||||||
MatchSchema.changeset(
|
|> MatchSchema.changeset(%{
|
||||||
%MatchSchema{},
|
fact_champion_played_game_status: 0,
|
||||||
%{match_id: match_id}
|
fact_champion_picked_item_status: 0,
|
||||||
)
|
fact_champion_picked_summoner_spell_status: 0
|
||||||
|
})
|
||||||
Repo.insert(match_changeset)
|
|> Repo.insert()
|
||||||
|
|
||||||
match ->
|
match ->
|
||||||
match
|
match
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@type update_attrs :: %{
|
||||||
|
optional(:fact_champion_played_game_status) => process_status(),
|
||||||
|
optional(:fact_champion_picked_item_status) => process_status(),
|
||||||
|
optional(:fact_champion_picked_summoner_spell_status) => process_status()
|
||||||
|
}
|
||||||
|
@spec update(%MatchSchema{}, update_attrs()) :: %MatchSchema{}
|
||||||
|
def update(match, attrs) do
|
||||||
|
mapped_attrs =
|
||||||
|
attrs
|
||||||
|
|> Enum.map(fn {k, v} -> {k, process_status_atom_to_db(v)} end)
|
||||||
|
|> Map.new()
|
||||||
|
|
||||||
|
match
|
||||||
|
|> MatchSchema.changeset(mapped_attrs)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
def list_matches() do
|
def list_matches() do
|
||||||
Repo.all(MatchSchema)
|
Repo.all(MatchSchema)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@type process_status :: :not_processed | :processed | :error
|
||||||
|
defp process_status_atom_to_db(:not_processed), do: 0
|
||||||
|
defp process_status_atom_to_db(:enqueued), do: 1
|
||||||
|
defp process_status_atom_to_db(:processed), do: 2
|
||||||
|
defp process_status_atom_to_db(:error), do: 3
|
||||||
|
defp process_status_atom_to_db(_), do: raise("Invalid processing status")
|
||||||
end
|
end
|
||||||
|
@ -2,14 +2,24 @@ defmodule LolAnalytics.Dimensions.Match.MatchSchema do
|
|||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@casting_attrs [
|
||||||
|
:match_id,
|
||||||
|
:fact_champion_picked_item_status,
|
||||||
|
:fact_champion_picked_summoner_spell_status,
|
||||||
|
:fact_champion_played_game_status
|
||||||
|
]
|
||||||
|
|
||||||
schema "dim_match" do
|
schema "dim_match" do
|
||||||
field :match_id, :string
|
field :match_id, :string
|
||||||
|
field :fact_champion_picked_item_status, :integer
|
||||||
|
field :fact_champion_picked_summoner_spell_status, :integer
|
||||||
|
field :fact_champion_played_game_status, :integer
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(match = %__MODULE__{}, attrs \\ %{}) do
|
def changeset(match = %__MODULE__{}, attrs \\ %{}) do
|
||||||
match
|
match
|
||||||
|> cast(attrs, [:match_id])
|
|> cast(attrs, @casting_attrs)
|
||||||
|> validate_required([:match_id])
|
|> validate_required([:match_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
|
|||||||
:slot_number => integer()
|
:slot_number => integer()
|
||||||
}) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
|
}) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
|
||||||
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)
|
||||||
_patch = PatchRepo.get_or_create(attrs.patch_number)
|
_patch = PatchRepo.get_or_create(attrs.patch_number)
|
||||||
@ -49,6 +49,8 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
|
|||||||
|
|
||||||
Schema.changeset(prev || %Schema{}, attrs)
|
Schema.changeset(prev || %Schema{}, attrs)
|
||||||
|> Repo.insert_or_update()
|
|> Repo.insert_or_update()
|
||||||
|
|
||||||
|
MatchRepo.update(match, %{fact_champion_picked_item: :processed})
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_champion_picked_items(String.t(), String.t(), String.t()) :: list()
|
@spec get_champion_picked_items(String.t(), String.t(), String.t()) :: list()
|
||||||
|
@ -22,7 +22,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
|||||||
:summoner_spell_id => String.t()
|
:summoner_spell_id => String.t()
|
||||||
}) :: any()
|
}) :: 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)
|
||||||
@ -40,6 +40,8 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
|||||||
|
|
||||||
Schema.changeset(prev || %Schema{}, attrs)
|
Schema.changeset(prev || %Schema{}, attrs)
|
||||||
|> Repo.insert_or_update()
|
|> Repo.insert_or_update()
|
||||||
|
|
||||||
|
MatchRepo.update(match, %{fact_champion_picked_summoner_spell: :processed})
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_champion_picked_summoners(String.t(), String.t(), String.t()) :: list()
|
@spec get_champion_picked_summoners(String.t(), String.t(), String.t()) :: list()
|
||||||
|
@ -10,7 +10,7 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
|||||||
alias LoLAnalytics.Repo
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
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)
|
||||||
_patch = PatchRepo.get_or_create(attrs.patch_number)
|
_patch = PatchRepo.get_or_create(attrs.patch_number)
|
||||||
@ -26,6 +26,7 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
|||||||
changeset = Schema.changeset(prev || %Schema{}, attrs)
|
changeset = Schema.changeset(prev || %Schema{}, attrs)
|
||||||
|
|
||||||
Repo.insert_or_update(changeset)
|
Repo.insert_or_update(changeset)
|
||||||
|
MatchRepo.update(match, %{fact_champion_played_game: :processed})
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_played_matches() do
|
def list_played_matches() do
|
||||||
|
@ -3,9 +3,9 @@ defmodule LoLAnalytics.Repo.Migrations.DimMatchFactProcessingStatus do
|
|||||||
|
|
||||||
def change do
|
def change do
|
||||||
alter table("dim_match") do
|
alter table("dim_match") do
|
||||||
add :fact_champion_played_game_status, :integer
|
add :fact_champion_played_game_status, :integer, default: 0
|
||||||
add :fact_champion_picked_item_status, :integer
|
add :fact_champion_picked_item_status, :integer, default: 0
|
||||||
add :fact_champion_picked_summoner_spell_status, :integer
|
add :fact_champion_picked_summoner_spell_status, :integer, default: 0
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("dim_match", [:fact_champion_played_game_status])
|
create index("dim_match", [:fact_champion_played_game_status])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user