Compare commits
4 Commits
deploy
..
520c234a94
| Author | SHA1 | Date | |
|---|---|---|---|
| 520c234a94 | |||
| dacb9ad8fc | |||
| 6053cfcdac | |||
| 5ce7ce0542 |
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
# A sample docker-setup hook
|
|
||||||
#
|
|
||||||
# Sets up a Docker network which can then be used by the application’s containers
|
|
||||||
|
|
||||||
ssh user@example.com docker network create kamal
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# A sample post-deploy hook
|
|
||||||
#
|
|
||||||
# These environment variables are available:
|
|
||||||
# KAMAL_RECORDED_AT
|
|
||||||
# KAMAL_PERFORMER
|
|
||||||
# KAMAL_VERSION
|
|
||||||
# KAMAL_HOSTS
|
|
||||||
# KAMAL_ROLE (if set)
|
|
||||||
# KAMAL_DESTINATION (if set)
|
|
||||||
# KAMAL_RUNTIME
|
|
||||||
|
|
||||||
echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds"
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
echo "Rebooted Traefik on $KAMAL_HOSTS"
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# A sample pre-build hook
|
|
||||||
#
|
|
||||||
# Checks:
|
|
||||||
# 1. We have a clean checkout
|
|
||||||
# 2. A remote is configured
|
|
||||||
# 3. The branch has been pushed to the remote
|
|
||||||
# 4. The version we are deploying matches the remote
|
|
||||||
#
|
|
||||||
# These environment variables are available:
|
|
||||||
# KAMAL_RECORDED_AT
|
|
||||||
# KAMAL_PERFORMER
|
|
||||||
# KAMAL_VERSION
|
|
||||||
# KAMAL_HOSTS
|
|
||||||
# KAMAL_ROLE (if set)
|
|
||||||
# KAMAL_DESTINATION (if set)
|
|
||||||
|
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
|
||||||
echo "Git checkout is not clean, aborting..." >&2
|
|
||||||
git status --porcelain >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
first_remote=$(git remote)
|
|
||||||
|
|
||||||
if [ -z "$first_remote" ]; then
|
|
||||||
echo "No git remote set, aborting..." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
current_branch=$(git branch --show-current)
|
|
||||||
|
|
||||||
if [ -z "$current_branch" ]; then
|
|
||||||
echo "Not on a git branch, aborting..." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1)
|
|
||||||
|
|
||||||
if [ -z "$remote_head" ]; then
|
|
||||||
echo "Branch not pushed to remote, aborting..." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$KAMAL_VERSION" != "$remote_head" ]; then
|
|
||||||
echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
# A sample pre-connect check
|
|
||||||
#
|
|
||||||
# Warms DNS before connecting to hosts in parallel
|
|
||||||
#
|
|
||||||
# These environment variables are available:
|
|
||||||
# KAMAL_RECORDED_AT
|
|
||||||
# KAMAL_PERFORMER
|
|
||||||
# KAMAL_VERSION
|
|
||||||
# KAMAL_HOSTS
|
|
||||||
# KAMAL_ROLE (if set)
|
|
||||||
# KAMAL_DESTINATION (if set)
|
|
||||||
# KAMAL_RUNTIME
|
|
||||||
|
|
||||||
hosts = ENV["KAMAL_HOSTS"].split(",")
|
|
||||||
results = nil
|
|
||||||
max = 3
|
|
||||||
|
|
||||||
elapsed = Benchmark.realtime do
|
|
||||||
results = hosts.map do |host|
|
|
||||||
Thread.new do
|
|
||||||
tries = 1
|
|
||||||
|
|
||||||
begin
|
|
||||||
Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)
|
|
||||||
rescue SocketError
|
|
||||||
if tries < max
|
|
||||||
puts "Retrying DNS warmup: #{host}"
|
|
||||||
tries += 1
|
|
||||||
sleep rand
|
|
||||||
retry
|
|
||||||
else
|
|
||||||
puts "DNS warmup failed: #{host}"
|
|
||||||
host
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
tries
|
|
||||||
end
|
|
||||||
end.map(&:value)
|
|
||||||
end
|
|
||||||
|
|
||||||
retries = results.sum - hosts.size
|
|
||||||
nopes = results.count { |r| r == max }
|
|
||||||
|
|
||||||
puts "Prewarmed %d DNS lookups in %.2f sec: %d retries, %d failures" % [ hosts.size, elapsed, retries, nopes ]
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
# A sample pre-deploy hook
|
|
||||||
#
|
|
||||||
# Checks the Github status of the build, waiting for a pending build to complete for up to 720 seconds.
|
|
||||||
#
|
|
||||||
# Fails unless the combined status is "success"
|
|
||||||
#
|
|
||||||
# These environment variables are available:
|
|
||||||
# KAMAL_RECORDED_AT
|
|
||||||
# KAMAL_PERFORMER
|
|
||||||
# KAMAL_VERSION
|
|
||||||
# KAMAL_HOSTS
|
|
||||||
# KAMAL_COMMAND
|
|
||||||
# KAMAL_SUBCOMMAND
|
|
||||||
# KAMAL_ROLE (if set)
|
|
||||||
# KAMAL_DESTINATION (if set)
|
|
||||||
|
|
||||||
# Only check the build status for production deployments
|
|
||||||
if ENV["KAMAL_COMMAND"] == "rollback" || ENV["KAMAL_DESTINATION"] != "production"
|
|
||||||
exit 0
|
|
||||||
end
|
|
||||||
|
|
||||||
require "bundler/inline"
|
|
||||||
|
|
||||||
# true = install gems so this is fast on repeat invocations
|
|
||||||
gemfile(true, quiet: true) do
|
|
||||||
source "https://rubygems.org"
|
|
||||||
|
|
||||||
gem "octokit"
|
|
||||||
gem "faraday-retry"
|
|
||||||
end
|
|
||||||
|
|
||||||
MAX_ATTEMPTS = 72
|
|
||||||
ATTEMPTS_GAP = 10
|
|
||||||
|
|
||||||
def exit_with_error(message)
|
|
||||||
$stderr.puts message
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
class GithubStatusChecks
|
|
||||||
attr_reader :remote_url, :git_sha, :github_client, :combined_status
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
@remote_url = `git config --get remote.origin.url`.strip.delete_prefix("https://github.com/")
|
|
||||||
@git_sha = `git rev-parse HEAD`.strip
|
|
||||||
@github_client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])
|
|
||||||
refresh!
|
|
||||||
end
|
|
||||||
|
|
||||||
def refresh!
|
|
||||||
@combined_status = github_client.combined_status(remote_url, git_sha)
|
|
||||||
end
|
|
||||||
|
|
||||||
def state
|
|
||||||
combined_status[:state]
|
|
||||||
end
|
|
||||||
|
|
||||||
def first_status_url
|
|
||||||
first_status = combined_status[:statuses].find { |status| status[:state] == state }
|
|
||||||
first_status && first_status[:target_url]
|
|
||||||
end
|
|
||||||
|
|
||||||
def complete_count
|
|
||||||
combined_status[:statuses].count { |status| status[:state] != "pending"}
|
|
||||||
end
|
|
||||||
|
|
||||||
def total_count
|
|
||||||
combined_status[:statuses].count
|
|
||||||
end
|
|
||||||
|
|
||||||
def current_status
|
|
||||||
if total_count > 0
|
|
||||||
"Completed #{complete_count}/#{total_count} checks, see #{first_status_url} ..."
|
|
||||||
else
|
|
||||||
"Build not started..."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
$stdout.sync = true
|
|
||||||
|
|
||||||
puts "Checking build status..."
|
|
||||||
attempts = 0
|
|
||||||
checks = GithubStatusChecks.new
|
|
||||||
|
|
||||||
begin
|
|
||||||
loop do
|
|
||||||
case checks.state
|
|
||||||
when "success"
|
|
||||||
puts "Checks passed, see #{checks.first_status_url}"
|
|
||||||
exit 0
|
|
||||||
when "failure"
|
|
||||||
exit_with_error "Checks failed, see #{checks.first_status_url}"
|
|
||||||
when "pending"
|
|
||||||
attempts += 1
|
|
||||||
end
|
|
||||||
|
|
||||||
exit_with_error "Checks are still pending, gave up after #{MAX_ATTEMPTS * ATTEMPTS_GAP} seconds" if attempts == MAX_ATTEMPTS
|
|
||||||
|
|
||||||
puts checks.current_status
|
|
||||||
sleep(ATTEMPTS_GAP)
|
|
||||||
checks.refresh!
|
|
||||||
end
|
|
||||||
rescue Octokit::NotFound
|
|
||||||
exit_with_error "Build status could not be found"
|
|
||||||
end
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
echo "Rebooting Traefik on $KAMAL_HOSTS..."
|
|
||||||
@@ -1,20 +1,26 @@
|
|||||||
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
||||||
alias Hex.HTTP
|
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
||||||
@behaviour LolAnalytics.Analyzer
|
@behaviour LolAnalytics.Analyzer
|
||||||
|
|
||||||
def analyze_all_matches do
|
def analyze_all_matches do
|
||||||
Storage.MatchStorage.S3MatchStorage.list_files("ranked")
|
Storage.MatchStorage.S3MatchStorage.stream_files("ranked")
|
||||||
|> Enum.map(& &1.key)
|
|> Enum.each(fn %{key: path} ->
|
||||||
|> Enum.each(fn path ->
|
IO.inspect(path)
|
||||||
LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/#{path}")
|
LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://192.168.1.55:9000/ranked/#{path}")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
# Storage.MatchStorage.S3MatchStorage.list_files("ranked")
|
||||||
|
# |> Enum.map(& &1.key)
|
||||||
|
# |> Enum.each(fn path ->
|
||||||
|
# LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/#{path}")
|
||||||
|
# end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/14.9.580.2108/EUW1_6923309745.json")
|
iex> LolAnalytics.Analyzer.ChampionAnalyzer.analyze(:url, "http://localhost:9000/ranked/14.9.580.2108/EUW1_6923309745.json")
|
||||||
"""
|
"""
|
||||||
|
@spec analyze(any(), any()) :: none()
|
||||||
@impl true
|
@impl true
|
||||||
@spec analyze(atom(), String.t()) :: :ok
|
|
||||||
def analyze(:url, path) do
|
def analyze(:url, path) do
|
||||||
data = HTTPoison.get!(path)
|
data = HTTPoison.get!(path)
|
||||||
analyze(:data, data.body)
|
analyze(:data, data.body)
|
||||||
@@ -22,7 +28,6 @@ defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec analyze(atom(), any()) :: list(LoLAPI.Model.Participant.t())
|
|
||||||
def analyze(:data, data) do
|
def analyze(:data, data) do
|
||||||
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
|
decoded_match = Poison.decode!(data, as: %LoLAPI.Model.MatchResponse{})
|
||||||
participants = decoded_match.info.participants
|
participants = decoded_match.info.participants
|
||||||
@@ -31,12 +36,16 @@ defmodule LolAnalytics.Analyzer.ChampionAnalyzer do
|
|||||||
participants
|
participants
|
||||||
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
|> Enum.each(fn participant = %LoLAPI.Model.Participant{} ->
|
||||||
if participant.teamPosition != "" do
|
if participant.teamPosition != "" do
|
||||||
LolAnalytics.ChampionWinRate.ChampionWinRateRepo.add_champion_win_rate(
|
attrs = %{
|
||||||
participant.championId,
|
champion_id: participant.championId,
|
||||||
version,
|
match_id: decoded_match.metadata.matchId,
|
||||||
participant.teamPosition,
|
is_win: participant.win,
|
||||||
participant.win
|
game_length_seconds: decoded_match.info.gameDuration,
|
||||||
)
|
queue_id: decoded_match.info.queueId,
|
||||||
|
puuid: participant.puuid,
|
||||||
|
team_position: participant.teamPosition
|
||||||
|
}
|
||||||
|
LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.insert(attrs)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Champion.ChampionRepo do
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
alias LolAnalytics.Dimensions.Champion.ChampionSchema
|
||||||
|
|
||||||
|
@spec get_or_create(String.t()) :: struct()
|
||||||
|
def get_or_create(champion_id) do
|
||||||
|
champion = Repo.get_by(ChampionSchema, champion_id: champion_id)
|
||||||
|
|
||||||
|
case champion do
|
||||||
|
nil ->
|
||||||
|
changeset = ChampionSchema.changeset(%ChampionSchema{}, %{champion_id: champion_id})
|
||||||
|
Repo.insert(changeset)
|
||||||
|
|
||||||
|
champion ->
|
||||||
|
champion
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_champions() do
|
||||||
|
Repo.all(ChampionSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Champion.ChampionSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "dim_champion" do
|
||||||
|
field :champion_id, :integer
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(champion = %__MODULE__{}, attrs \\ %{}) do
|
||||||
|
champion
|
||||||
|
|> cast(attrs, [:champion_id])
|
||||||
|
|> validate_required([:champion_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Item.ItemRepo do
|
||||||
|
alias LolAnalytics.Dimensions.Item.ItemSchema
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
|
def get_or_create(item_id) do
|
||||||
|
item = Repo.get(ItemSchema, item_id: item_id)
|
||||||
|
|
||||||
|
case item do
|
||||||
|
nil ->
|
||||||
|
item_changeset = ItemSchema.changeset(%ItemSchema{}, %{item_id: item_id})
|
||||||
|
Repo.insert(item_changeset)
|
||||||
|
|
||||||
|
item ->
|
||||||
|
item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_items() do
|
||||||
|
Repo.all(ItemSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Item.ItemSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "dim_item" do
|
||||||
|
field :item_id, :integer
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(item = %__MODULE__{}, attrs \\ %{}) do
|
||||||
|
item
|
||||||
|
|> cast(attrs, [:item_id])
|
||||||
|
|> validate_required([:item_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Match.MatchRepo do
|
||||||
|
alias LolAnalytics.Dimensions.Match.MatchSchema
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
@spec get_or_create(String.t()) :: %MatchSchema{}
|
||||||
|
def get_or_create(match_id) do
|
||||||
|
query = from m in MatchSchema, where: m.match_id == ^match_id
|
||||||
|
match = Repo.one(query)
|
||||||
|
|
||||||
|
case match do
|
||||||
|
nil ->
|
||||||
|
match_changeset =
|
||||||
|
MatchSchema.changeset(
|
||||||
|
%MatchSchema{},
|
||||||
|
%{match_id: match_id}
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.insert(match_changeset)
|
||||||
|
|
||||||
|
match ->
|
||||||
|
match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_matches() do
|
||||||
|
Repo.all(MatchSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Match.MatchSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "dim_match" do
|
||||||
|
field :match_id, :string
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(match = %__MODULE__{}, attrs \\ %{}) do
|
||||||
|
match
|
||||||
|
|> cast(attrs, [:match_id])
|
||||||
|
|> validate_required([:match_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Patch.PatchRepo do
|
||||||
|
alias LolAnalytics.Dimensions.Patch.PatchSchema
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
|
def get_or_create(patch_number) do
|
||||||
|
patch = Repo.get(PatchSchema, patch_number: patch_number)
|
||||||
|
|
||||||
|
case patch do
|
||||||
|
nil ->
|
||||||
|
patch_changeset =
|
||||||
|
PatchSchema.changeset(
|
||||||
|
%PatchSchema{},
|
||||||
|
%{patch_number: patch_number}
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.insert(patch_changeset)
|
||||||
|
|
||||||
|
patch ->
|
||||||
|
patch
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_patches() do
|
||||||
|
Repo.all(PatchSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Patch.PatchSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "dim_patch" do
|
||||||
|
field :patch_number, :string
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(patch = %__MODULE__{}, attrs \\ %{}) do
|
||||||
|
patch
|
||||||
|
|> cast(attrs, [:patch_number])
|
||||||
|
|> validate_required([:patch_number])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Player.PlayerRepo do
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias LolAnalytics.Dimensions.Player.PlayerSchema
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
|
def get_or_create(puuid) do
|
||||||
|
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
||||||
|
player = Repo.one(query)
|
||||||
|
|
||||||
|
case player do
|
||||||
|
nil ->
|
||||||
|
player_changeset =
|
||||||
|
PlayerSchema.changeset(
|
||||||
|
%PlayerSchema{},
|
||||||
|
%{puuid: puuid}
|
||||||
|
)
|
||||||
|
Repo.insert(player_changeset)
|
||||||
|
|
||||||
|
player ->
|
||||||
|
player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_players() do
|
||||||
|
Repo.all(PlayerSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.Player.PlayerSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "dim_player" do
|
||||||
|
field :puuid, :string
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(player = %__MODULE__{}, attrs \\ %{}) do
|
||||||
|
player
|
||||||
|
|> cast(attrs, [:puuid])
|
||||||
|
|> validate_required([:puuid])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellRepo do
|
||||||
|
alias LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
|
def get_or_create(spell_id) do
|
||||||
|
spell = Repo.get(SummonerSpellSchema, spell_id: spell_id)
|
||||||
|
|
||||||
|
case spell do
|
||||||
|
nil ->
|
||||||
|
spell_changeset =
|
||||||
|
SummonerSpellSchema.changeset(
|
||||||
|
%SummonerSpellSchema{},
|
||||||
|
%{spell_id: spell_id}
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.insert(spell_changeset)
|
||||||
|
|
||||||
|
spell ->
|
||||||
|
spell
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_spells() do
|
||||||
|
Repo.all(SummonerSpellSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
defmodule LolAnalytics.Dimensions.SummonerSpell.SummonerSpellSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "dim_summoner_spell" do
|
||||||
|
field :spell_id, :integer
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(summoner_spell = %__MODULE__{}, attrs) do
|
||||||
|
summoner_spell
|
||||||
|
|> cast(attrs, [:spell_id])
|
||||||
|
|> validate_required([:spell_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo do
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
alias LolAnalytics.Dimensions.Player.PlayerRepo
|
||||||
|
alias LolAnalytics.Dimensions.Champion.ChampionRepo
|
||||||
|
alias LolAnalytics.Dimensions.Match.MatchRepo
|
||||||
|
alias LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema
|
||||||
|
alias LolAnalytics.Facts.ChampionPlayedGame
|
||||||
|
alias LoLAnalytics.Repo
|
||||||
|
|
||||||
|
def insert(attrs) do
|
||||||
|
match = MatchRepo.get_or_create(attrs.match_id)
|
||||||
|
champion = ChampionRepo.get_or_create(attrs.champion_id)
|
||||||
|
player = PlayerRepo.get_or_create(attrs.puuid)
|
||||||
|
IO.puts(">>>>")
|
||||||
|
IO.inspect(attrs)
|
||||||
|
changeset = ChampionPlayedGameSchema.changeset(%ChampionPlayedGameSchema{}, attrs)
|
||||||
|
|
||||||
|
IO.inspect(changeset)
|
||||||
|
Repo.insert(changeset)
|
||||||
|
# Repo.insert(match)
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_played_matches() do
|
||||||
|
Repo.all(ChampionPlayedGameSchema)
|
||||||
|
end
|
||||||
|
end
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
defmodule LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameSchema do
|
||||||
|
use Ecto.Schema
|
||||||
|
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@casting_attrs [
|
||||||
|
:champion_id,
|
||||||
|
:match_id,
|
||||||
|
:is_win,
|
||||||
|
:game_length_seconds,
|
||||||
|
:team_position,
|
||||||
|
:puuid,
|
||||||
|
:queue_id
|
||||||
|
]
|
||||||
|
|
||||||
|
schema "fact_champion_played_game" do
|
||||||
|
field :champion_id, :integer
|
||||||
|
field :match_id, :string
|
||||||
|
field :is_win, :boolean
|
||||||
|
field :game_length_seconds, :integer
|
||||||
|
field :team_position, :string
|
||||||
|
field :puuid, :string
|
||||||
|
field :queue_id, :integer
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
def changeset(fact = %__MODULE__{}, attrs \\ %{}) do
|
||||||
|
fact
|
||||||
|
|> cast(attrs, @casting_attrs)
|
||||||
|
|> validate_required(@casting_attrs)
|
||||||
|
|> unique_constraint([:id, :champion_id, :queue_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -42,6 +42,7 @@ defmodule LoLAnalytics.MixProject do
|
|||||||
{:postgrex, ">= 0.0.0"},
|
{:postgrex, ">= 0.0.0"},
|
||||||
{:jason, "~> 1.2"},
|
{:jason, "~> 1.2"},
|
||||||
{:lol_api, in_umbrella: true},
|
{:lol_api, in_umbrella: true},
|
||||||
|
{:storage, in_umbrella: true},
|
||||||
{:httpoison, "~> 2.2"},
|
{:httpoison, "~> 2.2"},
|
||||||
{:poison, "~> 5.0"}
|
{:poison, "~> 5.0"}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
defmodule LoLAnalytics.Repo.Migrations.AnalyticsTables do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table("dim_champion") do
|
||||||
|
add :champion_id, :integer, primary_key: true, null: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("dim_champion", [:champion_id], unique: true)
|
||||||
|
|
||||||
|
create table("dim_item") do
|
||||||
|
add :item_id, :integer, primary_key: true, null: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("dim_item", [:item_id], unique: true)
|
||||||
|
|
||||||
|
create table("dim_match") do
|
||||||
|
add :match_id, :string, primary_key: true, null: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("dim_match", [:match_id], unique: true)
|
||||||
|
|
||||||
|
create table("dim_patch") do
|
||||||
|
add :patch_number, :string, primary_key: true, null: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("dim_patch", [:patch_number], unique: true)
|
||||||
|
|
||||||
|
create table("dim_player") do
|
||||||
|
add :puuid, :string, primary_key: true, null: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("dim_player", [:puuid], unique: true)
|
||||||
|
|
||||||
|
create table("dim_summoner_spell") do
|
||||||
|
add :spell_id, :integer, primary_key: true, null: false
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("dim_summoner_spell", [:spell_id], unique: true)
|
||||||
|
|
||||||
|
create table("fact_champion_played_game") do
|
||||||
|
add :champion_id, references("dim_champion", column: :champion_id, type: :integer)
|
||||||
|
add :match_id, references("dim_match", column: :match_id, type: :string)
|
||||||
|
add :is_win, :boolean
|
||||||
|
add :game_length_seconds, :integer
|
||||||
|
add :queue_id, :integer
|
||||||
|
add :patch_number, references("dim_patch", column: :patch_number, type: :string)
|
||||||
|
add :team_position, :string
|
||||||
|
add :puuid, references("dim_player", column: :puuid, type: :string)
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
create index("fact_champion_played_game", [:id, :champion_id, :queue_id])
|
||||||
|
create index("fact_champion_played_game", [:puuid, :match_id], unique: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,6 +6,29 @@ defmodule Scrapper.MatchClassifier do
|
|||||||
classify_match_by_queue(match.info.queueId)
|
classify_match_by_queue(match.info.queueId)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stream_classify_matches_by_queue(queue \\ 420, bucket \\ "ranked") do
|
||||||
|
Storage.MatchStorage.S3MatchStorage.stream_files("matches")
|
||||||
|
|> Stream.each(fn match ->
|
||||||
|
%{key: json_file} = match
|
||||||
|
[key | _] = String.split(json_file, ".")
|
||||||
|
|
||||||
|
response =
|
||||||
|
HTTPoison.get!("http://#{System.get_env("EX_AWS_ENDPOINT")}:9000/matches/#{key}.json", [],
|
||||||
|
timeout: 5000
|
||||||
|
)
|
||||||
|
|
||||||
|
%{"info" => %{"gameVersion" => gameVersion, "queueId" => queueId}} =
|
||||||
|
Poison.decode!(response.body)
|
||||||
|
|
||||||
|
if queueId == queue do
|
||||||
|
Storage.MatchStorage.S3MatchStorage.store_match(key, response.body, bucket, gameVersion)
|
||||||
|
Logger.info("Match #{key} processed")
|
||||||
|
end
|
||||||
|
|
||||||
|
match
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
@spec classify_match_by_queue(String.t()) :: nil
|
@spec classify_match_by_queue(String.t()) :: nil
|
||||||
def classify_match_by_queue("420") do
|
def classify_match_by_queue("420") do
|
||||||
matches = Storage.MatchStorage.S3MatchStorage.list_files("matches")
|
matches = Storage.MatchStorage.S3MatchStorage.list_files("matches")
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ defmodule Storage.MatchStorage.S3MatchStorage do
|
|||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stream_files(path) do
|
||||||
|
ExAws.S3.list_objects_v2(path)
|
||||||
|
|> ExAws.stream!()
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Lists all files at the given path.
|
Lists all files at the given path.
|
||||||
|
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
# Name of your application. Used to uniquely configure containers.
|
|
||||||
service: my-app
|
|
||||||
|
|
||||||
# Name of the container image.
|
|
||||||
image: user/my-app
|
|
||||||
|
|
||||||
# Deploy to these servers.
|
|
||||||
servers:
|
|
||||||
- 192.168.0.1
|
|
||||||
|
|
||||||
# Credentials for your image host.
|
|
||||||
registry:
|
|
||||||
# Specify the registry server, if you're not using Docker Hub
|
|
||||||
# server: registry.digitalocean.com / ghcr.io / ...
|
|
||||||
username: my-user
|
|
||||||
|
|
||||||
# Always use an access token rather than real password when possible.
|
|
||||||
password:
|
|
||||||
- KAMAL_REGISTRY_PASSWORD
|
|
||||||
|
|
||||||
# Inject ENV variables into containers (secrets come from .env).
|
|
||||||
# Remember to run `kamal env push` after making changes!
|
|
||||||
# env:
|
|
||||||
# clear:
|
|
||||||
# DB_HOST: 192.168.0.2
|
|
||||||
# secret:
|
|
||||||
# - RAILS_MASTER_KEY
|
|
||||||
|
|
||||||
# Use a different ssh user than root
|
|
||||||
# ssh:
|
|
||||||
# user: app
|
|
||||||
|
|
||||||
# Configure builder setup.
|
|
||||||
# builder:
|
|
||||||
# args:
|
|
||||||
# RUBY_VERSION: 3.2.0
|
|
||||||
# secrets:
|
|
||||||
# - GITHUB_TOKEN
|
|
||||||
# remote:
|
|
||||||
# arch: amd64
|
|
||||||
# host: ssh://app@192.168.0.1
|
|
||||||
|
|
||||||
# Use accessory services (secrets come from .env).
|
|
||||||
# accessories:
|
|
||||||
# db:
|
|
||||||
# image: mysql:8.0
|
|
||||||
# host: 192.168.0.2
|
|
||||||
# port: 3306
|
|
||||||
# env:
|
|
||||||
# clear:
|
|
||||||
# MYSQL_ROOT_HOST: '%'
|
|
||||||
# secret:
|
|
||||||
# - MYSQL_ROOT_PASSWORD
|
|
||||||
# files:
|
|
||||||
# - config/mysql/production.cnf:/etc/mysql/my.cnf
|
|
||||||
# - db/production.sql:/docker-entrypoint-initdb.d/setup.sql
|
|
||||||
# directories:
|
|
||||||
# - data:/var/lib/mysql
|
|
||||||
# redis:
|
|
||||||
# image: redis:7.0
|
|
||||||
# host: 192.168.0.2
|
|
||||||
# port: 6379
|
|
||||||
# directories:
|
|
||||||
# - data:/data
|
|
||||||
|
|
||||||
# Configure custom arguments for Traefik. Be sure to reboot traefik when you modify it.
|
|
||||||
# traefik:
|
|
||||||
# args:
|
|
||||||
# accesslog: true
|
|
||||||
# accesslog.format: json
|
|
||||||
|
|
||||||
# Configure a custom healthcheck (default is /up on port 3000)
|
|
||||||
# healthcheck:
|
|
||||||
# path: /healthz
|
|
||||||
# port: 4000
|
|
||||||
|
|
||||||
# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
|
|
||||||
# hitting 404 on in-flight requests. Combines all files from new and old
|
|
||||||
# version inside the asset_path.
|
|
||||||
#
|
|
||||||
# If your app is using the Sprockets gem, ensure it sets `config.assets.manifest`.
|
|
||||||
# See https://github.com/basecamp/kamal/issues/626 for details
|
|
||||||
#
|
|
||||||
# asset_path: /rails/public/assets
|
|
||||||
|
|
||||||
# Configure rolling deploys by setting a wait time between batches of restarts.
|
|
||||||
# boot:
|
|
||||||
# limit: 10 # Can also specify as a percentage of total hosts, such as "25%"
|
|
||||||
# wait: 2
|
|
||||||
|
|
||||||
# Configure the role used to determine the primary_host. This host takes
|
|
||||||
# deploy locks, runs health checks during the deploy, and follow logs, etc.
|
|
||||||
#
|
|
||||||
# Caution: there's no support for role renaming yet, so be careful to cleanup
|
|
||||||
# the previous role on the deployed hosts.
|
|
||||||
# primary_role: web
|
|
||||||
|
|
||||||
# Controls if we abort when see a role with no hosts. Disabling this may be
|
|
||||||
# useful for more complex deploy configurations.
|
|
||||||
#
|
|
||||||
# allow_empty_roles: false
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:latest
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
POSTGRES_USER: postgres
|
||||||
|
POSTGRES_DB: postgres
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
rabbitmq:
|
||||||
|
image: rabbitmq:3-management-alpine
|
||||||
|
container_name: 'rabbitmq'
|
||||||
|
ports:
|
||||||
|
- "15671:15671"
|
||||||
|
- "15672:15672"
|
||||||
|
- "15691:15691"
|
||||||
|
- "15692:15692"
|
||||||
|
- "25672:25672"
|
||||||
|
- "4639:4639"
|
||||||
|
- "5671:5671"
|
||||||
|
- "5672:5672"
|
||||||
|
volumes:
|
||||||
|
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
|
||||||
|
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
|
||||||
|
networks:
|
||||||
|
- rabbitmq_go_net
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
|
||||||
|
|
||||||
|
networks:
|
||||||
|
rabbitmq_go_net:
|
||||||
|
driver: bridge
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
```
|
||||||
|
SELECT
|
||||||
|
(cast(count(CASE WHEN is_win THEN 1 END) as float) / cast(count(*) as float)) * 100.0 as win_rate,
|
||||||
|
count(CASE WHEN is_win THEN 1 END) as games_won,
|
||||||
|
count(*) as total_games,
|
||||||
|
champion_id
|
||||||
|
FROM fact_champion_played_game
|
||||||
|
GROUP BY champion_id
|
||||||
|
ORDER BY win_rate desc;
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user