This commit is contained in:
parent
4371701ca9
commit
4823e68700
@ -11,5 +11,6 @@ defmodule LolAnalytics.Dimensions.Patch.PatchSchema do
|
|||||||
patch
|
patch
|
||||||
|> cast(attrs, [:patch_number])
|
|> cast(attrs, [:patch_number])
|
||||||
|> validate_required([:patch_number])
|
|> validate_required([:patch_number])
|
||||||
|
|> unique_constraint([:patch_number])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,15 +6,15 @@ defmodule LolAnalytics.Dimensions.Player.PlayerRepo do
|
|||||||
|
|
||||||
def get_or_create(puuid) do
|
def get_or_create(puuid) do
|
||||||
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
||||||
player = Repo.one(query)
|
|
||||||
|
|
||||||
case player do
|
case Repo.one(query) do
|
||||||
nil ->
|
nil ->
|
||||||
player_changeset =
|
player_changeset =
|
||||||
PlayerSchema.changeset(
|
PlayerSchema.changeset(
|
||||||
%PlayerSchema{},
|
%PlayerSchema{},
|
||||||
%{puuid: puuid}
|
%{puuid: puuid}
|
||||||
)
|
)
|
||||||
|
|
||||||
Repo.insert(player_changeset)
|
Repo.insert(player_changeset)
|
||||||
|
|
||||||
player ->
|
player ->
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
defmodule LolAnalytics.Facts.ChampionPickedItem.FactProcessor do
|
defmodule LolAnalytics.Facts.ChampionPickedItem.FactProcessor do
|
||||||
|
alias LolAnalytics.Facts.ChampionPickedItem.Repo
|
||||||
require Logger
|
require Logger
|
||||||
@behaviour LolAnalytics.Facts.FactBehaviour
|
@behaviour LolAnalytics.Facts.FactBehaviour
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
||||||
iex> LolAnalytics.Facts.ChampionPickedItem.FactProcessor.process_game_at_url("http://192.168.1.55:9000/ranked/EUW1_6923405153.json")
|
iex> LolAnalytics.Facts.ChampionPickedItem.FactProcessor.process_game_at_url("http://192.168.1.55:9000/ranked/14.3.558.106/EUW1_6803789466.json")
|
||||||
"""
|
"""
|
||||||
@impl true
|
@impl true
|
||||||
def process_game_at_url(url) do
|
def process_game_at_url(url) do
|
||||||
data = HTTPoison.get!(url)
|
case HTTPoison.get(url) do
|
||||||
process_game_data(data.body)
|
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
|
||||||
|
IO.inspect(url)
|
||||||
|
process_game_data(body)
|
||||||
|
|
||||||
|
{:error, %HTTPoison.Error{reason: reason}} ->
|
||||||
|
{:error, reason}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, "Could not fetch data from #{url}"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp process_game_data(data) do
|
defp process_game_data(data) do
|
||||||
@ -24,10 +34,22 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.FactProcessor do
|
|||||||
if participant.teamPosition != "" do
|
if participant.teamPosition != "" do
|
||||||
[:item0, :item1, :item2, :item3, :item4, :item5, :item6]
|
[:item0, :item1, :item2, :item3, :item4, :item5, :item6]
|
||||||
|> Enum.with_index()
|
|> Enum.with_index()
|
||||||
|> Enum.map(fn {item_key, index} ->
|
|> Enum.each(fn {item_key, index} ->
|
||||||
{index, Map.get(participant, item_key)}
|
item_key = Map.get(participant, item_key)
|
||||||
|
|
||||||
|
Repo.insert(%{
|
||||||
|
champion_id: participant.championId,
|
||||||
|
match_id: decoded_match.metadata.matchId,
|
||||||
|
is_win: participant.win,
|
||||||
|
item_id: item_key,
|
||||||
|
slot_number: index,
|
||||||
|
game_length_seconds: decoded_match.info.gameDuration,
|
||||||
|
queue_id: decoded_match.info.queueId,
|
||||||
|
puuid: participant.puuid,
|
||||||
|
team_position: participant.teamPosition,
|
||||||
|
patch_number: version
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|> IO.inspect()
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,6 @@ 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
|
||||||
IO.inspect(attrs)
|
|
||||||
_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)
|
||||||
@ -57,7 +56,8 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
|
|||||||
from f in Schema,
|
from f in Schema,
|
||||||
where:
|
where:
|
||||||
f.champion_id == ^champion_id and
|
f.champion_id == ^champion_id and
|
||||||
f.team_position == ^team_position,
|
f.team_position == ^team_position and
|
||||||
|
f.item_id != 0,
|
||||||
join: c in ChampionSchema,
|
join: c in ChampionSchema,
|
||||||
on: c.champion_id == f.champion_id,
|
on: c.champion_id == f.champion_id,
|
||||||
join: i in ItemSchema,
|
join: i in ItemSchema,
|
||||||
|
@ -8,8 +8,16 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
|||||||
@impl true
|
@impl true
|
||||||
@spec process_game_at_url(String.t()) :: any()
|
@spec process_game_at_url(String.t()) :: any()
|
||||||
def process_game_at_url(url) do
|
def process_game_at_url(url) do
|
||||||
data = HTTPoison.get!(url)
|
case HTTPoison.get(url) do
|
||||||
process_game_data(data.body)
|
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
|
||||||
|
process_game_data(body)
|
||||||
|
|
||||||
|
{:error, %HTTPoison.Error{reason: reason}} ->
|
||||||
|
{:error, reason}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, "Could not fetch data from #{url}"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp process_game_data(data) do
|
defp process_game_data(data) do
|
||||||
|
@ -14,7 +14,6 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
|||||||
_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)
|
||||||
changeset = Schema.changeset(%Schema{}, attrs)
|
|
||||||
|
|
||||||
prev =
|
prev =
|
||||||
from(f in Schema,
|
from(f in Schema,
|
||||||
|
@ -5,9 +5,17 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
|||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec process_game_at_url(String.t()) :: none()
|
@spec process_game_at_url(String.t()) :: none()
|
||||||
def process_game_at_url(path) do
|
def process_game_at_url(url) do
|
||||||
data = HTTPoison.get!(path)
|
case HTTPoison.get(url) do
|
||||||
process_game_data(data.body)
|
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
|
||||||
|
process_game_data(body)
|
||||||
|
|
||||||
|
{:error, %HTTPoison.Error{reason: reason}} ->
|
||||||
|
{:error, reason}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, "Could not fetch data from #{url}"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_game_data(data) do
|
def process_game_data(data) do
|
||||||
|
@ -6,6 +6,7 @@ defmodule LolAnalytics.Facts.FactsRunner do
|
|||||||
|> peach(fn %{key: path} ->
|
|> peach(fn %{key: path} ->
|
||||||
get_facts()
|
get_facts()
|
||||||
|> Enum.each(fn fact_runner ->
|
|> Enum.each(fn fact_runner ->
|
||||||
|
IO.inspect(path)
|
||||||
apply(fact_runner, ["http://192.168.1.55:9000/ranked/#{path}"])
|
apply(fact_runner, ["http://192.168.1.55:9000/ranked/#{path}"])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
@ -16,12 +17,13 @@ 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
|
# &Facts.ChampionPlayedGame.FactProcessor.process_game_at_url/1,
|
||||||
|
&Facts.ChampionPickedItem.FactProcessor.process_game_at_url/1
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def peach(enum, fun, concurrency \\ System.schedulers_online() * 2, timeout \\ :infinity) do
|
def peach(enum, fun, concurrency \\ System.schedulers_online(), timeout \\ :infinity) do
|
||||||
Task.async_stream(enum, &fun.(&1), max_concurrency: concurrency, timeout: timeout)
|
Task.async_stream(enum, &fun.(&1), max_concurrency: concurrency, timeout: timeout)
|
||||||
|> Stream.each(fn {:ok, val} -> val end)
|
|> Stream.each(fn {:ok, val} -> val end)
|
||||||
|> Enum.to_list()
|
|> Enum.to_list()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user