Skip to content

Commit

Permalink
Merge branch 'main' into mixpanel_api_ex_1_2
Browse files Browse the repository at this point in the history
  • Loading branch information
axelclark authored Feb 5, 2024
2 parents 318db3c + 0f7b6be commit bed3b13
Show file tree
Hide file tree
Showing 227 changed files with 2,138 additions and 1,927 deletions.
5 changes: 3 additions & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"],
line_length: 98
]
13 changes: 5 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ name: Elixir Testing CI
# This workflow runs every push
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

# Jobs are run in parallel
jobs:

# This is our one and only job
test:
runs-on: ubuntu-latest
services:

# We need postgres for our tests
postgres:
image: postgres:14
Expand All @@ -27,7 +25,7 @@ jobs:
POSTGRES_DB: postgres

# Maps tcp port 5432 on service container to the host
ports: ['5432:5432']
ports: ["5432:5432"]

# Set health checks to wait until postgres has started
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
Expand All @@ -51,7 +49,6 @@ jobs:
# A job has any number of steps: we will define them here
# Each dash (-) represents a step. Sometimes we give them a custom name, sometimes we leave it if it's obvious.
steps:

# Our OS filesystem has nothing on it - let's checkout our codebase using a pre-made Github step
- uses: actions/checkout@v3

Expand All @@ -60,8 +57,8 @@ jobs:
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '25.3.2'
elixir-version: '1.14.4'
otp-version: "26.2.1"
elixir-version: "1.16.1"

# We might as well re-use our deps instead of downloading them over and over. So let's use a cache.
# Docs: https://github.com/actions/cache
Expand Down
72 changes: 35 additions & 37 deletions .iex.exs
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
alias Ex338.{
Accounts.User,
CalendarAssistant,
Championships,
Championships.Championship,
Championships.ChampionshipResult,
Championships.ChampWithEventsResult,
Championships.ChampionshipSlot,
DraftPicks,
DraftPicks.Admin,
DraftPicks.DraftPick,
DraftQueues,
DraftQueues.DraftQueue,
FantasyLeagues,
FantasyLeagues.FantasyLeague,
FantasyPlayers,
FantasyPlayers.FantasyPlayer,
FantasyPlayers.SportsLeague,
FantasyTeams,
FantasyTeams.FantasyTeam,
FantasyTeams.Owner,
InSeasonDraftPicks,
InjuredReserves,
Mailer,
NotificationEmail,
Repo,
RosterPositions,
RosterPositions.Admin,
RosterPositions.RosterPosition,
Trades,
Trades.Trade,
Trades.TradeLineItem,
Waivers,
Waivers.Admin,
Waivers.Waiver
}

import Ecto.Query

alias Ex338.Accounts.User
alias Ex338.CalendarAssistant
alias Ex338.Championships
alias Ex338.Championships.Championship
alias Ex338.Championships.ChampionshipResult
alias Ex338.Championships.ChampionshipSlot
alias Ex338.Championships.ChampWithEventsResult
alias Ex338.DraftPicks
alias Ex338.DraftPicks.Admin
alias Ex338.DraftPicks.DraftPick
alias Ex338.DraftQueues
alias Ex338.DraftQueues.DraftQueue
alias Ex338.FantasyLeagues
alias Ex338.FantasyLeagues.FantasyLeague
alias Ex338.FantasyPlayers
alias Ex338.FantasyPlayers.FantasyPlayer
alias Ex338.FantasyPlayers.SportsLeague
alias Ex338.FantasyTeams
alias Ex338.FantasyTeams.FantasyTeam
alias Ex338.FantasyTeams.Owner
alias Ex338.InjuredReserves
alias Ex338.InSeasonDraftPicks
alias Ex338.Mailer
alias Ex338.NotificationEmail
alias Ex338.Repo
alias Ex338.RosterPositions
alias Ex338.RosterPositions.Admin
alias Ex338.RosterPositions.RosterPosition
alias Ex338.Trades
alias Ex338.Trades.Trade
alias Ex338.Trades.TradeLineItem
alias Ex338.Waivers
alias Ex338.Waivers.Admin
alias Ex338.Waivers.Waiver
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.14.4-otp-25
erlang 25.3.2
elixir 1.16.1-otp-26
erlang 26.2.1
3 changes: 2 additions & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ config :ex338, Ex338.Repo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL"),
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
ssl: true
ssl: true,
ssl_opts: [verify: :verify_none]

