Game zu Match umbenennen #89

Merged
flixcoo merged 5 commits from refactoring/78-game-zu-match-umbenennen into development 2025-12-12 15:34:17 +00:00
3 changed files with 16 additions and 16 deletions
Showing only changes of commit c4b249b199 - Show all commits

View File

@@ -66,7 +66,7 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
return (count ?? 0) > 0; return (count ?? 0) > 0;
} }
/// Removes the association of a player with a game by deleting the record /// Removes the association of a player with a match by deleting the record
/// from the [PlayerMatchTable]. /// from the [PlayerMatchTable].
/// Returns `true` if more than 0 rows were affected, otherwise `false`. /// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> removePlayerFromMatch({ Future<bool> removePlayerFromMatch({

View File

@@ -82,7 +82,7 @@ class _HomeViewState extends State<HomeView> {
return QuickInfoTile( return QuickInfoTile(
width: constraints.maxWidth * 0.45, width: constraints.maxWidth * 0.45,
height: constraints.maxHeight * 0.15, height: constraints.maxHeight * 0.15,
title: 'Games', title: 'Matches',
icon: Icons.groups_rounded, icon: Icons.groups_rounded,
value: count, value: count,
); );
@@ -112,7 +112,7 @@ class _HomeViewState extends State<HomeView> {
padding: const EdgeInsets.symmetric(vertical: 16.0), padding: const EdgeInsets.symmetric(vertical: 16.0),
child: InfoTile( child: InfoTile(
width: constraints.maxWidth * 0.95, width: constraints.maxWidth * 0.95,
title: 'Recent Games', title: 'Recent Matches',
icon: Icons.timer, icon: Icons.timer,
content: Padding( content: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0), padding: const EdgeInsets.symmetric(horizontal: 40.0),
@@ -127,7 +127,7 @@ class _HomeViewState extends State<HomeView> {
return const Center( return const Center(
heightFactor: 4, heightFactor: 4,
child: Text( child: Text(
'Error while loading recent games.', 'Error while loading recent matches.',
), ),
); );
} }

View File

@@ -33,7 +33,7 @@ class _StatisticsViewState extends State<StatisticsView> {
final matches = results[0] as List<Match>; final matches = results[0] as List<Match>;
final players = results[1] as List<Player>; final players = results[1] as List<Player>;
winCounts = _calculateWinsForAllPlayers(matches, players); winCounts = _calculateWinsForAllPlayers(matches, players);
matchCounts = _calculateGameAmountsForAllPlayers(matches, players); matchCounts = _calculateMatchAmountsForAllPlayers(matches, players);
winRates = computeWinRatePercent(wins: winCounts, matches: matchCounts); winRates = computeWinRatePercent(wins: winCounts, matches: matchCounts);
if (mounted) { if (mounted) {
setState(() { setState(() {
@@ -97,14 +97,14 @@ class _StatisticsViewState extends State<StatisticsView> {
/// Calculates the number of wins for each player /// Calculates the number of wins for each player
/// and returns a sorted list of tuples (playerName, winCount) /// and returns a sorted list of tuples (playerName, winCount)
List<(String, int)> _calculateWinsForAllPlayers( List<(String, int)> _calculateWinsForAllPlayers(
List<Match> games, List<Match> matches,
List<Player> players, List<Player> players,
) { ) {
List<(String, int)> winCounts = []; List<(String, int)> winCounts = [];
// Getting the winners // Getting the winners
for (var game in games) { for (var match in matches) {
final winner = game.winner; final winner = match.winner;
if (winner != null) { if (winner != null) {
final index = winCounts.indexWhere((entry) => entry.$1 == winner.id); final index = winCounts.indexWhere((entry) => entry.$1 == winner.id);
// -1 means winner not found in winCounts // -1 means winner not found in winCounts
@@ -143,7 +143,7 @@ class _StatisticsViewState extends State<StatisticsView> {
/// Calculates the number of matches played for each player /// Calculates the number of matches played for each player
/// and returns a sorted list of tuples (playerName, matchCount) /// and returns a sorted list of tuples (playerName, matchCount)
List<(String, int)> _calculateGameAmountsForAllPlayers( List<(String, int)> _calculateMatchAmountsForAllPlayers(
List<Match> matches, List<Match> matches,
List<Player> players, List<Player> players,
) { ) {
@@ -155,7 +155,7 @@ class _StatisticsViewState extends State<StatisticsView> {
final members = match.group!.members.map((p) => p.id).toList(); final members = match.group!.members.map((p) => p.id).toList();
for (var playerId in members) { for (var playerId in members) {
final index = matchCounts.indexWhere((entry) => entry.$1 == playerId); final index = matchCounts.indexWhere((entry) => entry.$1 == playerId);
// -1 means player not found in gameCounts // -1 means player not found in matchCounts
if (index != -1) { if (index != -1) {
final current = matchCounts[index].$2; final current = matchCounts[index].$2;
matchCounts[index] = (playerId, current + 1); matchCounts[index] = (playerId, current + 1);
@@ -168,7 +168,7 @@ class _StatisticsViewState extends State<StatisticsView> {
final members = match.players!.map((p) => p.id).toList(); final members = match.players!.map((p) => p.id).toList();
for (var playerId in members) { for (var playerId in members) {
final index = matchCounts.indexWhere((entry) => entry.$1 == playerId); final index = matchCounts.indexWhere((entry) => entry.$1 == playerId);
// -1 means player not found in gameCounts // -1 means player not found in matchCounts
if (index != -1) { if (index != -1) {
final current = matchCounts[index].$2; final current = matchCounts[index].$2;
matchCounts[index] = (playerId, current + 1); matchCounts[index] = (playerId, current + 1);
@@ -179,10 +179,10 @@ class _StatisticsViewState extends State<StatisticsView> {
} }
} }
// Adding all players with zero games // Adding all players with zero matches
for (var player in players) { for (var player in players) {
final index = matchCounts.indexWhere((entry) => entry.$1 == player.id); final index = matchCounts.indexWhere((entry) => entry.$1 == player.id);
// -1 means player not found in gameCounts // -1 means player not found in matchCounts
if (index == -1) { if (index == -1) {
matchCounts.add((player.id, 0)); matchCounts.add((player.id, 0));
} }
@@ -209,15 +209,15 @@ class _StatisticsViewState extends State<StatisticsView> {
required List<(String, int)> matches, required List<(String, int)> matches,
}) { }) {
final Map<String, int> winsMap = {for (var e in wins) e.$1: e.$2}; final Map<String, int> winsMap = {for (var e in wins) e.$1: e.$2};
final Map<String, int> gamesMap = {for (var e in matches) e.$1: e.$2}; final Map<String, int> matchesMap = {for (var e in matches) e.$1: e.$2};
// Get all unique player names // Get all unique player names
final names = {...winsMap.keys, ...gamesMap.keys}; final names = {...winsMap.keys, ...matchesMap.keys};
// Calculate win rates // Calculate win rates
final result = names.map((name) { final result = names.map((name) {
final int w = winsMap[name] ?? 0; final int w = winsMap[name] ?? 0;
final int g = gamesMap[name] ?? 0; final int g = matchesMap[name] ?? 0;
// Calculate percentage and round to 2 decimal places // Calculate percentage and round to 2 decimal places
// Avoid division by zero // Avoid division by zero
final double percent = (g > 0) final double percent = (g > 0)