Compare commits
No commits in common. "520c234a946bc4da217e84f90fc1894cd05cbecc" and "6053cfcdac75821f76bc4497f51d1b30af4403e4" have entirely different histories.
520c234a94
...
6053cfcdac
@ -1,19 +1,13 @@
|
|||||||
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
||||||
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
alias Hex.HTTP
|
||||||
@behaviour LolAnalytics.Analyzer
|
@behaviour LolAnalytics.Analyzer
|
||||||
|
|
||||||
def analyze_all_matches do
|
def analyze_all_matches do
|
||||||
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
Storage.MatchStorage.S3MatchStorage.list_files("ranked")
|
||||||
|> Enum.each(fn %{key: path} ->
|
|> Enum.map(& &1.key)
|
||||||
IO.inspect(path)
|
|> Enum.each(fn path ->
|
||||||
LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://192.168.1.55:9000/ranked/#{path}")
|
LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/#{path}")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
# Storage.MatchStorage.S3MatchStorage.list_files("ranked")
|
|
||||||
# |> Enum.map(& &1.key)
|
|
||||||
# |> Enum.each(fn path ->
|
|
||||||
# LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/#{path}")
|
|
||||||
# end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
@ -36,16 +30,12 @@ defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
|||||||
participants
|
participants
|
||||||
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
||||||
if participant.teamPosition != "" do
|
if participant.teamPosition != "" do
|
||||||
attrs = %{
|
LolAnalytics.ChampionWinRate.ChampionWinRateRepo.add_champion_win_rate(
|
||||||
champion_id: participant.championId,
|
participant.championId,
|
||||||
match_id: decoded_match.metadata.matchId,
|
version,
|
||||||
is_win: participant.win,
|
participant.teamPosition,
|
||||||
game_length_seconds: decoded_match.info.gameDuration,
|
participant.win
|
||||||
queue_id: decoded_match.info.queueId,
|
)
|
||||||
puuid: participant.puuid,
|
|
||||||
team_position: participant.teamPosition
|
|
||||||
}
|
|
||||||
LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.insert(attrs)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Champion.ChampionRepo do
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
|
||||||
|
|
||||||
@spec get_or_create(String.t()) :: struct()
|
|
||||||
def get_or_create(champion_id) do
|
|
||||||
champion = Repo.get_by(ChampionSchema, champion_id: champion_id)
|
|
||||||
|
|
||||||
case champion do
|
|
||||||
nil ->
|
|
||||||
changeset = ChampionSchema.changeset(%ChampionSchema{}, %{champion_id: champion_id})
|
|
||||||
Repo.insert(changeset)
|
|
||||||
|
|
||||||
champion ->
|
|
||||||
champion
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_champions() do
|
|
||||||
Repo.all(ChampionSchema)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Champion.ChampionSchema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
schema "dim_champion" do
|
|
||||||
field :champion_id, :integer
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(champion = %__MODULE__{}, attrs \\ %{}) do
|
|
||||||
champion
|
|
||||||
|> cast(attrs, [:champion_id])
|
|
||||||
|> validate_required([:champion_id])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Item.ItemRepo do
|
|
||||||
alias LolAnalytics.Dimensions.Item.ItemSchema
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
def get_or_create(item_id) do
|
|
||||||
item = Repo.get(ItemSchema, item_id: item_id)
|
|
||||||
|
|
||||||
case item do
|
|
||||||
nil ->
|
|
||||||
item_changeset = ItemSchema.changeset(%ItemSchema{}, %{item_id: item_id})
|
|
||||||
Repo.insert(item_changeset)
|
|
||||||
|
|
||||||
item ->
|
|
||||||
item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_items() do
|
|
||||||
Repo.all(ItemSchema)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Item.ItemSchema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
schema "dim_item" do
|
|
||||||
field :item_id, :integer
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(item = %__MODULE__{}, attrs \\ %{}) do
|
|
||||||
item
|
|
||||||
|> cast(attrs, [:item_id])
|
|
||||||
|> validate_required([:item_id])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Match.MatchRepo do
|
|
||||||
alias LolAnalytics.Dimensions.Match.MatchSchema
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
@spec get_or_create(String.t()) :: %MatchSchema{}
|
|
||||||
def get_or_create(match_id) do
|
|
||||||
query = from m in MatchSchema, where: m.match_id == ^match_id
|
|
||||||
match = Repo.one(query)
|
|
||||||
|
|
||||||
case match do
|
|
||||||
nil ->
|
|
||||||
match_changeset =
|
|
||||||
MatchSchema.changeset(
|
|
||||||
%MatchSchema{},
|
|
||||||
%{match_id: match_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
Repo.insert(match_changeset)
|
|
||||||
|
|
||||||
match ->
|
|
||||||
match
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_matches() do
|
|
||||||
Repo.all(MatchSchema)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Match.MatchSchema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
schema "dim_match" do
|
|
||||||
field :match_id, :string
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(match = %__MODULE__{}, attrs \\ %{}) do
|
|
||||||
match
|
|
||||||
|> cast(attrs, [:match_id])
|
|
||||||
|> validate_required([:match_id])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Patch.PatchRepo do
|
|
||||||
alias LolAnalytics.Dimensions.Patch.PatchSchema
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
def get_or_create(patch_number) do
|
|
||||||
patch = Repo.get(PatchSchema, patch_number: patch_number)
|
|
||||||
|
|
||||||
case patch do
|
|
||||||
nil ->
|
|
||||||
patch_changeset =
|
|
||||||
PatchSchema.changeset(
|
|
||||||
%PatchSchema{},
|
|
||||||
%{patch_number: patch_number}
|
|
||||||
)
|
|
||||||
|
|
||||||
Repo.insert(patch_changeset)
|
|
||||||
|
|
||||||
patch ->
|
|
||||||
patch
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_patches() do
|
|
||||||
Repo.all(PatchSchema)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Patch.PatchSchema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
schema "dim_patch" do
|
|
||||||
field :patch_number, :string
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(patch = %__MODULE__{}, attrs \\ %{}) do
|
|
||||||
patch
|
|
||||||
|> cast(attrs, [:patch_number])
|
|
||||||
|> validate_required([:patch_number])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Player.PlayerRepo do
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
alias LolAnalytics.Dimensions.Player.PlayerSchema
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
def get_or_create(puuid) do
|
|
||||||
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
|
||||||
player = Repo.one(query)
|
|
||||||
|
|
||||||
case player do
|
|
||||||
nil ->
|
|
||||||
player_changeset =
|
|
||||||
PlayerSchema.changeset(
|
|
||||||
%PlayerSchema{},
|
|
||||||
%{puuid: puuid}
|
|
||||||
)
|
|
||||||
Repo.insert(player_changeset)
|
|
||||||
|
|
||||||
player ->
|
|
||||||
player
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_players() do
|
|
||||||
Repo.all(PlayerSchema)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.Player.PlayerSchema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
schema "dim_player" do
|
|
||||||
field :puuid, :string
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(player = %__MODULE__{}, attrs \\ %{}) do
|
|
||||||
player
|
|
||||||
|> cast(attrs, [:puuid])
|
|
||||||
|> validate_required([:puuid])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo do
|
|
||||||
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
def get_or_create(spell_id) do
|
|
||||||
spell = Repo.get(SummonerSpellSchema, spell_id: spell_id)
|
|
||||||
|
|
||||||
case spell do
|
|
||||||
nil ->
|
|
||||||
spell_changeset =
|
|
||||||
SummonerSpellSchema.changeset(
|
|
||||||
%SummonerSpellSchema{},
|
|
||||||
%{spell_id: spell_id}
|
|
||||||
)
|
|
||||||
|
|
||||||
Repo.insert(spell_changeset)
|
|
||||||
|
|
||||||
spell ->
|
|
||||||
spell
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_spells() do
|
|
||||||
Repo.all(SummonerSpellSchema)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema do
|
|
||||||
use Ecto.Schema
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
schema "dim_summoner_spell" do
|
|
||||||
field :spell_id, :integer
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(summoner_spell = %__MODULE__{}, attrs) do
|
|
||||||
summoner_spell
|
|
||||||
|> cast(attrs, [:spell_id])
|
|
||||||
|> validate_required([:spell_id])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,27 +1,3 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo do
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo do
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
|
||||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
|
||||||
alias LolAnalytics.Dimensions.Match.MatchRepo
|
|
||||||
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
|
||||||
alias LolAnalytics.Facts.ChampionPlayedGame
|
|
||||||
alias LoLAnalytics.Repo
|
|
||||||
|
|
||||||
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)
|
|
||||||
IO.puts(">>>>")
|
|
||||||
IO.inspect(attrs)
|
|
||||||
changeset = ChampionPlayedGameSchema.changeset(%ChampionPlayedGameSchema{}, attrs)
|
|
||||||
|
|
||||||
IO.inspect(changeset)
|
|
||||||
Repo.insert(changeset)
|
|
||||||
# Repo.insert(match)
|
|
||||||
end
|
|
||||||
|
|
||||||
def list_played_matches() do
|
|
||||||
Repo.all(ChampionPlayedGameSchema)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,33 +1,11 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema do
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.Changeset
|
|
||||||
|
|
||||||
@casting_attrs [
|
|
||||||
:champion_id,
|
|
||||||
:match_id,
|
|
||||||
:is_win,
|
|
||||||
:game_length_seconds,
|
|
||||||
:team_position,
|
|
||||||
:puuid,
|
|
||||||
:queue_id
|
|
||||||
]
|
|
||||||
|
|
||||||
schema "fact_champion_played_game" do
|
schema "fact_champion_played_game" do
|
||||||
field :champion_id, :integer
|
field :champion_id, :integer
|
||||||
field :match_id, :string
|
field :match_id, :integer
|
||||||
field :is_win, :boolean
|
field :is_win, :boolean
|
||||||
field :game_length_seconds, :integer
|
field :game_length_seconds, :integer
|
||||||
field :team_position, :string
|
|
||||||
field :puuid, :string
|
|
||||||
field :queue_id, :integer
|
field :queue_id, :integer
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
def changeset(fact = %__MODULE__{}, attrs \\ %{}) do
|
|
||||||
fact
|
|
||||||
|> cast(attrs, @casting_attrs)
|
|
||||||
|> validate_required(@casting_attrs)
|
|
||||||
|> unique_constraint([:id, :champion_id, :queue_id])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -42,7 +42,6 @@ defmodule LoLAnalytics.MixProject do
|
|||||||
{:postgrex, ">= 0.0.0"},
|
{:postgrex, ">= 0.0.0"},
|
||||||
{:jason, "~> 1.2"},
|
{:jason, "~> 1.2"},
|
||||||
{:lol_api, in_umbrella: true},
|
{:lol_api, in_umbrella: true},
|
||||||
{:storage, in_umbrella: true},
|
|
||||||
{:httpoison, "~> 2.2"},
|
{:httpoison, "~> 2.2"},
|
||||||
{:poison, "~> 5.0"}
|
{:poison, "~> 5.0"}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -2,61 +2,50 @@ defmodule LoLAnalytics.Repo.Migrations.AnalyticsTables do
|
|||||||
use Ecto.Migration
|
use Ecto.Migration
|
||||||
|
|
||||||
def change do
|
def change do
|
||||||
create table("dim_champion") do
|
create table("dom_champion") do
|
||||||
add :champion_id, :integer, primary_key: true, null: false
|
add :champion_id, :integer, primary_key: true
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("dim_champion", [:champion_id], unique: true)
|
create table("dom_match") do
|
||||||
|
add :match_id, :integer, primary_key: true
|
||||||
create table("dim_item") do
|
|
||||||
add :item_id, :integer, primary_key: true, null: false
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("dim_item", [:item_id], unique: true)
|
create index("dom_match", [:match_id], unique: true)
|
||||||
|
|
||||||
create table("dim_match") do
|
create table("dom_patch") do
|
||||||
add :match_id, :string, primary_key: true, null: false
|
add :patch_number, :string, primary_key: true
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("dim_match", [:match_id], unique: true)
|
create index("dom_patch", [:patch_number], unique: true)
|
||||||
|
|
||||||
create table("dim_patch") do
|
create table("dom_item") do
|
||||||
add :patch_number, :string, primary_key: true, null: false
|
add :item_id, :integer, primary_key: true
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("dim_patch", [:patch_number], unique: true)
|
create index("dom_item", [:item_id], unique: true)
|
||||||
|
|
||||||
create table("dim_player") do
|
create table("dom_summoner_spell") do
|
||||||
add :puuid, :string, primary_key: true, null: false
|
add :spell_id, :integer, primary_key: true
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("dim_player", [:puuid], unique: true)
|
create index("dom_summoner_spell", [:spell_id], unique: true)
|
||||||
|
|
||||||
create table("dim_summoner_spell") do
|
|
||||||
add :spell_id, :integer, primary_key: true, null: false
|
|
||||||
timestamps()
|
|
||||||
end
|
|
||||||
|
|
||||||
create index("dim_summoner_spell", [:spell_id], unique: true)
|
|
||||||
|
|
||||||
create table("fact_champion_played_game") do
|
create table("fact_champion_played_game") do
|
||||||
add :champion_id, references("dim_champion", column: :champion_id, type: :integer)
|
add :champion_id, references("dom_champion", with: [champion_id: :champion_id]),
|
||||||
add :match_id, references("dim_match", column: :match_id, type: :string)
|
primary_key: true
|
||||||
|
|
||||||
|
add :match_id, references("dom_match", with: [match_id: :match_id])
|
||||||
add :is_win, :boolean
|
add :is_win, :boolean
|
||||||
add :game_length_seconds, :integer
|
add :game_length_seconds, :integer
|
||||||
add :queue_id, :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)
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
create index("fact_champion_played_game", [:id, :champion_id, :queue_id])
|
create index("fact_champion_played_game", [:id, :champion_id, :queue_id])
|
||||||
create index("fact_champion_played_game", [:puuid, :match_id], unique: true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
services:
|
|
||||||
db:
|
|
||||||
image: postgres:latest
|
|
||||||
volumes:
|
|
||||||
- postgres-data:/var/lib/postgresql/data
|
|
||||||
environment:
|
|
||||||
POSTGRES_PASSWORD: postgres
|
|
||||||
POSTGRES_USER: postgres
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
rabbitmq:
|
|
||||||
image: rabbitmq:3-management-alpine
|
|
||||||
container_name: 'rabbitmq'
|
|
||||||
ports:
|
|
||||||
- "15671:15671"
|
|
||||||
- "15672:15672"
|
|
||||||
- "15691:15691"
|
|
||||||
- "15692:15692"
|
|
||||||
- "25672:25672"
|
|
||||||
- "4639:4639"
|
|
||||||
- "5671:5671"
|
|
||||||
- "5672:5672"
|
|
||||||
volumes:
|
|
||||||
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
|
|
||||||
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
|
|
||||||
networks:
|
|
||||||
- rabbitmq_go_net
|
|
||||||
volumes:
|
|
||||||
postgres-data:
|
|
||||||
|
|
||||||
|
|
||||||
networks:
|
|
||||||
rabbitmq_go_net:
|
|
||||||
driver: bridge
|
|
||||||
10
queries.md
10
queries.md
@ -1,10 +0,0 @@
|
|||||||
```
|
|
||||||
SELECT
|
|
||||||
(cast(count(CASE WHEN is_win THEN 1 END) as float) / cast(count(*) as float)) * 100.0 as win_rate,
|
|
||||||
count(CASE WHEN is_win THEN 1 END) as games_won,
|
|
||||||
count(*) as total_games,
|
|
||||||
champion_id
|
|
||||||
FROM fact_champion_played_game
|
|
||||||
GROUP BY champion_id
|
|
||||||
ORDER BY win_rate desc;
|
|
||||||
```
|
|
||||||
Loading…
x
Reference in New Issue
Block a user