config :ex338, :pow_redis, uri: System.get_env("REDIS_URL")

Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ config :ex338, Ex338Web.Endpoint,
pubsub_server: Ex338.PubSub

# Print only warnings and errors during test
config :logger, level: :warn
config :logger, level: :warning

# Configure your database
config :ex338, Ex338.Repo,
Expand Down
4 changes: 2 additions & 2 deletions elixir_buildpack.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Erlang version
erlang_version=25.3.2
erlang_version=26.2.1

# Elixir version
elixir_version=1.14.4
elixir_version=1.16.1

config_vars_to_export=(SENDGRID_API_KEY)

Expand Down
24 changes: 9 additions & 15 deletions lib/ex338/abilities.ex
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
defimpl Canada.Can, for: Ex338.Accounts.User do
alias Ex338.{
Accounts.User,
DraftPicks.DraftPick,
FantasyTeams.FantasyTeam,
Waivers.Waiver,
InSeasonDraftPicks.InSeasonDraftPick
}
alias Ex338.Accounts.User
alias Ex338.DraftPicks.DraftPick
alias Ex338.FantasyTeams.FantasyTeam
alias Ex338.InSeasonDraftPicks.InSeasonDraftPick
alias Ex338.Waivers.Waiver

def can?(%User{admin: true}, _, _), do: true

def can?(%User{id: user_id}, action, %User{id: user_id})
when action in [:edit, :update] do
def can?(%User{id: user_id}, action, %User{id: user_id}) when action in [:edit, :update] do
true
end

def can?(%User{}, action, %User{})
when action in [:edit, :update] do
def can?(%User{}, action, %User{}) when action in [:edit, :update] do
false
end

def can?(%User{}, action, nil)
when action in [:edit, :update] do
def can?(%User{}, action, nil) when action in [:edit, :update] do
false
end

def can?(%User{id: user_id}, action, model)
when action in [:edit, :update, :create, :new] do
def can?(%User{id: user_id}, action, model) when action in [:edit, :update, :create, :new] do
owner?(user_id, model)
end

Expand Down
7 changes: 5 additions & 2 deletions lib/ex338/accounts.ex
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
defmodule Ex338.Accounts do
@moduledoc false

alias Ex338.{FantasyTeams.FantasyTeam, Accounts.User, FantasyTeams, Repo}
alias Ex338.Accounts.User
alias Ex338.FantasyTeams
alias Ex338.FantasyTeams.FantasyTeam
alias Ex338.Repo

def get_admin_emails() do
def get_admin_emails do
Repo.all(User.admin_emails())
end

Expand Down
5 changes: 3 additions & 2 deletions lib/ex338/accounts/user.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule Ex338.Accounts.User do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset
import Ecto.Query, warn: false

use Pow.Ecto.Schema,
password_min_length: 6,
Expand All @@ -11,6 +9,9 @@ defmodule Ex338.Accounts.User do
use Pow.Extension.Ecto.Schema,
extensions: [PowResetPassword, PowPersistentSession, PowInvitation]

import Ecto.Changeset
import Ecto.Query, warn: false

alias Ex338.Accounts.User

schema "users" do
Expand Down
42 changes: 15 additions & 27 deletions lib/ex338/autodraft.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
defmodule Ex338.AutoDraft do
@moduledoc false

alias Ex338.{
DraftPicks,
DraftPicks.DraftPick,
DraftQueues,
FantasyTeams,
InSeasonDraftPicks,
InSeasonDraftPicks.InSeasonDraftPick
}

alias Ex338Web.{DraftEmail, InSeasonDraftEmail}
alias Ex338.DraftPicks
alias Ex338.DraftPicks.DraftPick
alias Ex338.DraftQueues
alias Ex338.FantasyTeams
alias Ex338.InSeasonDraftPicks
alias Ex338.InSeasonDraftPicks.InSeasonDraftPick
alias Ex338Web.DraftEmail
alias Ex338Web.InSeasonDraftEmail

