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}}
|
||||
end
|
||||
|
||||
@spec queue_match(String.t()) :: any()
|
||||
def queue_match(match_id) do
|
||||
@spec enqueue_match(String.t()) :: any()
|
||||
def enqueue_match(match_id) do
|
||||
LolAnalytics.Match.MatchRepo.get_match(match_id)
|
||||
|> case do
|
||||
nil -> GenServer.call(__MODULE__, {:queue_match, match_id})
|
||||
nil -> GenServer.call(__MODULE__, {:enqueue_match, match_id})
|
||||
_match -> :already_processed
|
||||
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)
|
||||
{:reply, nil, state}
|
||||
end
|
||||
|
@ -16,27 +16,27 @@ defmodule Scrapper.Queue.PlayerQueue do
|
||||
{:ok, {channel, connection}}
|
||||
end
|
||||
|
||||
@spec queue_puuid(String.t()) :: nil
|
||||
def queue_puuid(puuid) do
|
||||
@spec enqueue_puuid(String.t()) :: nil
|
||||
def enqueue_puuid(puuid) do
|
||||
case LolAnalytics.Player.PlayerRepo.get_player(puuid) do
|
||||
nil -> GenServer.call(__MODULE__, {:queue_player, puuid})
|
||||
player_entry -> queue_if_not_updated?(player_entry)
|
||||
nil -> GenServer.call(__MODULE__, {:enqueue_player, puuid})
|
||||
player_entry -> enqueue_if_not_updated?(player_entry)
|
||||
end
|
||||
end
|
||||
|
||||
@spec queue_if_not_updated?(%LolAnalytics.Player.PlayerSchema{}) :: nil
|
||||
defp queue_if_not_updated?(player = %LolAnalytics.Player.PlayerSchema{}) do
|
||||
@spec enqueue_if_not_updated?(%LolAnalytics.Player.PlayerSchema{}) :: nil
|
||||
defp enqueue_if_not_updated?(player = %LolAnalytics.Player.PlayerSchema{}) do
|
||||
now = DateTime.utc_now() |> DateTime.truncate(:second)
|
||||
|
||||
case player.last_processed_at do
|
||||
nil ->
|
||||
GenServer.call(__MODULE__, {:queue_player, player.puuid})
|
||||
GenServer.call(__MODULE__, {:enqueue_player, player.puuid})
|
||||
|
||||
processed_at ->
|
||||
diff_in_hours = DateTime.diff(now, processed_at, :hour)
|
||||
|
||||
if diff_in_hours > @hours_to_update_player do
|
||||
GenServer.call(__MODULE__, {:queue_player, player.puuid})
|
||||
GenServer.call(__MODULE__, {:enqueue_player, player.puuid})
|
||||
else
|
||||
Logger.info(
|
||||
"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
|
||||
|
||||
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)
|
||||
AMQP.Basic.publish(channel, "", "player", puuid)
|
||||
{:reply, nil, state}
|
||||
|
Loading…
x
Reference in New Issue
Block a user