This commit is contained in:
parent
4371701ca9
commit
4823e68700
@ -11,5 +11,6 @@ defmodule LolAnalytics.Dimensions.Patch.PatchSchema do
|
||||
patch
|
||||
|> cast(attrs, [:patch_number])
|
||||
|> validate_required([:patch_number])
|
||||
|> unique_constraint([:patch_number])
|
||||
end
|
||||
end
|
||||
|
@ -6,15 +6,15 @@ defmodule LolAnalytics.Dimensions.Player.PlayerRepo do
|
||||
|
||||
def get_or_create(puuid) do
|
||||
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
||||
player = Repo.one(query)
|
||||
|
||||
case player do
|
||||
case Repo.one(query) do
|
||||
nil ->
|
||||
player_changeset =
|
||||
PlayerSchema.changeset(
|
||||
%PlayerSchema{},
|
||||
%{puuid: puuid}
|
||||
)
|
||||
|
||||
Repo.insert(player_changeset)
|
||||
|
||||
player ->
|
||||
|
@ -1,15 +1,25 @@
|
||||
defmodule LolAnalytics.Facts.ChampionPickedItem.FactProcessor do
|
||||
alias LolAnalytics.Facts.ChampionPickedItem.Repo
|
||||
require Logger
|
||||
@behaviour LolAnalytics.Facts.FactBehaviour
|
||||
|
||||
@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
|
||||
def process_game_at_url(url) do
|
||||
data = HTTPoison.get!(url)
|
||||
process_game_data(data.body)
|
||||
case HTTPoison.get(url) do
|
||||
{: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
|
||||
|
||||
defp process_game_data(data) do
|
||||
@ -24,10 +34,22 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.FactProcessor do
|
||||
if participant.teamPosition != "" do
|
||||
[:item0, :item1, :item2, :item3, :item4, :item5, :item6]
|
||||
|> Enum.with_index()
|
||||
|> Enum.map(fn {item_key, index} ->
|
||||
{index, Map.get(participant, item_key)}
|
||||
|> Enum.each(fn {item_key, index} ->
|
||||
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)
|
||||
|> IO.inspect()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
@ -30,7 +30,6 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
|
||||
:slot_number => integer()
|
||||
}) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
|
||||
def insert(attrs) do
|
||||
IO.inspect(attrs)
|
||||
_match = MatchRepo.get_or_create(attrs.match_id)
|
||||
_champion = ChampionRepo.get_or_create(attrs.champion_id)
|
||||
_player = PlayerRepo.get_or_create(attrs.puuid)
|
||||
@ -57,7 +56,8 @@ defmodule LolAnalytics.Facts.ChampionPickedItem.Repo do
|
||||
from f in Schema,
|
||||
where:
|
||||
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,
|
||||
on: c.champion_id == f.champion_id,
|
||||
join: i in ItemSchema,
|
||||
|
@ -8,8 +8,16 @@ defmodule LolAnalytics.Facts.ChampionPickedSummonerSpell.FactProcessor do
|
||||
@impl true
|
||||
@spec process_game_at_url(String.t()) :: any()
|
||||
def process_game_at_url(url) do
|
||||
data = HTTPoison.get!(url)
|
||||
process_game_data(data.body)
|
||||
case HTTPoison.get(url) do
|
||||
{: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
|
||||
|
||||
defp process_game_data(data) do
|
||||
|
@ -14,7 +14,6 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.Repo do
|
||||
_champion = ChampionRepo.get_or_create(attrs.champion_id)
|
||||
_player = PlayerRepo.get_or_create(attrs.puuid)
|
||||
_patch = PatchRepo.get_or_create(attrs.patch_number)
|
||||
changeset = Schema.changeset(%Schema{}, attrs)
|
||||
|
||||
prev =
|
||||
from(f in Schema,
|
||||
|
@ -5,9 +5,17 @@ defmodule LolAnalytics.Facts.ChampionPlayedGame.FactProcessor do
|
||||
|
||||
@impl true
|
||||
@spec process_game_at_url(String.t()) :: none()
|
||||
def process_game_at_url(path) do
|
||||
data = HTTPoison.get!(path)
|
||||
process_game_data(data.body)
|
||||
def process_game_at_url(url) do
|
||||
case HTTPoison.get(url) do
|
||||
{: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
|
||||
|
||||
def process_game_data(data) do
|
||||
|
@ -6,6 +6,7 @@ defmodule LolAnalytics.Facts.FactsRunner do
|
||||
|> peach(fn %{key: path} ->
|
||||
get_facts()
|
||||
|> Enum.each(fn fact_runner ->
|
||||
IO.inspect(path)
|
||||
apply(fact_runner, ["http://192.168.1.55:9000/ranked/#{path}"])
|
||||
end)
|
||||
end)
|
||||
@ -16,12 +17,13 @@ defmodule LolAnalytics.Facts.FactsRunner do
|
||||
|
||||
def get_facts() do
|
||||
[
|
||||
&Facts.ChampionPickedSummonerSpell.FactProcessor.process_game_at_url/1,
|
||||
&Facts.ChampionPlayedGame.FactProcessor.process_game_at_url/1
|
||||
# &Facts.ChampionPickedSummonerSpell.FactProcessor.process_game_at_url/1,
|
||||
# &Facts.ChampionPlayedGame.FactProcessor.process_game_at_url/1,
|
||||
&Facts.ChampionPickedItem.FactProcessor.process_game_at_url/1
|
||||
]
|
||||
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)
|
||||
|> Stream.each(fn {:ok, val} -> val end)
|
||||
|> Enum.to_list()
|
||||
|
Loading…
x
Reference in New Issue
Block a user