-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move storage and api to apps, create base analyzer
- Loading branch information
1 parent
987339f
commit 2e56c71
Showing
42 changed files
with
401 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ erl_crash.dump | |
|
||
.env | ||
|
||
|
||
.DS_store |
3 changes: 3 additions & 0 deletions
3
apps/lol_analytics/lib/lol_analytics/analyzer/base_analyzer.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defmodule LolAnalytics.Analyzer.BaseAnalyzer do | ||
@callback analyze(:url, path :: String.t()) :: :ok | ||
end |
32 changes: 32 additions & 0 deletions
32
apps/lol_analytics/lib/lol_analytics/analyzer/champion_analyzer.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do | ||
alias Hex.HTTP | ||
@behaviour LolAnalytics.Analyzer.BaseAnalyzer | ||
|
||
@doc """ | ||
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "https://na1.api.riotgames.com/lol/match/v4/match/234567890123456789") | ||
:ok | ||
""" | ||
@impl true | ||
@spec analyze(atom(), String.t()) :: :ok | ||
def analyze(:url, path) do | ||
data = HTTPoison.get!(path) | ||
analyze(:data, data.body) | ||
:ok | ||
end | ||
|
||
@doc """ | ||
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/14.9.580.2108/EUW1_6923309745.json") | ||
""" | ||
@impl true | ||
@spec analyze(atom(), any()) :: list(LoLAPI.Model.Participant.t()) | ||
def analyze(:data, data) do | ||
decoded = Poison.decode!(data) | ||
|
||
%{"info" => %{"participants" => participants}} = decoded | ||
|
||
participants | ||
|> Enum.each(fn %{"win" => win, "championId" => champion_id} -> | ||
IO.inspect(%{win: win, champion_id: champion_id}) | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
lol_api-*.tar | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# LoLAPI | ||
|
||
**TODO: Add description** | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `lol_api` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
{:lol_api, "~> 0.1.0"} | ||
] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at <https://hexdocs.pm/lol_api>. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Config | ||
|
||
config :lol_api, | ||
riot_api_key: System.get_env("RIOT_API_KEY") |
4 changes: 3 additions & 1 deletion
4
.../scrapper/lib/scrapper/api/account_api.ex → apps/lol_api/lib/api/account_api.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
apps/scrapper/lib/scrapper/api/model/info.ex → apps/lol_api/lib/api/model/info.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule LoLAPI.Model.MatchResponse do | ||
alias LoLAPI.Model.{Info, Metadata} | ||
|
||
defstruct metadata: %Metadata{}, | ||
info: %Info{} | ||
end |
2 changes: 1 addition & 1 deletion
2
...rapper/lib/scrapper/api/model/metadata.ex → apps/lol_api/lib/api/model/metadata.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
defmodule Scrapper.Api.Model.Metadata do | ||
defmodule LoLAPI.Model.Metadata do | ||
defstruct [:dataVersion, :matchId, :participants] | ||
end |
2 changes: 1 addition & 1 deletion
2
...per/lib/scrapper/api/model/participant.ex → apps/lol_api/lib/api/model/participant.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule LoLAPI do | ||
@moduledoc """ | ||
Documentation for `LoLAPI`. | ||
""" | ||
|
||
@doc """ | ||
Hello world. | ||
## Examples | ||
iex> LoLAPI.hello() | ||
:world | ||
""" | ||
def hello do | ||
:world | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule LoLAPI.MixProject do | ||
use Mix.Project | ||
|
||
def project do | ||
[ | ||
app: :lol_api, | ||
version: "0.1.0", | ||
build_path: "../../_build", | ||
config_path: "../../config/config.exs", | ||
deps_path: "../../deps", | ||
lockfile: "../../mix.lock", | ||
elixir: "~> 1.16", | ||
start_permanent: Mix.env() == :prod, | ||
deps: deps() | ||
] | ||
end | ||
|
||
# Run "mix help compile.app" to learn about applications. | ||
def application do | ||
[ | ||
extra_applications: [:logger] | ||
] | ||
end | ||
|
||
# Run "mix help deps" to learn about dependencies. | ||
defp deps do | ||
[ | ||
{:httpoison, "~> 2.2"}, | ||
{:poison, "~> 5.0"} | ||
# {:dep_from_hexpm, "~> 0.3.0"}, | ||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, | ||
# {:sibling_app_in_umbrella, in_umbrella: true} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule LoLAPITest do | ||
use ExUnit.Case | ||
doctest LoLAPI | ||
|
||
test "greets the world" do | ||
assert LoLAPI.hello() == :world | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ExUnit.start() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule Scrapper.MatchClassifier do | ||
require Logger | ||
|
||
@spec classify_match(%LoLAPI.Model.MatchResponse{}) :: nil | ||
def classify_match(match = %LoLAPI.Model.MatchResponse{}) do | ||
classify_match_by_queue(match.info.queueId) | ||
end | ||
|
||
@spec classify_match_by_queue(String.t()) :: nil | ||
def classify_match_by_queue("420") do | ||
matches = Storage.MatchStorage.S3MatchStorage.list_matches() | ||
total_matches = Enum.count(matches) | ||
|
||
matches | ||
|> Enum.with_index(fn match, index -> {match, index} end) | ||
|> Scrapper.Parallel.peach(fn {match, index} -> | ||
%{key: json_file} = match | ||
[key | _] = String.split(json_file, ".") | ||
Logger.info("Match at #{index} of #{total_matches} is classified") | ||
response = HTTPoison.get!("http://localhost:9000/matches/#{key}.json", [], timeout: 5000) | ||
%{"info" => %{"gameVersion" => gameVersion}} = Poison.decode!(response.body) | ||
Storage.MatchStorage.S3MatchStorage.store_match(key, response.body, "ranked", gameVersion) | ||
match | ||
end) | ||
end | ||
|
||
# pass functions, not data | ||
|
||
def classify_match_by_queue(_) do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule Scrapper.Parallel do | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
Oops, something went wrong.