88 lines
2.3 KiB
Dart
88 lines
2.3 KiB
Dart
class Score {
|
|
final String id;
|
|
final String memberId;
|
|
final String eventId;
|
|
final String clubId;
|
|
final List<int> frames;
|
|
final int totalScore;
|
|
final DateTime date;
|
|
final String? notes;
|
|
final String? participantName;
|
|
|
|
Score({
|
|
required this.id,
|
|
required this.memberId,
|
|
required this.eventId,
|
|
required this.clubId,
|
|
required this.frames,
|
|
required this.totalScore,
|
|
required this.date,
|
|
this.notes,
|
|
this.participantName,
|
|
});
|
|
|
|
factory Score.fromJson(Map<String, dynamic> json) {
|
|
return Score(
|
|
id: json['id']?.toString() ?? '',
|
|
memberId: json['memberId']?.toString() ?? '',
|
|
eventId: json['eventId']?.toString() ?? '',
|
|
clubId: json['clubId']?.toString() ?? '',
|
|
frames: json['frames'] != null ? List<int>.from(json['frames']) : [],
|
|
totalScore: json['totalScore'] ?? 0,
|
|
date: json['date'] != null ? DateTime.parse(json['date'].toString()) : DateTime.now(),
|
|
notes: json['notes']?.toString(),
|
|
participantName: json['participantName']?.toString(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'memberId': memberId,
|
|
'eventId': eventId,
|
|
'clubId': clubId,
|
|
'frames': frames,
|
|
'totalScore': totalScore,
|
|
'date': date.toIso8601String(),
|
|
'notes': notes,
|
|
'participantName': participantName,
|
|
};
|
|
}
|
|
}
|
|
|
|
class ScoreStatistics {
|
|
final double average;
|
|
final int highScore;
|
|
final int lowScore;
|
|
final int gamesPlayed;
|
|
final Map<String, dynamic>? additionalStats;
|
|
|
|
ScoreStatistics({
|
|
required this.average,
|
|
required this.highScore,
|
|
required this.lowScore,
|
|
required this.gamesPlayed,
|
|
this.additionalStats,
|
|
});
|
|
|
|
factory ScoreStatistics.fromJson(Map<String, dynamic> json) {
|
|
return ScoreStatistics(
|
|
average: json['average'] != null ? (json['average'] is int ? (json['average'] as int).toDouble() : json['average'].toDouble()) : 0.0,
|
|
highScore: json['highScore'] ?? 0,
|
|
lowScore: json['lowScore'] ?? 0,
|
|
gamesPlayed: json['gamesPlayed'] ?? 0,
|
|
additionalStats: json['additionalStats'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'average': average,
|
|
'highScore': highScore,
|
|
'lowScore': lowScore,
|
|
'gamesPlayed': gamesPlayed,
|
|
'additionalStats': additionalStats,
|
|
};
|
|
}
|
|
}
|