Skip to content

Commit

Permalink
Merge branch 'julien4215-broadcast-player-screen'
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Dec 18, 2024
2 parents 3c13242 + 185045e commit a194d20
Show file tree
Hide file tree
Showing 14 changed files with 921 additions and 192 deletions.
26 changes: 26 additions & 0 deletions lib/src/model/broadcast/broadcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BroadcastTournamentData with _$BroadcastTournamentData {
const factory BroadcastTournamentData({
required BroadcastTournamentId id,
required String name,
required String slug,
required String? imageUrl,
required String? description,
// PRIVATE=-1, NORMAL=3, HIGH=4, BEST=5
Expand Down Expand Up @@ -71,6 +72,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 @@ -126,7 +128,31 @@ 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, upcoming }
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',
};
11 changes: 11 additions & 0 deletions lib/src/model/broadcast/broadcast_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ Future<IList<BroadcastPlayerExtended>> broadcastPlayers(
return ref.withClient((client) => BroadcastRepository(client).getPlayers(tournamentId));
}

@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
59 changes: 58 additions & 1 deletion lib/src/model/broadcast/broadcast_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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(Map<String, dynamic> json) {
Expand All @@ -62,13 +72,14 @@ Broadcast _broadcastFromPick(RequiredPick pick) {
tour: _tournamentDataFromPick(pick('tour').required()),
round: _roundFromPick(pick('round').required()),
group: pick('group').asStringOrNull(),
roundToLinkId: pick('roundToLink', 'id').asBroadcastRoundIddOrNull() ?? roundId,
roundToLinkId: pick('roundToLink', 'id').asBroadcastRoundIdOrNull() ?? roundId,
);
}

BroadcastTournamentData _tournamentDataFromPick(RequiredPick pick) => BroadcastTournamentData(
id: pick('id').asBroadcastTournamentIdOrThrow(),
name: pick('name').asStringOrThrow(),
slug: pick('slug').asStringOrThrow(),
tier: pick('tier').asIntOrNull(),
imageUrl: pick('image').asStringOrNull(),
description: pick('description').asStringOrNull(),
Expand Down Expand Up @@ -116,6 +127,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 @@ -209,5 +221,50 @@ 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

0 comments on commit a194d20

Please sign in to comment.