Compare commits

..

2 Commits

Author SHA1 Message Date
56ba989ad8 asdf
Some checks failed
ci / docker (push) Failing after 3m31s
2024-06-22 17:30:53 +02:00
667bf76591 add processing info to match 2024-06-22 17:30:35 +02:00
10 changed files with 62 additions and 23 deletions

View File

@ -2,10 +2,10 @@
## Requirements
- Postgresql
- PostgreSQL
- Elixir
- RabbitMQ
- Minio
- MinIO
A `docker-compose` file is provided to run them locally.
@ -14,7 +14,7 @@ A `docker-compose` file is provided to run them locally.
The followign environment variables are required:
```
export RIOT_API_KEY="API-KEY"
export RIOT_API_KEY="{API-KEY}"
export EX_AWS_SECRET_KEY="{SECRET}"
export EX_AWS_ACCESS_KEY="{ACCESS}"
@ -28,7 +28,6 @@ export SECRET_KEY_BASE="SECRET-KEY"
```
mix deps.get
mix compile
mix ecto.create && mix ecto.migrate
iex -S mix phx.server
```

View File

@ -1,12 +1,9 @@
defmodule LolAnalytics.Dimensions.Item.ItemMetadata do
alias LolAnalytics.Dimensions.Item.ItemRepo
alias LolAnalytics.Dimensions.Champion.ChampionRepo
@items_data_url "https://ddragon.leagueoflegends.com/cdn/14.11.1/data/en_US/item.json"
def update_metadata() do
data = get_items()
data
get_items()
|> Enum.each(&save_metadata/1)
end

View File

@ -11,20 +11,44 @@ defmodule LolAnalytics.Dimensions.Match.MatchRepo do
case match do
nil ->
match_changeset =
MatchSchema.changeset(
%MatchSchema{},
%{match_id: match_id}
)
Repo.insert(match_changeset)
%MatchSchema{}
|> MatchSchema.changeset(%{
fact_champion_played_game_status: 0,
fact_champion_picked_item_status: 0,
fact_champion_picked_summoner_spell_status: 0
})
|> Repo.insert()
match ->
match
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
Repo.all(MatchSchema)
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

View File

@ -2,14 +2,24 @@ defmodule LolAnalytics.Dimensions.Match.MatchSchema do
use Ecto.Schema
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
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()
end
def changeset(match = %__MODULE__{}, attrs \\ %{}) do
match
|> cast(attrs, [:match_id])
|> cast(attrs, @casting_attrs)
|> validate_required([:match_id])
end
end

View File

@ -31,7 +31,7 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
:slot_number => integer()
}) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
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)
_player = PlayerRepo.get_or_create(attrs.puuid)
_patch = PatchRepo.get_or_create(attrs.patch_number)
@ -49,6 +49,8 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
Schema.changeset(prev || %Schema{}, attrs)
|> Repo.insert_or_update()
MatchRepo.update(match, %{fact_champion_picked_item: :processed})
end
@spec get_champion_picked_items(String.t(), String.t(), String.t()) :: list()

View File

@ -22,7 +22,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
:summoner_spell_id => String.t()
}) :: any()
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)
_player = PlayerRepo.get_or_create(attrs.puuid)
_spell = SummonerSpellRepo.get_or_create(attrs.summoner_spell_id)
@ -40,6 +40,8 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
Schema.changeset(prev || %Schema{}, attrs)
|> Repo.insert_or_update()
MatchRepo.update(match, %{fact_champion_picked_summoner_spell: :processed})
end
@spec get_champion_picked_summoners(String.t(), String.t(), String.t()) :: list()

View File

@ -10,7 +10,7 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
alias LoLAnalytics.Repo
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)
_player = PlayerRepo.get_or_create(attrs.puuid)
_patch = PatchRepo.get_or_create(attrs.patch_number)
@ -26,6 +26,7 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
changeset = Schema.changeset(prev || %Schema{}, attrs)
Repo.insert_or_update(changeset)
MatchRepo.update(match, %{fact_champion_played_game: :processed})
end
def list_played_matches() do

View File

@ -1,6 +1,10 @@
defmodule LolAnalytics.MatchesProcessor do
use GenServer
def init(init_args) do
{:ok, init_args}
end
@doc """
iex> LolAnalytics.MatchesProcessor.process_for_patch "14.12.593.5894"
"""

View File

@ -3,9 +3,9 @@ defmodule LoLAnalytics.Repo.Migrations.DimMatchFactProcessingStatus do
def change do
alter table("dim_match") do
add :fact_champion_played_game_status, :integer
add :fact_champion_picked_item_status, :integer
add :fact_champion_picked_summoner_spell_status, :integer
add :fact_champion_played_game_status, :integer, default: 0
add :fact_champion_picked_item_status, :integer, default: 0
add :fact_champion_picked_summoner_spell_status, :integer, default: 0
end
create index("dim_match", [:fact_champion_played_game_status])

View File

@ -21,7 +21,7 @@
"gen_stage": {:hex, :gen_stage, "1.2.1", "19d8b5e9a5996d813b8245338a28246307fd8b9c99d1237de199d21efc4c76a1", [:mix], [], "hexpm", "83e8be657fa05b992ffa6ac1e3af6d57aa50aace8f691fcf696ff02f8335b001"},
"gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},