Skip to content

Commit

Permalink
Merge pull request #82 from canopas/Mayank/allow-team-add-multiple-ad…
Browse files Browse the repository at this point in the history
…mins

Allow team to add multiple admins
  • Loading branch information
cp-mayank authored Aug 23, 2024
2 parents f4d171d + 36d8ca0 commit b698acf
Show file tree
Hide file tree
Showing 51 changed files with 1,505 additions and 957 deletions.
16 changes: 16 additions & 0 deletions data/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
include: package:flutter_lints/flutter.yaml
analyzer:
exclude:
- '**.freezed.dart'
- '**.g.dart'
- '**.gr.dart'
- '**/generated_plugin_registrant.dart'

errors:
invalid_annotation_target: ignore

linter:
rules:
prefer_relative_imports: true
prefer_final_locals: true
require_trailing_commas: true
always_declare_return_types: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
189 changes: 109 additions & 80 deletions data/lib/api/ball_score/ball_score_model.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ignore_for_file: non_constant_identifier_names

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:data/api/user/user_models.dart';
import 'package:data/extensions/double_extensions.dart';
import 'package:data/extensions/int_extensions.dart';
import '../user/user_models.dart';
import '../../extensions/double_extensions.dart';
import '../../extensions/int_extensions.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'ball_score_model.freezed.dart';
Expand Down Expand Up @@ -36,8 +36,9 @@ class BallScoreModel with _$BallScoreModel {
_$BallScoreModelFromJson(json);

factory BallScoreModel.fromFireStore(
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options) =>
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options,
) =>
BallScoreModel.fromJson(snapshot.data()!);
}

Expand Down Expand Up @@ -279,7 +280,7 @@ extension OverSummaryMetaData on OverSummary {
(balls.lastOrNull?.isLegalDelivery() ?? false);

double get overCount {
int totalBalls = ((overNumber - 1) * 6) + legalDeliveriesCount;
final int totalBalls = ((overNumber - 1) * 6) + legalDeliveriesCount;
return totalBalls.toOvers();
}

Expand All @@ -290,35 +291,43 @@ extension OverSummaryMetaData on OverSummary {
balls.fold(0, (runCount, element) => runCount += element.runs_scored);

int get extras => balls.fold(
0, (extraCount, element) => extraCount += (element.extras_awarded ?? 0));
0,
(extraCount, element) => extraCount += (element.extras_awarded ?? 0),
);

int get wickets => balls.fold(
0,
(wicketCount, element) => wicketCount += (element.wicket_type != null &&
element.wicket_type != WicketType.retiredHurt
? 1
: 0));
0,
(wicketCount, element) => wicketCount += (element.wicket_type != null &&
element.wicket_type != WicketType.retiredHurt
? 1
: 0),
);

DateTime get time => balls.lastOrNull?.time ?? DateTime.now();

BowlerSummary get bowlerStatAtStart {
final runsInOver = balls
.where((ball) =>
ball.extras_type == null ||
ball.extras_type == ExtrasType.noBall ||
ball.extras_type == ExtrasType.wide)
.where(
(ball) =>
ball.extras_type == null ||
ball.extras_type == ExtrasType.noBall ||
ball.extras_type == ExtrasType.wide,
)
.fold(
0,
(runCount, ball) =>
runCount += (ball.extras_awarded ?? 0) + ball.runs_scored);
0,
(runCount, ball) =>
runCount += (ball.extras_awarded ?? 0) + ball.runs_scored,
);
final runsConceded = bowler.runsConceded - runsInOver;
final maiden = bowler.maiden - (isMaiden ? 1 : 0);
final wicketsInOver = balls
.where((element) =>
element.wicket_type != null &&
element.wicket_type != WicketType.retired &&
element.wicket_type != WicketType.retiredHurt &&
element.wicket_type != WicketType.timedOut)
.where(
(element) =>
element.wicket_type != null &&
element.wicket_type != WicketType.retired &&
element.wicket_type != WicketType.retiredHurt &&
element.wicket_type != WicketType.timedOut,
)
.length;
final wickets = bowler.wicket - wicketsInOver;
final noBallInOver = balls
Expand All @@ -331,12 +340,13 @@ extension OverSummaryMetaData on OverSummary {

final overDelivered = bowler.overDelivered.remove(legalDeliveriesCount);
return bowler.copyWith(
wideBalls: wideBalls,
runsConceded: runsConceded,
overDelivered: overDelivered,
noBalls: noBalls,
maiden: maiden,
wicket: wickets);
wideBalls: wideBalls,
runsConceded: runsConceded,
overDelivered: overDelivered,
noBalls: noBalls,
maiden: maiden,
wicket: wickets,
);
}

