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

Best of match scheduling #136

Merged
merged 15 commits into from
Nov 21, 2024
Merged
18 changes: 18 additions & 0 deletions data/lib/api/match/match_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: non_constant_identifier_names

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:collection/collection.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import '../../converter/timestamp_json_converter.dart';
Expand Down Expand Up @@ -210,6 +211,23 @@ extension DataMatchModel on MatchModel {
revised_target == null &&
match_type == MatchType.limitedOvers;
}

double getRunRate(String teamId) {
if (!team_ids.contains(teamId)) return 0;

final team = teams.firstWhereOrNull((team) => team.team_id == teamId);
if (team == null) return 0;

final runs = team.run;
final overs = team.over;

if (overs == 0) {
return 0.0;
}

final runRate = runs / overs;
return double.parse(runRate.toStringAsFixed(2));
}
}

enum WinnerByType {
Expand Down
1 change: 0 additions & 1 deletion data/lib/api/tournament/tournament_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ enum TournamentType {
miniRobin(2, minTeamReq: 3),
boxLeague(3, minTeamReq: 4),
doubleOut(4, minTeamReq: 4),
superOver(5, minTeamReq: 2),
bestOf(6, minTeamReq: 2),
custom(7, minTeamReq: 2);

Expand Down
1 change: 0 additions & 1 deletion data/lib/api/tournament/tournament_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions khelo/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,13 @@
"tournament_type_mini_robin": "Mini Robin",
"tournament_type_box_league": "Box League",
"tournament_type_double_out": "Double Out",
"tournament_type_super_over": "Super Over",
"tournament_type_best_of": "Best Of",
"tournament_type_best_of": "Best Of three",
"tournament_type_custom": "Custom",

"tournament_type_knock_out_description": "Teams face off in a single elimination, with the loser immediately knocked out.\nMinimum {count} teams required.",
"tournament_type_mini_robin_description": "A smaller round-robin format where each team plays once against all others.\nMinimum {count} teams required.",
"tournament_type_box_league_description": "Teams are divided into groups, with top teams advancing to the knockout stage.\nMinimum {count} teams required.",
"tournament_type_double_out_description": "Teams get two chances before being knocked out, with a winners and losers bracket.\nMinimum {count} teams required.",
"tournament_type_super_over_description": "A knockout format with a super over to decide tied matches.\nMinimum {count} teams required.",
"tournament_type_best_of_description": "Teams play a series of matches, and the first to win the majority is the champion.\nMinimum {count} teams required.",
"tournament_type_custom_description": "Fully flexible, create a structure that suits your needs.\nMinimum {count} teams required.",

Expand Down
4 changes: 0 additions & 4 deletions khelo/lib/domain/extensions/enum_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ extension TournamentTypeString on TournamentType {
return context.l10n.tournament_type_box_league;
case TournamentType.doubleOut:
return context.l10n.tournament_type_double_out;
case TournamentType.superOver:
return context.l10n.tournament_type_super_over;
case TournamentType.bestOf:
return context.l10n.tournament_type_best_of;
case TournamentType.custom:
Expand All @@ -321,8 +319,6 @@ extension TournamentTypeString on TournamentType {
return context.l10n.tournament_type_box_league_description(minTeamReq);
case TournamentType.doubleOut:
return context.l10n.tournament_type_double_out_description(minTeamReq);
case TournamentType.superOver:
return context.l10n.tournament_type_super_over_description(minTeamReq);
case TournamentType.bestOf:
return context.l10n.tournament_type_best_of_description(minTeamReq);
case TournamentType.custom:
Expand Down
Loading
Loading