Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team split fixes and cleanup #352

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/teiserver/account/exports/player_count_export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Teiserver.Account.PlayerCountExport do
Teiserver.Game.MatchRatingsExport.show_form(nil, %{
"date_preset" => "All time",
"end_date" => "",
"rating_type" => "Team",
"rating_type" => "Large Team",
"start_date" => ""
})
"""
Expand Down
8 changes: 8 additions & 0 deletions lib/teiserver/account/reports/growth_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ defmodule Teiserver.Account.GrowthReport do
name: "Team games",
paths: [~w"matches counts team"]
},
%{
name: "Small Team games",
paths: [~w"matches counts small_team"]
},
%{
name: "Large Team games",
paths: [~w"matches counts large_team"]
},
%{
name: "FFA games",
paths: [~w"matches counts ffa"]
Expand Down
18 changes: 9 additions & 9 deletions lib/teiserver/account/reports/week_on_week_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defmodule Teiserver.Account.WeekOnWeekReport do
previous_key = {week - 1, weekday}
previous_value = data_map[previous_key]

if previous_value do
if previous_value not in [nil, 0] do
delta = NumberHelper.percent(this_value / previous_value) - 100

{key, delta}
Expand Down Expand Up @@ -80,7 +80,7 @@ defmodule Teiserver.Account.WeekOnWeekReport do
previous_key = key - 1
previous_value = week_data[previous_key]

if previous_value do
if previous_value not in [nil, 0] do
delta = NumberHelper.percent(this_value / previous_value) - 100

{key, delta}
Expand Down Expand Up @@ -118,16 +118,16 @@ defmodule Teiserver.Account.WeekOnWeekReport do
})
end

defp get_metric(data, "Unique users"), do: data["aggregates"]["stats"]["unique_users"]
defp get_metric(data, "Unique players"), do: data["aggregates"]["stats"]["unique_players"]
defp get_metric(data, "Unique users"), do: data["aggregates"]["stats"]["unique_users"] || 0
defp get_metric(data, "Unique players"), do: data["aggregates"]["stats"]["unique_players"] || 0

defp get_metric(data, "Peak users"),
do: data["aggregates"]["stats"]["peak_user_counts"]["total"]
do: data["aggregates"]["stats"]["peak_user_counts"]["total"] || 0

defp get_metric(data, "Peak players"),
do: data["aggregates"]["stats"]["peak_user_counts"]["player"]
do: data["aggregates"]["stats"]["peak_user_counts"]["player"] || 0

defp get_metric(data, "Total time"), do: data["aggregates"]["minutes"]["total"]
defp get_metric(data, "Play time"), do: data["aggregates"]["minutes"]["player"]
defp get_metric(data, "Registrations"), do: data["aggregates"]["stats"]["accounts_created"]
defp get_metric(data, "Total time"), do: data["aggregates"]["minutes"]["total"] || 0
defp get_metric(data, "Play time"), do: data["aggregates"]["minutes"]["player"] || 0
defp get_metric(data, "Registrations"), do: data["aggregates"]["stats"]["accounts_created"] || 0
end
49 changes: 29 additions & 20 deletions lib/teiserver/account/tasks/recalculate_user_cache_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,37 @@ defmodule Teiserver.Account.RecacheUserStatsTask do
{k, Enum.count(v)}
end)

team_type =
team_subtype
|> String.downcase()
|> String.replace(" ", "_")

total = Enum.count(logs)

if total > 0 do
winrate = win_count / total

Account.update_user_stat(userid, %{
"exit_status.team.count" => total,
"exit_status.team.stayed" => ((statuses[:stayed] || 0) / total) |> percent(1),
"exit_status.team.early" => ((statuses[:early] || 0) / total) |> percent(1),
"exit_status.team.abandoned" => ((statuses[:abandoned] || 0) / total) |> percent(1),
"exit_status.team.noshow" => ((statuses[:noshow] || 0) / total) |> percent(1),
"recent_count.team" => total,
"win_count.team" => win_count,
"loss_count.team" => loss_count,
"win_rate.team" => winrate |> percent(1)
"exit_status.#{team_type}.count" => total,
"exit_status.#{team_type}.stayed" => ((statuses[:stayed] || 0) / total) |> percent(1),
"exit_status.#{team_type}.early" => ((statuses[:early] || 0) / total) |> percent(1),
"exit_status.#{team_type}.abandoned" =>
((statuses[:abandoned] || 0) / total) |> percent(1),
"exit_status.#{team_type}.noshow" => ((statuses[:noshow] || 0) / total) |> percent(1),
"recent_count.#{team_type}" => total,
"win_count.#{team_type}" => win_count,
"loss_count.#{team_type}" => loss_count,
"win_rate.#{team_type}" => winrate |> percent(1)
})
end

# For team we also look at their really recent games as that's where we'd expect
# smurfs to be most active right now
do_match_processed_team_recent(userid, logs)
do_match_processed_team_recent(userid, logs, team_type)
:ok
end

def do_match_processed_team_recent(userid, logs) do
def do_match_processed_team_recent(userid, logs, team_type) do
# Filter down to just the recent ones rather than re-running the query
timestamp_after = Timex.now() |> Timex.shift(days: -@match_cache_recent_days)

Expand Down Expand Up @@ -214,16 +220,19 @@ defmodule Teiserver.Account.RecacheUserStatsTask do
winrate = win_count / total

Account.update_user_stat(userid, %{
"exit_status.team_recent.count" => total,
"exit_status.team_recent.stayed" => ((statuses[:stayed] || 0) / total) |> percent(1),
"exit_status.team_recent.early" => ((statuses[:early] || 0) / total) |> percent(1),
"exit_status.team_recent.abandoned" =>
"exit_status.#{team_type}_recent.count" => total,
"exit_status.#{team_type}_recent.stayed" =>
((statuses[:stayed] || 0) / total) |> percent(1),
"exit_status.#{team_type}_recent.early" =>
((statuses[:early] || 0) / total) |> percent(1),
"exit_status.#{team_type}_recent.abandoned" =>
((statuses[:abandoned] || 0) / total) |> percent(1),
"exit_status.team_recent.noshow" => ((statuses[:noshow] || 0) / total) |> percent(1),
"recent_count.team_recent" => total,
"win_count.team_recent" => win_count,
"loss_count.team_recent" => loss_count,
"win_rate.team_recent" => winrate |> percent(1)
"exit_status.#{team_type}_recent.noshow" =>
((statuses[:noshow] || 0) / total) |> percent(1),
"recent_count.#{team_type}_recent" => total,
"win_count.#{team_type}_recent" => win_count,
"loss_count.#{team_type}_recent" => loss_count,
"win_rate.#{team_type}_recent" => winrate |> percent(1)
})
end

Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/battle/tasks/battle_daily_cleanup_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule Teiserver.Battle.Tasks.CleanupTask do
# Battle.list_matches(
# search: [
# inserted_before: Timex.shift(Timex.now(), days: -battle_match_rated_days),
# game_type_in: ["Team", "Duel", "FFA", "Team FFA"]
# game_type_in: ["Small Team", "Large Team", "Duel", "FFA", "Team FFA"]
# ],
# search: [:id],
# limit: :infinity
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/coordinator/consul_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ defmodule Teiserver.Coordinator.ConsulServer do
if Enum.count(player_numbers) != Enum.count(players) do
players
|> Enum.map(fn c ->
{-c.team_number, BalanceLib.get_user_rating_value(c.userid, "Team"), c}
{-c.team_number, BalanceLib.get_user_rating_value(c.userid, "Large Team"), c}
end)
|> Enum.sort()
|> Enum.reverse()
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/data/matchmaking.ex
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ defmodule Teiserver.Data.Matchmaking do
cond do
queue.settings["rating_type"] != nil -> queue.settings["rating_type"]
queue.team_size == 1 -> "Duel"
true -> "Team"
true -> "Large Team"
end

BalanceLib.get_user_rating_value(userid, rating_type)
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/game/exports/match_datatable_export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Teiserver.Game.MatchDataTableExport do
Teiserver.Game.MatchDataTableExport.show_form(nil, %{
"date_preset" => "All time",
"end_date" => "",
"rating_type" => "Team",
"rating_type" => "Large Team",
"start_date" => ""
})

Expand Down
4 changes: 2 additions & 2 deletions lib/teiserver/game/exports/match_ratings_export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ defmodule Teiserver.Game.MatchRatingsExport do
Teiserver.Game.MatchRatingsExport.show_form(nil, %{
"date_preset" => "All time",
"end_date" => "",
"rating_type" => "Team",
"rating_type" => "Large Team",
"start_date" => ""
})

Teiserver.Game.MatchRatingsExport.show_form(nil, %{
"date_preset" => "All time",
"end_date" => "",
"rating_type" => "Team",
"rating_type" => "Large Team",
"start_date" => "2023-06-02"
})
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/game/exports/player_ratings_export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Teiserver.Game.PlayerRatingsExport do
Teiserver.Game.PlayerRatingsExport.show_form(nil, %{
"date_preset" => "All time",
"end_date" => "",
"rating_type" => "Team",
"rating_type" => "Large Team",
"start_date" => ""
})

Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/game/exports/rating_logs_export.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Teiserver.Game.RatingLogsExport do
Teiserver.Game.RatingLogsExport.show_form(nil, %{
"date_preset" => "All time",
"end_date" => "",
"rating_type" => "Team",
"rating_type" => "Large Team",
"start_date" => ""
})

Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/lobby/libs/lobby_restrictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ defmodule Teiserver.Lobby.LobbyRestrictions do
Determining the rating type is slightly different for lobby restrictions compared to rating a match.
When rating a match we want to use the number of players and team count in the match.
But with the lobby, we want to use the target team size/count defined by the dropdowns in the lobby.
So if there are two players in the lobby, but the team size dropdown is 8, we want to use the "Team" rating.
So if there are two players in the lobby, but the team size dropdown is 8, we want to use the "Large Team" rating.
"""
@spec check_rating_to_play(any(), any()) :: :ok | {:error, iodata()}
def check_rating_to_play(user_id, consul_state) do
Expand Down
10 changes: 5 additions & 5 deletions lib/teiserver/logging/lib/server_day_log_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ defmodule Teiserver.Logging.ServerDayLogLib do
end