OverSummary addBall(BallScoreModel ball, {Player? catchBy}) {
Expand All @@ -354,17 +364,21 @@ extension OverSummaryMetaData on OverSummary {
final ballScores = [...balls, ball].toList();
ballScores.sort((a, b) => a.time.compareTo(b.time));

final configuredStriker = striker.addBall(ball,
ballBy: ball.player_out_id == striker.player.id
? Player(id: bowler.player.id, name: bowler.player.name ?? "")
: null,
catchBy: ball.player_out_id == striker.player.id ? catchBy : null);
final configuredStriker = striker.addBall(
ball,
ballBy: ball.player_out_id == striker.player.id
? Player(id: bowler.player.id, name: bowler.player.name ?? "")
: null,
catchBy: ball.player_out_id == striker.player.id ? catchBy : null,
);

final configuredNonStriker = nonStriker.addBall(ball,
ballBy: ball.player_out_id == nonStriker.player.id
? Player(id: bowler.player.id, name: bowler.player.name ?? "")
: null,
catchBy: ball.player_out_id == nonStriker.player.id ? catchBy : null);
final configuredNonStriker = nonStriker.addBall(
ball,
ballBy: ball.player_out_id == nonStriker.player.id
? Player(id: bowler.player.id, name: bowler.player.name ?? "")
: null,
catchBy: ball.player_out_id == nonStriker.player.id ? catchBy : null,
);

final outPlayersList = outPlayers.toList();
if (ball.player_out_id == configuredStriker.player.id) {
Expand All @@ -377,8 +391,10 @@ extension OverSummaryMetaData on OverSummary {
totalWickets: totalWicketCount,
extrasSummary: extraSummaryDetail,
balls: ballScores,
bowler: bowler.addBall(ball,
isMaidenWithoutTheBall: runs == 0 && wickets == 0 && extras == 0),
bowler: bowler.addBall(
ball,
isMaidenWithoutTheBall: runs == 0 && wickets == 0 && extras == 0,
),
outPlayers: outPlayersList,
striker: configuredStriker,
nonStriker: configuredNonStriker,
Expand Down Expand Up @@ -407,10 +423,12 @@ extension OverSummaryMetaData on OverSummary {
final outPlayersList = outPlayers;
if (ball.player_out_id == configuredStriker.player.id) {
outPlayersList.removeWhere(
(element) => element.player.id == configuredStriker.player.id);
(element) => element.player.id == configuredStriker.player.id,
);
} else if (ball.player_out_id == configuredNonStriker.player.id) {
outPlayersList.removeWhere(
(element) => element.player.id == configuredNonStriker.player.id);
(element) => element.player.id == configuredNonStriker.player.id,
);
}

final lastBall = ballScores.lastOrNull;
Expand Down Expand Up @@ -439,8 +457,10 @@ extension BowlerSummaryMetaData on BowlerSummary {
return double.parse((runsConceded / overDelivered).toStringAsFixed(1));
}

BowlerSummary addBall(BallScoreModel ball,
{required bool isMaidenWithoutTheBall}) {
BowlerSummary addBall(
BallScoreModel ball, {
required bool isMaidenWithoutTheBall,
}) {
if (ball.bowler_id != player.id) {
return this;
}
Expand Down Expand Up @@ -477,16 +497,19 @@ extension BowlerSummaryMetaData on BowlerSummary {
: maiden;

return copyWith(
wicket: wicketCount,
maiden: maidenCount,
noBalls: noBallCount,
overDelivered: overDeliverCount,
runsConceded: runCount,
wideBalls: wideBallCount);
wicket: wicketCount,
maiden: maidenCount,
noBalls: noBallCount,
overDelivered: overDeliverCount,
runsConceded: runCount,
wideBalls: wideBallCount,
);
}

BowlerSummary removeBall(BallScoreModel ball,
{required bool isMaidenIncludingBall}) {
BowlerSummary removeBall(
BallScoreModel ball, {
required bool isMaidenIncludingBall,
}) {
if (ball.bowler_id != player.id) {
return this;
}
Expand Down Expand Up @@ -523,12 +546,13 @@ extension BowlerSummaryMetaData on BowlerSummary {
: maiden;

return copyWith(
wicket: wicketCount,
maiden: maidenCount,
noBalls: noBallCount,
overDelivered: overDeliverCount,
runsConceded: runCount,
wideBalls: wideBallCount);
wicket: wicketCount,
maiden: maidenCount,
noBalls: noBallCount,
overDelivered: overDeliverCount,
runsConceded: runCount,
wideBalls: wideBallCount,
);
}
}

Expand All @@ -537,8 +561,11 @@ extension BatsmanSummaryMetaData on BatsmanSummary {
return double.parse(((runs / ballFaced) * 100).toStringAsFixed(1));
}

BatsmanSummary addBall(BallScoreModel ball,
{Player? ballBy, Player? catchBy}) {
BatsmanSummary addBall(
BallScoreModel ball, {
Player? ballBy,
Player? catchBy,
}) {
if (ball.batsman_id != player.id && ball.non_striker_id != player.id) {
return this;
}
Expand All @@ -548,16 +575,17 @@ extension BatsmanSummaryMetaData on BatsmanSummary {
? ballFaced + 1
: ballFaced;
return copyWith(
sixes: ball.batsman_id == player.id && ball.is_six ? sixes + 1 : sixes,
fours: ball.batsman_id == player.id && ball.is_four ? fours + 1 : fours,
catchBy: catchBy,
ballBy: ballBy,
ballFaced: ballFacedCount,
runs: ball.batsman_id == player.id ? runs + ball.runs_scored : runs,
outAtOver: ball.wicket_type != null && ball.player_out_id == player.id
? double.parse("${ball.over_number - 1}.${ball.ball_number}")
: outAtOver,
wicketType: ball.player_out_id == player.id ? ball.wicket_type : null);
sixes: ball.batsman_id == player.id && ball.is_six ? sixes + 1 : sixes,
fours: ball.batsman_id == player.id && ball.is_four ? fours + 1 : fours,
catchBy: catchBy,
ballBy: ballBy,
ballFaced: ballFacedCount,
runs: ball.batsman_id == player.id ? runs + ball.runs_scored : runs,
outAtOver: ball.wicket_type != null && ball.player_out_id == player.id
? double.parse("${ball.over_number - 1}.${ball.ball_number}")
: outAtOver,
wicketType: ball.player_out_id == player.id ? ball.wicket_type : null,
);
}

BatsmanSummary removeBall(BallScoreModel ball) {
Expand All @@ -570,14 +598,15 @@ extension BatsmanSummaryMetaData on BatsmanSummary {
? ballFaced - 1
: ballFaced;
return copyWith(
sixes: ball.batsman_id == player.id && ball.is_six ? sixes - 1 : sixes,
fours: ball.batsman_id == player.id && ball.is_four ? fours - 1 : fours,
catchBy: null,
ballBy: null,
ballFaced: ballFacedCount,
runs: ball.batsman_id == player.id ? runs - ball.runs_scored : runs,
outAtOver: null,
wicketType: null);
sixes: ball.batsman_id == player.id && ball.is_six ? sixes - 1 : sixes,
fours: ball.batsman_id == player.id && ball.is_four ? fours - 1 : fours,
catchBy: null,
ballBy: null,
ballFaced: ballFacedCount,
runs: ball.batsman_id == player.id ? runs - ball.runs_scored : runs,
outAtOver: null,
wicketType: null,
);
}
}

Expand Down
5 changes: 3 additions & 2 deletions data/lib/api/innings/inning_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class InningModel with _$InningModel {
_$InningModelFromJson(json);

factory InningModel.fromFireStore(
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options) =>
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options,
) =>
InningModel.fromJson(snapshot.data()!);
}

Expand Down
18 changes: 10 additions & 8 deletions data/lib/api/match/match_model.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// ignore_for_file: non_constant_identifier_names

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:data/api/team/team_model.dart';
import 'package:data/api/user/user_models.dart';
import '../team/team_model.dart';
import '../user/user_models.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

part 'match_model.freezed.dart';
Expand Down Expand Up @@ -77,10 +77,11 @@ extension DataMatchModel on MatchModel {

final runDifference = firstTeam.run - secondTeam.run;
return MatchResult(
teamId: firstTeam.team.id ?? "",
teamName: teamName,
difference: runDifference,
winType: WinnerByType.run);
teamId: firstTeam.team.id ?? "",
teamName: teamName,
difference: runDifference,
winType: WinnerByType.run,
);
} else if (firstTeam.run == secondTeam.run) {
return MatchResult(
teamId: "",
Expand Down Expand Up @@ -183,8 +184,9 @@ class AddEditMatchRequest with _$AddEditMatchRequest {
_$AddEditMatchRequestFromJson(json);

factory AddEditMatchRequest.fromFireStore(
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options) =>
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options,
) =>
AddEditMatchRequest.fromJson(snapshot.data()!);
}

Expand Down
5 changes: 3 additions & 2 deletions data/lib/api/support/support_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class AddSupportCaseRequest with _$AddSupportCaseRequest {
_$AddSupportCaseRequestFromJson(json);

factory AddSupportCaseRequest.fromFireStore(
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options) =>
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options,
) =>
AddSupportCaseRequest.fromJson(snapshot.data()!);
}

Expand Down
Loading

0 comments on commit b698acf

Please sign in to comment.