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

Split Team ratings into Small team and big team #296

Merged
merged 26 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
3 changes: 1 addition & 2 deletions lib/teiserver/account/reports/mapping_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ defmodule Teiserver.Game.MappingReport do
search: [
started_after: start_date |> Timex.to_datetime(),
started_before: end_date |> Timex.to_datetime(),
# game_type_in: ["Duel", "Team", "FFA", "Team FFA"],
game_type_in: ["Duel", "Team"],
game_type_in: ["Duel", "Small Team", "Big Team"],
of_interest: true,
has_winning_team: true
],
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/account/reports/open_skill_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ defmodule Teiserver.Account.OpenSkillReport do
defp apply_defaults(params) do
Map.merge(
%{
"rating_type" => "Team",
"rating_type" => "Big Team",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make an issue to improve this report and make this a selector but I have a started branch with that anyway

"metric" => "Game Rating",
"last_active" => "7 days",
"uncertainty" => "5"
Expand Down
4 changes: 3 additions & 1 deletion lib/teiserver/account/reports/user_age_report.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ defmodule Teiserver.Account.UserAgeReport do
type_where =
case params["game_type"] do
"Duel" -> "AND m.game_type = 'Duel'"
"Team" -> "AND m.game_type = 'Team'"
"Team" -> "AND m.game_type IN ('Small Team', 'Big Team')"
"Small Team" -> "AND m.game_type = 'Small Team'"
"Big Team" -> "AND m.game_type = 'Big Team'"
"FFA" -> "AND m.game_type = 'FFA'"
"Raptors" -> "AND m.game_type = 'Raptors'"
"Scavengers" -> "AND m.game_type = 'Scavengers'"
Expand Down
15 changes: 12 additions & 3 deletions lib/teiserver/account/tasks/recalculate_user_cache_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule Teiserver.Account.RecacheUserStatsTask do
case match.game_type do
"Duel" -> do_match_processed_duel(userid)
"FFA" -> do_match_processed_duel(userid)
"Team" -> do_match_processed_team(userid)
"Small Team" -> do_match_processed_team_small(userid)
"Big Team" -> do_match_processed_team_big(userid)
_ -> :ok
end

Expand Down Expand Up @@ -105,8 +106,16 @@ defmodule Teiserver.Account.RecacheUserStatsTask do
:ok
end

def do_match_processed_team(userid) do
filter_type_id = MatchRatingLib.rating_type_name_lookup()["Team"]
def do_match_processed_team_big(userid) do
do_match_processed_team(userid, "Big Team")
end

def do_match_processed_team_small(userid) do
do_match_processed_team(userid, "Small Team")
end

defp do_match_processed_team(userid, team_subtype) do
filter_type_id = MatchRatingLib.rating_type_name_lookup()[team_subtype]

logs =
Game.list_rating_logs(
Expand Down
11 changes: 7 additions & 4 deletions lib/teiserver/battle/libs/match_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ defmodule Teiserver.Battle.MatchLib do
String.contains?(bot_names, "Raptor") -> "Raptors"
Enum.empty?(bots) == false -> "Bots"
Enum.count(teams) == 2 and max_team_size == 1 -> "Duel"
Enum.count(teams) == 2 -> "Team"
Enum.count(teams) == 2 and max_team_size <= 4 -> "Small Team" # 2v2, 3v3, 4v4
Enum.count(teams) == 2 and max_team_size > 4 -> "Big Team" # 5v5, 6v6, 7v7, 8v8
max_team_size == 1 -> "FFA"
true -> "Team FFA"
end
Expand All @@ -47,7 +48,8 @@ defmodule Teiserver.Battle.MatchLib do
def list_game_types() do
[
"Duel",
"Team",
"Small Team",
"Big Team",
"FFA",
"Team FFA",
"Raptors",
Expand All @@ -59,7 +61,8 @@ defmodule Teiserver.Battle.MatchLib do
def list_rated_game_types() do
[
"Duel",
"Team",
"Small Team",
"Big Team",
"FFA",
"Team FFA"
]
Expand Down Expand Up @@ -142,7 +145,7 @@ defmodule Teiserver.Battle.MatchLib do
def make_match_name(match) do
case match.game_type do
"Duel" -> "Duel on #{match.map}"
"Team" -> "#{match.team_size}v#{match.team_size} on #{match.map}"
type when type in ["Small Team", "Big Team"] -> "#{match.team_size}v#{match.team_size} on #{match.map}"
"FFA" -> "#{match.team_count} way FFA on #{match.map}"
t -> "#{t} game on #{match.map}"
end
Expand Down
3 changes: 2 additions & 1 deletion lib/teiserver/battle/tasks/breakdown_match_data_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule Teiserver.Battle.Tasks.BreakdownMatchDataTask do

%{
duel: get_subset_data(matches, game_type: "Duel"),
team: get_subset_data(matches, game_type: "Team"),
small_team: get_subset_data(matches, game_type: "Small Team"),
big_team: get_subset_data(matches, game_type: "Big Team"),
ffa: get_subset_data(matches, game_type: "FFA"),
team_ffa: get_subset_data(matches, game_type: "Team FFA"),
scavengers: get_subset_data(matches, game_type: "Scavengers"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Teiserver.Battle.ExportRawMatchMetricsTask do
defp do_output(data, _params) do
data
|> Stream.filter(fn match ->
match.game_type == "Team"
match.game_type in ["Small Team", "Big Team"]
end)
|> Stream.map(fn match ->
members =
Expand Down
4 changes: 3 additions & 1 deletion lib/teiserver/coordinator/consul_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,9 @@ defmodule Teiserver.Coordinator.ConsulServer do
player_list = list_players(state)

{player_rating, player_uncertainty} =
BalanceLib.get_user_rating_value_uncertainty_pair(user.id, "Team")
# TODO FIX THIS BUG
L-e-x-o-n marked this conversation as resolved.
Show resolved Hide resolved
# Teiserver.Battle.MatchLib.game_type/2 maybe to check for game type to get ratings for?
BalanceLib.get_user_rating_value_uncertainty_pair(user.id, "Big Team")

player_rating = max(player_rating, 1)
avoid_status = Account.check_avoid_status(user.id, player_list)
Expand Down
7 changes: 3 additions & 4 deletions lib/teiserver/game/libs/match_rating_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Teiserver.Game.MatchRatingLib do
alias Teiserver.Battle.{BalanceLib, MatchLib}
require Logger

@rated_match_types ["Team", "Duel", "FFA", "Team FFA", "Partied Team"]
@rated_match_types ["Small Team", "Big Team", "Duel", "Team", "FFA", "Team FFA", "Partied Team"]

@spec rating_type_list() :: [String.t()]
def rating_type_list() do
Expand Down Expand Up @@ -191,7 +191,7 @@ defmodule Teiserver.Game.MatchRatingLib do
rate_result = rate_with_ids([winner_ratings, loser_ratings], as_map: true)

status_lookup =
if match.game_type == "Team" do
if match.game_type in ["Small Team", "Big Team"] do
match.members
|> Map.new(fn membership ->
{membership.user_id,
Expand Down Expand Up @@ -357,7 +357,7 @@ defmodule Teiserver.Game.MatchRatingLib do
win_result = Map.new(win_result)

status_lookup =
if Enum.member?(["Team", "Team FFA"], match.game_type) do
if Enum.member?(["Small Team", "Big Team", "Team FFA"], match.game_type) do
match.members
|> Map.new(fn membership ->
{membership.user_id,
Expand Down Expand Up @@ -771,7 +771,6 @@ defmodule Teiserver.Game.MatchRatingLib do
results =
Battle.list_matches(
search: [
# game_type_in: ["Team"],
game_type_in: @rated_match_types,
processed: true,
started_after: Timex.now() |> Timex.shift(days: -31)
Expand Down
7 changes: 5 additions & 2 deletions lib/teiserver/game/servers/balancer_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,13 @@ defmodule Teiserver.Game.BalancerServer do
"Duel"

team_count > 2 ->
if player_count > team_count, do: "Team", else: "FFA"
if player_count > team_count, do: "Big Team", else: "FFA"

team_count == 2 ->
if player_count > 8, do: "Big Team", else: "Small Team"

true ->
"Team"
"Big Team"
end

if opts[:allow_groups] do
Expand Down
3 changes: 2 additions & 1 deletion lib/teiserver/libs/test_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ defmodule Teiserver.TeiserverTestLib do
Teiserver.Account.get_or_add_smurf_key_type("hw3")

Teiserver.Game.get_or_add_rating_type("Duel")
Teiserver.Game.get_or_add_rating_type("Team")
Teiserver.Game.get_or_add_rating_type("Small Team")
Teiserver.Game.get_or_add_rating_type("Big Team")
Teiserver.Game.get_or_add_rating_type("FFA")

Teiserver.Telemetry.get_or_add_complex_server_event_type("Server startup")
Expand Down
9 changes: 6 additions & 3 deletions lib/teiserver/logging/tasks/match_graph_logs_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ defmodule Teiserver.Logging.MatchGraphLogsTask do
def perform(logs, "split", key) do
[
{"Duel", "duel.aggregate.#{key}"},
{"Team", "team.aggregate.#{key}"},
{"Small Team", "team.aggregate.#{key}"},
{"Big Team", "team.aggregate.#{key}"},
{"FFA", "ffa.aggregate.#{key}"},
{"Team FFA", "team_ffa.aggregate.#{key}"},
{"Bot", "bots.aggregate.#{key}"},
Expand Down Expand Up @@ -34,7 +35,8 @@ defmodule Teiserver.Logging.MatchGraphLogsTask do
pvp =
Map.get(l.data["duel"]["aggregate"], key, 0) +
Map.get(l.data["ffa"]["aggregate"], key, 0) +
Map.get(l.data["team"]["aggregate"], key, 0) +
Map.get(l.data["small_team"]["aggregate"], key, 0) +
Map.get(l.data["big_team"]["aggregate"], key, 0) +
Map.get(l.data["team_ffa"]["aggregate"], key, 0)

pve =
Expand Down Expand Up @@ -84,7 +86,8 @@ defmodule Teiserver.Logging.MatchGraphLogsTask do
pvp =
Map.get(l.data["duel"]["aggregate"], key, 0) +
Map.get(l.data["ffa"]["aggregate"], key, 0) +
Map.get(l.data["team"]["aggregate"], key, 0)
Map.get(l.data["big_team"]["aggregate"], key, 0) +
Map.get(l.data["team_ffa"]["aggregate"], key, 0)

coop =
Map.get(l.data["raptors"]["aggregate"], key, 0) +
Expand Down
3 changes: 2 additions & 1 deletion lib/teiserver/logging/tasks/persist_server_day_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ defmodule Teiserver.Logging.Tasks.PersistServerDayTask do
"Raptors" -> :raptors
"Bots" -> :bots
"Duel" -> :duel
"Team" -> :team
"Small Team" -> :small_team
"Big Team" -> :big_team
"FFA" -> :ffa
"Team FFA" -> :team_ffa
end
Expand Down
8 changes: 7 additions & 1 deletion lib/teiserver/mix_tasks/fake_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ defmodule Mix.Tasks.Teiserver.Fakedata do
team1 = shuffled_users |> Enum.take(team_size)
team2 = shuffled_users |> Enum.reverse() |> Enum.take(team_size)

game_type = cond do
team_size == 1 -> "Duel"
team_size <= 4 -> "Small Team"
true -> "Big Team"
end

team1_score =
team1
|> Enum.map(fn {_, name} -> String.length(name) end)
Expand All @@ -356,7 +362,7 @@ defmodule Mix.Tasks.Teiserver.Fakedata do
team_size: team_size,
passworded: false,
processed: true,
game_type: if(team_size == 1, do: "Duel", else: "Team"),
game_type: game_type,

# All rooms are hosted by the same user for now
founder_id: 1,
Expand Down
101 changes: 101 additions & 0 deletions lib/teiserver/mix_tasks/team_rating.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
defmodule Mix.Tasks.Teiserver.Teamrating do
@moduledoc """
Run with mix teiserver.teamrating
Goes through every existing 'Team' rating and sorts it into either 'Small Team' or 'Big Team' rating category based on team size.
Recalculates 'Small Team' and 'Big Team' ratings for affected players.
"""

use Mix.Task

alias Teiserver.Battle
require Logger

@spec run(list()) :: :ok
def run(args) do
Application.ensure_all_started(:teiserver)

rating_type_id = Teiserver.Game.MatchRatingLib.rating_type_name_lookup()["Team"]
Teiserver.Game.MatchRatingLib.reset_player_ratings(rating_type_id)

Logger.debug("Starting to process small team games..")
process_small_team_games()
Logger.debug("Finished processing small team games")

Logger.debug("Starting to process big team games")
process_big_team_games(0, 0)
Logger.debug("Finished processing big team games")
end

defp process_small_team_games() do
# Get all small team matches
small_team_matches =
Battle.list_matches(
search: [
server_uuid_not_nil: true,
game_type_in: ["Team", "Small Team"],
has_finished: true,
processed: true,
team_size_less_than: 5
],
order_by: "Oldest first",
limit: :infinity,
preload: [:members]
)

Logger.debug("Found #{Enum.count(small_team_matches)} small team game matches")

# For small team games change game type and update rating
small_team_matches
|> Enum.chunk_every(50)
|> Enum.each(fn chunk ->
chunk
|> Enum.each(fn match ->
Battle.update_match(match, %{
game_type: "Small Team"
})

Teiserver.rate_match(match.id)
end)
end)
end

defp process_big_team_games(offset, i) do
batch_size = 50_000

big_team_matches =
Battle.list_matches(
search: [
server_uuid_not_nil: true,
game_type_in: ["Team", "Big Team"],
has_finished: true,
processed: true,
team_size_greater_than: 4
],
order_by: "Oldest first",
limit: batch_size,
offset: offset,
preload: [:members]
)

match_count = Enum.count(big_team_matches)
Logger.debug("Batch #{i} - Found #{match_count} big team game matches")

if match_count > 0 do
big_team_matches
|> Enum.chunk_every(50)
|> Enum.each(fn chunk ->
chunk
|> Enum.each(fn match ->
Battle.update_match(match, %{
game_type: "Big Team"
})
Teiserver.rate_match(match.id)
end)
end)

# Fetch and process the next batch
process_big_team_games(offset + batch_size, i+1)
end
end

end
5 changes: 4 additions & 1 deletion lib/teiserver_web/controllers/admin/match_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ defmodule TeiserverWeb.Admin.MatchController do
match.team_count > 2 ->
if match.team_size > 1, do: "Team FFA", else: "FFA"

match.team_count == 2 ->
if match.team_size > 4, do: "Big Team", else: "Small Team"

true ->
"Team"
"Big Team"
end

partied_players =
Expand Down
5 changes: 3 additions & 2 deletions lib/teiserver_web/controllers/api/spads_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule TeiserverWeb.API.SpadsController do
}) do
actual_type =
case type do
"TeamFFA" -> "Team"
"TeamFFA" -> "Big Team" # Team FFA uses Big Team rating
v -> v
end

Expand Down Expand Up @@ -160,7 +160,8 @@ defmodule TeiserverWeb.API.SpadsController do
rating_type =
cond do
total_players == 2 -> "Duel"
team_count == 2 -> "Team"
team_count == 2 and total_players <= 8 -> "Small Team"
team_count == 2 and total_players > 8 -> "Big Team"
total_players == team_count -> "FFA"
true -> "Team FFA"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/controllers/report/rating_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ defmodule TeiserverWeb.Report.RatingController do
rating_type =
cond do
Enum.count(player_ids) == 2 -> "Duel"
true -> "Team"
true -> "Big Team" # Should probably get rating based on team size instad
L-e-x-o-n marked this conversation as resolved.
Show resolved Hide resolved
end

rating_lookup =
Expand Down
Loading
Loading