This commit is contained in:
parent
0c72f96e16
commit
ce825b75b1
@ -2,10 +2,12 @@ defmodule LolAnalytics.Dimensions.Patch.PatchRepo do
|
|||||||
alias LolAnalytics.Dimensions.Patch.PatchSchema
|
alias LolAnalytics.Dimensions.Patch.PatchSchema
|
||||||
alias LoLAnalytics.Repo
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
def get_or_create(patch_number) do
|
import Ecto.Query
|
||||||
patch = Repo.get(PatchSchema, patch_number: patch_number)
|
|
||||||
|
|
||||||
case patch do
|
def get_or_create(patch_number) do
|
||||||
|
query = from p in PatchSchema, where: p.patch_number == ^patch_number
|
||||||
|
|
||||||
|
case Repo.one(query) do
|
||||||
nil ->
|
nil ->
|
||||||
patch_changeset =
|
patch_changeset =
|
||||||
PatchSchema.changeset(
|
PatchSchema.changeset(
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
||||||
alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
require Logger
|
||||||
|
|
||||||
|
alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
||||||
|
|
||||||
def process_game_at_url(url) do
|
def process_game_at_url(url) do
|
||||||
data = HTTPoison.get!(url)
|
data = HTTPoison.get!(url)
|
||||||
@ -11,10 +13,11 @@ alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
|||||||
participants = decoded_match.info.participants
|
participants = decoded_match.info.participants
|
||||||
version = extract_game_version(decoded_match)
|
version = extract_game_version(decoded_match)
|
||||||
|
|
||||||
|
Logger.info("Processing ChampionPickedSummoner for match #{decoded_match.metadata.matchId}")
|
||||||
|
|
||||||
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_spell_1 = %{
|
attrs_spell_1 = %{
|
||||||
champion_id: participant.championId,
|
champion_id: participant.championId,
|
||||||
match_id: decoded_match.metadata.matchId,
|
match_id: decoded_match.metadata.matchId,
|
||||||
@ -26,6 +29,7 @@ alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
|||||||
team_position: participant.teamPosition,
|
team_position: participant.teamPosition,
|
||||||
patch_number: version
|
patch_number: version
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs_spell_2 = %{
|
attrs_spell_2 = %{
|
||||||
champion_id: participant.championId,
|
champion_id: participant.championId,
|
||||||
match_id: decoded_match.metadata.matchId,
|
match_id: decoded_match.metadata.matchId,
|
||||||
@ -37,6 +41,7 @@ alias LolAnalytics.Facts.ChampionPickedSummonerSpell
|
|||||||
team_position: participant.teamPosition,
|
team_position: participant.teamPosition,
|
||||||
patch_number: version
|
patch_number: version
|
||||||
}
|
}
|
||||||
|
|
||||||
ChampionPickedSummonerSpell.Repo.insert(attrs_spell_1)
|
ChampionPickedSummonerSpell.Repo.insert(attrs_spell_1)
|
||||||
ChampionPickedSummonerSpell.Repo.insert(attrs_spell_2)
|
ChampionPickedSummonerSpell.Repo.insert(attrs_spell_2)
|
||||||
end
|
end
|
||||||
|
@ -39,10 +39,7 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo do
|
|||||||
|
|
||||||
changeset = Schema.changeset(prev || %Schema{}, attrs)
|
changeset = Schema.changeset(prev || %Schema{}, attrs)
|
||||||
|
|
||||||
IO.inspect(attrs)
|
|
||||||
|
|
||||||
Repo.insert_or_update(changeset)
|
Repo.insert_or_update(changeset)
|
||||||
|> IO.inspect()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_champion_picked_summoners(championId, team_position \\ "MIDDLE") do
|
def get_champion_picked_summoners(championId, team_position \\ "MIDDLE") do
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias LolAnalytics.Dimensions.Patch.PatchRepo
|
||||||
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
||||||
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
||||||
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
||||||
@ -12,8 +13,20 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo 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)
|
||||||
changeset = Schema.changeset(%Schema{}, attrs)
|
changeset = Schema.changeset(%Schema{}, attrs)
|
||||||
Repo.insert(changeset)
|
|
||||||
|
prev =
|
||||||
|
from(f in Schema,
|
||||||
|
where:
|
||||||
|
f.match_id == ^attrs.match_id and
|
||||||
|
f.champion_id == ^attrs.champion_id and f.queue_id == ^attrs.queue_id
|
||||||
|
)
|
||||||
|
|> Repo.one()
|
||||||
|
|
||||||
|
changeset = Schema.changeset(prev || %Schema{}, attrs)
|
||||||
|
|
||||||
|
Repo.update(changeset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_played_matches() do
|
def list_played_matches() do
|
||||||
@ -46,6 +59,34 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
|||||||
Repo.all(query)
|
Repo.all(query)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_win_rates_by_patch(champion_id) do
|
||||||
|
query =
|
||||||
|
from m in Schema,
|
||||||
|
join: c in ChampionSchema,
|
||||||
|
on: c.champion_id == m.champion_id,
|
||||||
|
select: %{
|
||||||
|
wins: fragment("count(CASE WHEN ? THEN 1 END)", m.is_win),
|
||||||
|
win_rate:
|
||||||
|
fragment(
|
||||||
|
"
|
||||||
|
((cast(count(CASE WHEN ? THEN 1 END) as float) / cast(count(*) as float)) * 100.0
|
||||||
|
)",
|
||||||
|
m.is_win
|
||||||
|
),
|
||||||
|
id: m.champion_id,
|
||||||
|
patch_number: m.patch_number,
|
||||||
|
name: c.name,
|
||||||
|
image: c.image,
|
||||||
|
team_position: m.team_position,
|
||||||
|
total_games: count("*")
|
||||||
|
},
|
||||||
|
where: c.champion_id == ^champion_id,
|
||||||
|
group_by: [m.champion_id, c.image, c.name, m.team_position, m.patch_number],
|
||||||
|
having: count("*") > 100
|
||||||
|
|
||||||
|
Repo.all(query)
|
||||||
|
end
|
||||||
|
|
||||||
def get_win_rates_by_roles() do
|
def get_win_rates_by_roles() do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Schema do
|
|||||||
@casting_attrs [
|
@casting_attrs [
|
||||||
:champion_id,
|
:champion_id,
|
||||||
:match_id,
|
:match_id,
|
||||||
|
:patch_number,
|
||||||
:is_win,
|
:is_win,
|
||||||
:game_length_seconds,
|
:game_length_seconds,
|
||||||
:team_position,
|
:team_position,
|
||||||
@ -16,6 +17,7 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Schema do
|
|||||||
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, :string
|
||||||
|
field :patch_number, :string
|
||||||
field :is_win, :boolean
|
field :is_win, :boolean
|
||||||
field :game_length_seconds, :integer
|
field :game_length_seconds, :integer
|
||||||
field :team_position, :string
|
field :team_position, :string
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
||||||
|
require Logger
|
||||||
|
|
||||||
def process_game_at_url(path) do
|
def process_game_at_url(path) do
|
||||||
data = HTTPoison.get!(path)
|
data = HTTPoison.get!(path)
|
||||||
process_game_data(data.body)
|
process_game_data(data.body)
|
||||||
@ -9,6 +11,8 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
|||||||
participants = decoded_match.info.participants
|
participants = decoded_match.info.participants
|
||||||
version = extract_game_version(decoded_match)
|
version = extract_game_version(decoded_match)
|
||||||
|
|
||||||
|
Logger.info("Processing ChampionPlayedMatch for #{decoded_match.metadata.matchId}")
|
||||||
|
|
||||||
participants
|
participants
|
||||||
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
||||||
if participant.teamPosition != "" do
|
if participant.teamPosition != "" do
|
||||||
|
@ -3,7 +3,7 @@ defmodule LolAnalytics.Facts.FactsRunner do
|
|||||||
|
|
||||||
def analyze_all_matches do
|
def analyze_all_matches do
|
||||||
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
||||||
|> Enum.each(fn %{key: path} ->
|
|> peach(fn %{key: path} ->
|
||||||
get_facts()
|
get_facts()
|
||||||
|> Enum.each(fn fact_runner ->
|
|> Enum.each(fn fact_runner ->
|
||||||
apply(fact_runner, ["http://192.168.1.55:9000/ranked/#{path}"])
|
apply(fact_runner, ["http://192.168.1.55:9000/ranked/#{path}"])
|
||||||
@ -16,7 +16,14 @@ defmodule LolAnalytics.Facts.FactsRunner do
|
|||||||
|
|
||||||
def get_facts() do
|
def get_facts() do
|
||||||
[
|
[
|
||||||
&Facts.ChampionPickedSummonerSpell.FactProcessor.process_game_at_url/1
|
&Facts.ChampionPickedSummonerSpell.FactProcessor.process_game_at_url/1,
|
||||||
|
&Facts.ChampionPlayedGame.FactProcessor.process_game_at_url/1
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def peach(enum, fun, concurrency \\ 10, timeout \\ :infinity) do
|
||||||
|
Task.async_stream(enum, &fun.(&1), max_concurrency: concurrency, timeout: timeout)
|
||||||
|
|> Stream.each(fn {:ok, val} -> val end)
|
||||||
|
|> Enum.to_list()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user