@next_pick 1

Expand Down Expand Up @@ -91,11 +89,9 @@ defmodule Ex338.AutoDraft do

defp draft_status?(fantasy_league_id, championship) do
with true <- draft_started?(championship),
available_picks <- InSeasonDraftPicks.available_picks(fantasy_league_id, championship),
available_picks = InSeasonDraftPicks.available_picks(fantasy_league_id, championship),
true <- any_available_picks?(available_picks) do
{:in_progress, available_picks}
else
other_status -> other_status
end
end

Expand All @@ -109,9 +105,10 @@ defmodule Ex338.AutoDraft do
end

defp any_available_picks?(available_picks) do
case Enum.any?(available_picks, &(&1.available_to_pick? == true)) do
false -> :in_season_draft_picks_complete
true -> true
if Enum.any?(available_picks, &(&1.available_to_pick? == true)) do
true
else
:in_season_draft_picks_complete
end
end

Expand Down Expand Up @@ -154,11 +151,7 @@ defmodule Ex338.AutoDraft do
end
end

defp make_picks_with_skips(
fantasy_league_id,
previous_picks,
sleep_before_pick
) do
defp make_picks_with_skips(fantasy_league_id, previous_picks, sleep_before_pick) do
available_picks = DraftPicks.get_picks_available_with_skips(fantasy_league_id)

do_make_picks_with_skips(
Expand All @@ -173,12 +166,7 @@ defmodule Ex338.AutoDraft do
make_picks_from_queues(:no_pick, picks, sleep_before_pick)
end

defp do_make_picks_with_skips(
fantasy_league_id,
available_picks,
picks,
sleep_before_pick
) do
defp do_make_picks_with_skips(fantasy_league_id, available_picks, picks, sleep_before_pick) do
new_picks =
Enum.reduce(available_picks, picks, fn next_pick, picks ->
with %{fantasy_player_id: queued_player_id, fantasy_team: fantasy_team} <-
Expand Down
28 changes: 13 additions & 15 deletions lib/ex338/championships.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
defmodule Ex338.Championships do
@moduledoc false

alias Ex338.{
Championships.Championship,
Championships.CreateSlot,
FantasyTeams,
Jobs,
Repo,
InSeasonDraftPicks
}
alias Ex338.Championships.Championship
alias Ex338.Championships.CreateSlot
alias Ex338.FantasyTeams
alias Ex338.InSeasonDraftPicks
alias Ex338.Jobs
alias Ex338.Repo

def all_for_league(fantasy_league_id) do
Championship
Expand Down Expand Up @@ -45,7 +43,7 @@ defmodule Ex338.Championships do
|> Championship.preload_assocs_by_league(fantasy_league_id)
|> Repo.get!(id)
|> Championship.add_deadline_statuses()
|> update_next_in_season_pick
|> update_next_in_season_pick()
|> preload_events_by_league(fantasy_league_id)
|> get_slot_standings(fantasy_league_id)
end
Expand All @@ -70,7 +68,7 @@ defmodule Ex338.Championships do
Championship
|> Championship.sum_slot_points(championship.id, league_id)
|> Repo.all()
|> rank_slots
|> rank_slots()

Map.put(championship, :slot_standings, slots)
end
Expand Down Expand Up @@ -113,22 +111,22 @@ defmodule Ex338.Championships do
end

defp owned_after_championship?(%{active_at: active_at}, championship_at) do
DateTime.compare(active_at, championship_at) == :gt
DateTime.after?(active_at, championship_at)
end

defp released_before_championship?(%{released_at: nil}, _championship_at), do: false

defp released_before_championship?(%{released_at: released_at}, championship_at) do
DateTime.compare(championship_at, released_at) == :gt
DateTime.after?(championship_at, released_at)
end

## get_slot_standings

defp rank_slots(slots) do
slots
|> remove_nonscoring_slots
|> sort_by_points
|> add_rank_to_slots
|> remove_nonscoring_slots()
|> sort_by_points()
|> add_rank_to_slots()
end

defp remove_nonscoring_slots(slots) do
Expand Down
Loading

0 comments on commit bed3b13

Please sign in to comment.