mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
show logged-in player count in landing hero
Count distinct users with a session token valid within the 14-day window and use it for the hero players-training stat. The learning strip keeps the total player count. Also load the split seed modules in seeds_test and drop an invalid 8-piece seed FEN so precommit passes.
This commit is contained in:
@@ -332,6 +332,22 @@ defmodule Chesstrainer.Accounts do
|
||||
Repo.one(query)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the number of users with at least one valid session token.
|
||||
|
||||
Session tokens stay valid for `UserToken.session_validity_in_days/0` days, so
|
||||
this counts users who logged in during that window, not necessarily users who
|
||||
are connected right now. A user with multiple sessions counts once.
|
||||
"""
|
||||
def count_logged_in_users do
|
||||
days = UserToken.session_validity_in_days()
|
||||
|
||||
UserToken
|
||||
|> where([t], t.context == "session" and t.inserted_at > ago(^days, "day"))
|
||||
|> select([t], count(t.user_id, :distinct))
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@doc ~S"""
|
||||
Delivers the update email instructions to the given user.
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ defmodule Chesstrainer.Accounts.UserToken do
|
||||
{token, %UserToken{token: token, context: "session", user_id: user.id, authenticated_at: dt}}
|
||||
end
|
||||
|
||||
@doc "How long a session token stays valid, in days."
|
||||
def session_validity_in_days, do: @session_validity_in_days
|
||||
|
||||
@doc """
|
||||
Checks if the token is valid and returns its underlying lookup query.
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
defmodule ChesstrainerWeb.PageController do
|
||||
use ChesstrainerWeb, :controller
|
||||
|
||||
alias Chesstrainer.Accounts
|
||||
alias Chesstrainer.Attempts
|
||||
alias Chesstrainer.Branding
|
||||
alias Chesstrainer.DailyPuzzles
|
||||
@@ -23,6 +24,7 @@ defmodule ChesstrainerWeb.PageController do
|
||||
active_endgame: DailyPuzzles.today(),
|
||||
puzzle_count: Endgames.count_endgames(),
|
||||
user_count: Attempts.count_users_with_attempts(),
|
||||
logged_in_count: Accounts.count_logged_in_users(),
|
||||
today: Date.utc_today()
|
||||
)
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<i>♜</i>
|
||||
</span>
|
||||
<span>
|
||||
<strong>{count_label(@user_count)}</strong> players training
|
||||
<strong>{count_label(@logged_in_count)}</strong> players training
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -58,7 +58,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|
||||
awaiting_best_line={@awaiting_best_line}
|
||||
/>
|
||||
|
||||
<div :if={@user_rating} class="mb-4">
|
||||
<div :if={@user_rating} class="mb-4">
|
||||
<.rating_guide rating={@user_rating} deviation={@user_deviation} />
|
||||
</div>
|
||||
</Layouts.app>
|
||||
|
||||
Reference in New Issue
Block a user