# Given an existing segment and a batch of logs, calculate the segment and add them together
defp extend_segment(existing, {%{data: data} = _server_log, %{data: activity} = _activity_log}) do
defp extend_segment(existing, %{data: data} = _server_log) do
%{
# Used to make calculating the end of day stats easier, this will not appear in the final result
tmp_reduction: %{
battles: existing.tmp_reduction.battles + get_in(data, ~w(aggregates stats battles)),
unique_users:
existing.tmp_reduction.unique_users ++
Map.keys(activity["total"]),
existing.tmp_reduction.unique_users ||
0 + get_in(data, ~w(aggregates stats unique_users)),
unique_players:
existing.tmp_reduction.unique_players ++
Map.keys(activity["player"]),
existing.tmp_reduction.unique_players ||
0 + get_in(data, ~w(aggregates stats unique_players)),
accounts_created:
existing.tmp_reduction.accounts_created +
get_in(data, ~w(aggregates stats accounts_created)),
Expand Down
5 changes: 3 additions & 2 deletions lib/teiserver/logging/tasks/match_graph_logs_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ defmodule Teiserver.Logging.MatchGraphLogsTask do
def perform(logs, "split", key) do
[
{"Duel", "duel.aggregate.#{key}"},
{"Small Team", "team.aggregate.#{key}"},
{"Large Team", "team.aggregate.#{key}"},
{"Small Team", "small_team.aggregate.#{key}"},
{"Large Team", "large_team.aggregate.#{key}"},
{"FFA", "ffa.aggregate.#{key}"},
{"Team FFA", "team_ffa.aggregate.#{key}"},
{"Bot", "bots.aggregate.#{key}"},
Expand Down Expand Up @@ -87,6 +87,7 @@ defmodule Teiserver.Logging.MatchGraphLogsTask do
Map.get(l.data["duel"]["aggregate"], key, 0) +
Map.get(l.data["ffa"]["aggregate"], key, 0) +
Map.get(l.data["large_team"]["aggregate"], key, 0) +
Map.get(l.data["small_team"]["aggregate"], key, 0) +
Map.get(l.data["team_ffa"]["aggregate"], key, 0)

coop =
Expand Down
15 changes: 8 additions & 7 deletions lib/teiserver/logging/tasks/persist_match_month_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Teiserver.Logging.Tasks.PersistMatchMonthTask do
alias Teiserver.Logging
import Ecto.Query, warn: false

@sections ~w(bots duel ffa raptors scavengers team totals)
@sections ~w(bots duel ffa raptors scavengers team small_team large_team totals)

# [] List means 1 day segments
# %{} Dict means total for the month of that key
Expand Down Expand Up @@ -148,16 +148,17 @@ defmodule Teiserver.Logging.Tasks.PersistMatchMonthTask do
defp extend_sub_section(existing, data) do
%{
aggregate: %{
total_count: existing.aggregate.total_count + data["aggregate"]["total_count"],
total_count: existing.aggregate.total_count + (data["aggregate"]["total_count"] || 0),
total_duration_seconds:
existing.aggregate.total_duration_seconds + data["aggregate"]["total_duration_seconds"],
existing.aggregate.total_duration_seconds +
(data["aggregate"]["total_duration_seconds"] || 0),
weighted_count:
existing.aggregate.weighted_count + (data["aggregate"]["weighted_count"] || 0)
},
duration: sum_maps(existing.duration, data["duration"]),
maps: sum_maps(existing.maps, data["maps"]),
matches_per_hour: sum_maps(existing.matches_per_hour, data["matches_per_hour"]),
team_sizes: sum_maps(existing.team_sizes, data["team_sizes"])
duration: sum_maps(existing.duration, data["duration"] || 0),
maps: sum_maps(existing.maps, data["maps"] || 0),
matches_per_hour: sum_maps(existing.matches_per_hour, data["matches_per_hour"] || 0),
team_sizes: sum_maps(existing.team_sizes, data["team_sizes"] || 0)
}
end

Expand Down
3 changes: 3 additions & 0 deletions lib/teiserver/logging/tasks/persist_server_day_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ defmodule Teiserver.Logging.Tasks.PersistServerDayTask do
bots: 0,
duel: 0,
team: 0,
small_team: 0,
large_team: 0,
ffa: 0,
team_ffa: 0,
passworded: 0
Expand Down Expand Up @@ -562,6 +564,7 @@ defmodule Teiserver.Logging.Tasks.PersistServerDayTask do
"Raptors" -> :raptors
"Bots" -> :bots
"Duel" -> :duel
"Team" -> :team
"Small Team" -> :small_team
"Large Team" -> :large_team
"FFA" -> :ffa
Expand Down
4 changes: 2 additions & 2 deletions lib/teiserver_web/controllers/battle/match_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ defmodule TeiserverWeb.Battle.MatchController do
def ratings(conn, params) do
user = conn.assigns.current_user

filter = params["filter"] || "Team"
filter = params["filter"] || "Large Team"
filter_type_id = MatchRatingLib.rating_type_name_lookup()[filter] || 1

ratings =
Expand Down Expand Up @@ -144,7 +144,7 @@ defmodule TeiserverWeb.Battle.MatchController do
def ratings_graph(conn, params) do
user = conn.assigns.current_user

filter = params["filter"] || "Team"
filter = params["filter"] || "Large Team"
filter_type_id = MatchRatingLib.rating_type_name_lookup()[filter] || 1

ratings =
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/battles/lobbies/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ defmodule TeiserverWeb.Battle.LobbyLive.Show do
ratings =
users
|> Map.new(fn {userid, _} ->
{userid, BalanceLib.get_user_rating_value_uncertainty_pair(userid, "Team")}
{userid, BalanceLib.get_user_rating_value_uncertainty_pair(userid, "Large Team")}
end)

{users, clients, ratings, parties, stats}
Expand Down
4 changes: 2 additions & 2 deletions lib/teiserver_web/live/battles/match/ratings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Ratings do
|> assign(:view_colour, Battle.MatchLib.colours())
|> assign(:game_types, game_types)
|> assign(:user_ratings, user_ratings)
|> assign(:rating_type, Map.get(params, "rating_type", "Team"))
|> assign(:rating_type, Map.get(params, "rating_type", "Large Team"))
|> assign(:rating_type_list, MatchRatingLib.rating_type_list())
|> assign(:rating_type_id_lookup, MatchRatingLib.rating_type_id_lookup())
|> add_breadcrumb(name: "Matches", url: "/battle/matches")
Expand All @@ -39,7 +39,7 @@ defmodule TeiserverWeb.Battle.MatchLive.Ratings do
def handle_params(params, _url, socket) do
socket =
socket
|> assign(:rating_type, Map.get(params, "rating_type", "Team"))
|> assign(:rating_type, Map.get(params, "rating_type", "Large Team"))
|> update_match_list()

{:noreply, socket}
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/tournament/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ defmodule TeiserverWeb.TournamentLive.Show do
ratings =
users
|> Map.new(fn {userid, _} ->
{userid, BalanceLib.get_user_rating_value_uncertainty_pair(userid, "Team")}
{userid, BalanceLib.get_user_rating_value_uncertainty_pair(userid, "Large Team")}
end)

{users, clients, ratings, parties, stats}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
<th>Weighted Total</th>

<th>Duel</th>
<th>Team</th>
<th>Small Team</th>
<th>LargeTeam</th>
<th>FFA</th>
<th>Team FFA</th>
<th>Scav</th>
Expand All @@ -58,7 +59,8 @@
<td><%= format_number(log.data["totals"]["aggregate"]["weighted_count"]) %></td>

<td><%= format_number(log.data["duel"]["aggregate"]["total_count"]) %></td>
<td><%= format_number(log.data["team"]["aggregate"]["total_count"]) %></td>
<td><%= format_number(log.data["small_team"]["aggregate"]["total_count"]) %></td>
<td><%= format_number(log.data["large_team"]["aggregate"]["total_count"]) %></td>
<td><%= format_number(log.data["ffa"]["aggregate"]["total_count"]) %></td>
<td><%= format_number(log.data["team_ffa"]["aggregate"]["total_count"]) %></td>
<td><%= format_number(log.data["scavengers"]["aggregate"]["total_count"]) %></td>
Expand Down
Loading
Loading