This commit is contained in:
parent
90d54f85d9
commit
e0aa1b2476
54
README.md
54
README.md
@ -1 +1,53 @@
|
|||||||
# LoLAnalytics.Umbrella
|
# LoLAnalytics
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Postgresql
|
||||||
|
- Elixir
|
||||||
|
- RabbitMQ
|
||||||
|
- Minio
|
||||||
|
|
||||||
|
A `docker-compose` file is provided to run them locally.
|
||||||
|
|
||||||
|
## Environment variables
|
||||||
|
|
||||||
|
The followign environment variables are required:
|
||||||
|
|
||||||
|
```
|
||||||
|
export RIOT_API_KEY="API-KEY"
|
||||||
|
|
||||||
|
export EX_AWS_SECRET_KEY="{SECRET}"
|
||||||
|
export EX_AWS_ACCESS_KEY="{ACCESS}"
|
||||||
|
export EX_AWS_ENDPOINT="{HOST}"
|
||||||
|
export EX_AWS_PORT="{PORT}" # minio defaults to 9000
|
||||||
|
export DATABASE_URL="ecto://{USERNAME}:{PASSWORD}@{HOST}/lol-analytics"
|
||||||
|
export SECRET_KEY_BASE="SECRET-KEY"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
```
|
||||||
|
mix deps.get
|
||||||
|
mix compile
|
||||||
|
mix ecto.create && mix ecto.migrate
|
||||||
|
iex -S mix phx.server
|
||||||
|
```
|
||||||
|
|
||||||
|
## Queueing a player
|
||||||
|
|
||||||
|
```
|
||||||
|
Scrapper.Queues.PlayerQueue.enqueue_puuid("PUUID")
|
||||||
|
```
|
||||||
|
|
||||||
|
The scrapper will retrieve player ranked history, enqueue it's teammates, and store every match in minio.
|
||||||
|
|
||||||
|
## Processing
|
||||||
|
|
||||||
|
A `Task` to process the matches stored for a patch can be spawned by running:
|
||||||
|
```
|
||||||
|
LolAnalytics.MatchesProcessor.process_for_patch "14.12.594.4901"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Web site
|
||||||
|
|
||||||
|
A web site is exposed at `localhost:4000`.
|
@ -14,16 +14,16 @@ defmodule Scrapper.Queue.MatchQueue do
|
|||||||
{:ok, %{:channel => channel, :connection => connection}}
|
{:ok, %{:channel => channel, :connection => connection}}
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec queue_match(String.t()) :: any()
|
@spec enqueue_match(String.t()) :: any()
|
||||||
def queue_match(match_id) do
|
def enqueue_match(match_id) do
|
||||||
LolAnalytics.Match.MatchRepo.get_match(match_id)
|
LolAnalytics.Match.MatchRepo.get_match(match_id)
|
||||||
|> case do
|
|> case do
|
||||||
nil -> GenServer.call(__MODULE__, {:queue_match, match_id})
|
nil -> GenServer.call(__MODULE__, {:enqueue_match, match_id})
|
||||||
_match -> :already_processed
|
_match -> :already_processed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_call({:queue_match, match_id}, _from, %{:channel => channel} = state) do
|
def handle_call({:enqueue_match, match_id}, _from, %{:channel => channel} = state) do
|
||||||
AMQP.Basic.publish(channel, "", "match", match_id)
|
AMQP.Basic.publish(channel, "", "match", match_id)
|
||||||
{:reply, nil, state}
|
{:reply, nil, state}
|
||||||
end
|
end
|
||||||
|
@ -16,27 +16,27 @@ defmodule Scrapper.Queue.PlayerQueue do
|
|||||||
{:ok, {channel, connection}}
|
{:ok, {channel, connection}}
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec queue_puuid(String.t()) :: nil
|
@spec enqueue_puuid(String.t()) :: nil
|
||||||
def queue_puuid(puuid) do
|
def enqueue_puuid(puuid) do
|
||||||
case LolAnalytics.Player.PlayerRepo.get_player(puuid) do
|
case LolAnalytics.Player.PlayerRepo.get_player(puuid) do
|
||||||
nil -> GenServer.call(__MODULE__, {:queue_player, puuid})
|
nil -> GenServer.call(__MODULE__, {:enqueue_player, puuid})
|
||||||
player_entry -> queue_if_not_updated?(player_entry)
|
player_entry -> enqueue_if_not_updated?(player_entry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec queue_if_not_updated?(%LolAnalytics.Player.PlayerSchema{}) :: nil
|
@spec enqueue_if_not_updated?(%LolAnalytics.Player.PlayerSchema{}) :: nil
|
||||||
defp queue_if_not_updated?(player = %LolAnalytics.Player.PlayerSchema{}) do
|
defp enqueue_if_not_updated?(player = %LolAnalytics.Player.PlayerSchema{}) do
|
||||||
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
||||||
|
|
||||||
case player.last_processed_at do
|
case player.last_processed_at do
|
||||||
nil ->
|
nil ->
|
||||||
GenServer.call(__MODULE__, {:queue_player, player.puuid})
|
GenServer.call(__MODULE__, {:enqueue_player, player.puuid})
|
||||||
|
|
||||||
processed_at ->
|
processed_at ->
|
||||||
diff_in_hours = DateTime.diff(now, processed_at, :hour)
|
diff_in_hours = DateTime.diff(now, processed_at, :hour)
|
||||||
|
|
||||||
if diff_in_hours > @hours_to_update_player do
|
if diff_in_hours > @hours_to_update_player do
|
||||||
GenServer.call(__MODULE__, {:queue_player, player.puuid})
|
GenServer.call(__MODULE__, {:enqueue_player, player.puuid})
|
||||||
else
|
else
|
||||||
Logger.info(
|
Logger.info(
|
||||||
"Player #{player.puuid} already processed at #{player.last_processed_at}, diff was #{diff_in_hours}"
|
"Player #{player.puuid} already processed at #{player.last_processed_at}, diff was #{diff_in_hours}"
|
||||||
@ -45,7 +45,7 @@ defmodule Scrapper.Queue.PlayerQueue do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_call({:queue_player, puuid}, _from, {channel, _} = state) do
|
def handle_call({:enqueue_player, puuid}, _from, {channel, _} = state) do
|
||||||
LolAnalytics.Player.PlayerRepo.insert_player(puuid)
|
LolAnalytics.Player.PlayerRepo.insert_player(puuid)
|
||||||
AMQP.Basic.publish(channel, "", "player", puuid)
|
AMQP.Basic.publish(channel, "", "player", puuid)
|
||||||
{:reply, nil, state}
|
{:reply, nil, state}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user