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

Record match event and partnership #149

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion data/lib/api/ball_score/ball_score_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ class ExtraSummary with _$ExtraSummary {
}) = _ExtraSummary;
}

extension BallScoreModelBoolean on BallScoreModel? {
extension BallScoreModelData on BallScoreModel? {
double get formattedOver => double.parse("${(this?.over_number ?? 1) - 1}.${this?.ball_number ?? 0}");

bool? isLegalDelivery() {
if (this == null) {
return null;
Expand Down
97 changes: 97 additions & 0 deletions data/lib/api/match_event/match_event_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ignore_for_file: non_constant_identifier_names

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

import '../../converter/timestamp_json_converter.dart';
import '../ball_score/ball_score_model.dart';

part 'match_event_model.freezed.dart';
part 'match_event_model.g.dart';

@Freezed()
class MatchEventModel with _$MatchEventModel {
@JsonSerializable(anyMap: true, explicitToJson: true, includeIfNull: false)
const factory MatchEventModel({
required String id,
required String match_id,
required String inning_id,
required EventType type,
@TimeStampJsonConverter() required DateTime time,
String? bowler_id,
String? batsman_id,
FieldingPositionType? fielding_position,
@Default(0) double over,
@Default([]) List<String> ball_ids,
@Default([]) List<MatchEventWicket> wickets,
@Default([]) List<MatchEventMilestone> milestone,
}) = _MatchEventModel;

factory MatchEventModel.fromJson(Map<String, dynamic> json) =>
_$MatchEventModelFromJson(json);

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

@JsonEnum(valueField: "value")
enum EventType {
hatTrick(1),
century(2),
fifty(3),
wicket(4),
six(5),
four(6);

final int value;

const EventType(this.value);
}

@freezed
class MatchEventWicket with _$MatchEventWicket {
@JsonSerializable(anyMap: true, explicitToJson: true)
const factory MatchEventWicket({
@TimeStampJsonConverter() required DateTime time,
required String ball_id,
required String batsman_id,
required WicketType wicket_type,
required double over,
String? wicket_taker_id,
}) = _MatchEventWicket;

factory MatchEventWicket.fromJson(Map<String, dynamic> json) =>
_$MatchEventWicketFromJson(json);

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

@freezed
class MatchEventMilestone with _$MatchEventMilestone {
@JsonSerializable(anyMap: true, explicitToJson: true)
const factory MatchEventMilestone({
@TimeStampJsonConverter() required DateTime time,
required String ball_id,
@Default(0.0) double over,
@Default(0) int runs,
@Default(0) int ball_faced,
@Default(0) int fours,
@Default(0) int sixes,
}) = _MatchEventMilestone;

factory MatchEventMilestone.fromJson(Map<String, dynamic> json) =>
_$MatchEventMilestoneFromJson(json);

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