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

Broadcast player results screen #1253

Merged
merged 21 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 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
32 changes: 32 additions & 0 deletions lib/src/model/broadcast/broadcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BroadcastTournamentData with _$BroadcastTournamentData {
const factory BroadcastTournamentData({
required BroadcastTournamentId id,
required String name,
required String slug,
required String? imageUrl,
required String? description,
required BroadcastTournamentInformation information,
Expand Down Expand Up @@ -78,6 +79,7 @@ class BroadcastRound with _$BroadcastRound {
const factory BroadcastRound({
required BroadcastRoundId id,
required String name,
required String slug,
required RoundStatus status,
required DateTime? startsAt,
required DateTime? finishedAt,
Expand Down Expand Up @@ -136,9 +138,39 @@ class BroadcastPlayerExtended with _$BroadcastPlayerExtended {
required int played,
required double? score,
required int? ratingDiff,
required int? performance,
}) = _BroadcastPlayerExtended;
}

typedef BroadcastFideData = ({
({
int? standard,
int? rapid,
int? blitz,
}) ratings,
int? birthYear,
});

typedef BroadcastPlayerResults = ({
BroadcastPlayerExtended player,
BroadcastFideData fideData,
IList<BroadcastPlayerResultData> games,
});

enum BroadcastPoints { one, half, zero }

@freezed
class BroadcastPlayerResultData with _$BroadcastPlayerResultData {
const factory BroadcastPlayerResultData({
required BroadcastRoundId roundId,
required BroadcastGameId gameId,
required Side color,
required BroadcastPoints? points,
required int? ratingDiff,
required BroadcastPlayer opponent,
}) = _BroadcastPlayerResult;
}

enum RoundStatus {
live,
finished,
Expand Down
205 changes: 205 additions & 0 deletions lib/src/model/broadcast/broadcast_federation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
const federationIdToName = {
'FID': 'FIDE',
'USA': 'United States of America',
'IND': 'India',
'CHN': 'China',
'RUS': 'Russia',
'AZE': 'Azerbaijan',
'FRA': 'France',
'UKR': 'Ukraine',
'ARM': 'Armenia',
'GER': 'Germany',
'ESP': 'Spain',
'NED': 'Netherlands',
'HUN': 'Hungary',
'POL': 'Poland',
'ENG': 'England',
'ROU': 'Romania',
'NOR': 'Norway',
'UZB': 'Uzbekistan',
'ISR': 'Israel',
'CZE': 'Czech Republic',
'SRB': 'Serbia',
'CRO': 'Croatia',
'GRE': 'Greece',
'IRI': 'Iran',
'TUR': 'Turkiye',
'SLO': 'Slovenia',
'ARG': 'Argentina',
'SWE': 'Sweden',
'GEO': 'Georgia',
'ITA': 'Italy',
'CUB': 'Cuba',
'AUT': 'Austria',
'PER': 'Peru',
'BUL': 'Bulgaria',
'BRA': 'Brazil',
'DEN': 'Denmark',
'SUI': 'Switzerland',
'CAN': 'Canada',
'SVK': 'Slovakia',
'LTU': 'Lithuania',
'VIE': 'Vietnam',
'AUS': 'Australia',
'BEL': 'Belgium',
'MNE': 'Montenegro',
'MDA': 'Moldova',
'KAZ': 'Kazakhstan',
'ISL': 'Iceland',
'COL': 'Colombia',
'BIH': 'Bosnia & Herzegovina',
'EGY': 'Egypt',
'FIN': 'Finland',
'MGL': 'Mongolia',
'PHI': 'Philippines',
'BLR': 'Belarus',
'LAT': 'Latvia',
'POR': 'Portugal',
'CHI': 'Chile',
'MEX': 'Mexico',
'MKD': 'North Macedonia',
'INA': 'Indonesia',
'PAR': 'Paraguay',
'EST': 'Estonia',
'SGP': 'Singapore',
'SCO': 'Scotland',
'VEN': 'Venezuela',
'IRL': 'Ireland',
'URU': 'Uruguay',
'TKM': 'Turkmenistan',
'MAR': 'Morocco',
'MAS': 'Malaysia',
'BAN': 'Bangladesh',
'ALG': 'Algeria',
'RSA': 'South Africa',
'AND': 'Andorra',
'ALB': 'Albania',
'KGZ': 'Kyrgyzstan',
'KOS': 'Kosovo *',
'FAI': 'Faroe Islands',
'ZAM': 'Zambia',
'MYA': 'Myanmar',
'NZL': 'New Zealand',
'ECU': 'Ecuador',
'CRC': 'Costa Rica',
'NGR': 'Nigeria',
'JPN': 'Japan',
'SYR': 'Syria',
'DOM': 'Dominican Republic',
'LUX': 'Luxembourg',
'WLS': 'Wales',
'BOL': 'Bolivia',
'TUN': 'Tunisia',
'UAE': 'United Arab Emirates',
'MNC': 'Monaco',
'TJK': 'Tajikistan',
'PAN': 'Panama',
'LBN': 'Lebanon',
'NCA': 'Nicaragua',
'ESA': 'El Salvador',
'ANG': 'Angola',
'TTO': 'Trinidad & Tobago',
'SRI': 'Sri Lanka',
'IRQ': 'Iraq',
'JOR': 'Jordan',
'UGA': 'Uganda',
'MAD': 'Madagascar',
'ZIM': 'Zimbabwe',
'MLT': 'Malta',
'SUD': 'Sudan',
'KOR': 'South Korea',
'PUR': 'Puerto Rico',
'HON': 'Honduras',
'GUA': 'Guatemala',
'PAK': 'Pakistan',
'JAM': 'Jamaica',
'THA': 'Thailand',
'YEM': 'Yemen',
'LBA': 'Libya',
'CYP': 'Cyprus',
'NEP': 'Nepal',
'HKG': 'Hong Kong, China',
'SSD': 'South Sudan',
'BOT': 'Botswana',
'PLE': 'Palestine',
'KEN': 'Kenya',
'AHO': 'Netherlands Antilles',
'MAW': 'Malawi',
'LIE': 'Liechtenstein',
'TPE': 'Chinese Taipei',
'AFG': 'Afghanistan',
'MOZ': 'Mozambique',
'KSA': 'Saudi Arabia',
'BAR': 'Barbados',
'NAM': 'Namibia',
'HAI': 'Haiti',
'ARU': 'Aruba',
'CIV': 'Cote d’Ivoire',
'CPV': 'Cape Verde',
'SUR': 'Suriname',
'LBR': 'Liberia',
'IOM': 'Isle of Man',
'MTN': 'Mauritania',
'BRN': 'Bahrain',
'GHA': 'Ghana',
'OMA': 'Oman',
'BRU': 'Brunei Darussalam',
'GCI': 'Guernsey',
'GUM': 'Guam',
'KUW': 'Kuwait',
'JCI': 'Jersey',
'MRI': 'Mauritius',
'SEN': 'Senegal',
'BAH': 'Bahamas',
'MDV': 'Maldives',
'NRU': 'Nauru',
'TOG': 'Togo',
'FIJ': 'Fiji',
'PLW': 'Palau',
'GUY': 'Guyana',
'LES': 'Lesotho',
'CAY': 'Cayman Islands',
'SOM': 'Somalia',
'SWZ': 'Eswatini',
'TAN': 'Tanzania',
'LCA': 'Saint Lucia',
'ISV': 'US Virgin Islands',
'SLE': 'Sierra Leone',
'BER': 'Bermuda',
'SMR': 'San Marino',
'BDI': 'Burundi',
'QAT': 'Qatar',
'ETH': 'Ethiopia',
'DJI': 'Djibouti',
'SEY': 'Seychelles',
'PNG': 'Papua New Guinea',
'DMA': 'Dominica',
'STP': 'Sao Tome and Principe',
'MAC': 'Macau',
'CAM': 'Cambodia',
'VIN': 'Saint Vincent and the Grenadines',
'BUR': 'Burkina Faso',
'COM': 'Comoros Islands',
'GAB': 'Gabon',
'RWA': 'Rwanda',
'CMR': 'Cameroon',
'MLI': 'Mali',
'ANT': 'Antigua and Barbuda',
'CHA': 'Chad',
'GAM': 'Gambia',
'COD': 'Democratic Republic of the Congo',
'SKN': 'Saint Kitts and Nevis',
'BHU': 'Bhutan',
'NIG': 'Niger',
'GRN': 'Grenada',
'BIZ': 'Belize',
'CAF': 'Central African Republic',
'ERI': 'Eritrea',
'GEQ': 'Equatorial Guinea',
'IVB': 'British Virgin Islands',
'LAO': 'Laos',
'SOL': 'Solomon Islands',
'TGA': 'Tonga',
'TLS': 'Timor-Leste',
'VAN': 'Vanuatu',
};
12 changes: 12 additions & 0 deletions lib/src/model/broadcast/broadcast_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ Future<IList<BroadcastPlayerExtended>> broadcastPlayers(
);
}

@riverpod
Future<BroadcastPlayerResults> broadcastPlayerResult(
Ref ref,
BroadcastTournamentId broadcastTournamentId,
String playerId,
) {
return ref.withClient(
(client) => BroadcastRepository(client)
.getPlayerResults(broadcastTournamentId, playerId),
);
}

@Riverpod(keepAlive: true)
BroadcastImageWorkerFactory broadcastImageWorkerFactory(Ref ref) {
return const BroadcastImageWorkerFactory();
Expand Down
62 changes: 61 additions & 1 deletion lib/src/model/broadcast/broadcast_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class BroadcastRepository {
mapper: _makePlayerFromJson,
);
}

Future<BroadcastPlayerResults> getPlayerResults(
BroadcastTournamentId tournamentId,
String playerId,
) {
return client.readJson(
Uri(path: 'broadcast/$tournamentId/players/$playerId'),
mapper: _makePlayerResultsFromJson,
);
}
}

BroadcastList _makeBroadcastResponseFromJson(
Expand All @@ -79,7 +89,7 @@ Broadcast _broadcastFromPick(RequiredPick pick) {
round: _roundFromPick(pick('round').required()),
group: pick('group').asStringOrNull(),
roundToLinkId:
pick('roundToLink', 'id').asBroadcastRoundIddOrNull() ?? roundId,
pick('roundToLink', 'id').asBroadcastRoundIdOrNull() ?? roundId,
);
}

Expand All @@ -89,6 +99,7 @@ BroadcastTournamentData _tournamentDataFromPick(
BroadcastTournamentData(
id: pick('id').asBroadcastTournamentIdOrThrow(),
name: pick('name').asStringOrThrow(),
slug: pick('slug').asStringOrThrow(),
imageUrl: pick('image').asStringOrNull(),
description: pick('description').asStringOrNull(),
information: (
Expand Down Expand Up @@ -139,6 +150,7 @@ BroadcastRound _roundFromPick(RequiredPick pick) {
return BroadcastRound(
id: pick('id').asBroadcastRoundIdOrThrow(),
name: pick('name').asStringOrThrow(),
slug: pick('slug').asStringOrThrow(),
status: status,
startsAt: pick('startsAt').asDateTimeFromMillisecondsOrNull(),
finishedAt: pick('finishedAt').asDateTimeFromMillisecondsOrNull(),
Expand Down Expand Up @@ -237,5 +249,53 @@ BroadcastPlayerExtended _playerExtendedFromPick(RequiredPick pick) {
played: pick('played').asIntOrThrow(),
score: pick('score').asDoubleOrNull(),
ratingDiff: pick('ratingDiff').asIntOrNull(),
performance: pick('performance').asIntOrNull(),
);
}

BroadcastPlayerResults _makePlayerResultsFromJson(
Map<String, dynamic> json,
) {
return (
player: _playerExtendedFromPick(pick(json).required()),
fideData: _fideDataFromPick(pick(json, 'fide')),
games:
pick(json, 'games').asListOrThrow(_makePlayerResultFromPick).toIList()
);
}

BroadcastFideData _fideDataFromPick(Pick pick) {
return (
ratings: (
standard: pick('ratings', 'standard').asIntOrNull(),
rapid: pick('ratings', 'rapid').asIntOrNull(),
blitz: pick('ratings', 'blitz').asIntOrNull()
),
birthYear: pick('year').asIntOrNull(),
);
}

BroadcastPlayerResultData _makePlayerResultFromPick(RequiredPick pick) {
final pointsString = pick('points').asStringOrNull();
BroadcastPoints? points;
if (pointsString == '1') {
points = BroadcastPoints.one;
} else if (pointsString == '1/2') {
points = BroadcastPoints.half;
} else if (pointsString == '0') {
points = BroadcastPoints.zero;
}

return BroadcastPlayerResultData(
roundId: pick('round').asBroadcastRoundIdOrThrow(),
gameId: pick('id').asBroadcastGameIdOrThrow(),
color: pick('color').asSideOrThrow(),
ratingDiff: pick('ratingDiff').asIntOrNull(),
points: points,
opponent: _playerFromPick(
pick('opponent').required(),
isPlaying: false,
thinkingTime: Duration.zero,
),
);
}
Loading
Loading