Skip to content

Commit

Permalink
feat: add win rate color and change stats with dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharlock10 committed Apr 16, 2024
1 parent 2c78f8a commit 1e70a0f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ const themeNames = {
const baseUrl = "https://api.paladinsedge.app";
const githubLink = "https://github.com/tusharlock10/paladins-edge-client";
const sponsorLink = "https://github.com/sponsors/tusharlock10";

// The number of matches after which win rate will start showing on the timed stats widget
const timedStatsWinRateThreshold = 25;
14 changes: 12 additions & 2 deletions lib/data_classes/players/player_timed_stats.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "package:flutter/material.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:paladinsedge/models/index.dart" show Ranked, MatchPlayerStats;
import "package:paladinsedge/utilities/index.dart" as utilities;
Expand Down Expand Up @@ -44,9 +45,18 @@ class PlayerTimedStats with _$PlayerTimedStats {
}) = _PlayerTimedStats;

int get totalMatches => wins + losses;

num get winRate => wins * 100 / totalMatches;
String get winRateFormatted => winRate.toStringAsPrecision(3);
MaterialColor get winRateColor => utilities.getWinRateColor(winRate);

num get damagePerMinute => utilities.safeDivide(
totalStats.totalDamageDealt, totalMatchesDuration.inMinutes);
totalStats.totalDamageDealt,
totalMatchesDuration.inMinutes,
);
num get healingPerMinute => utilities.safeDivide(
totalStats.healingDone, totalMatchesDuration.inMinutes);
totalStats.healingDone,
totalMatchesDuration.inMinutes,
);
MatchPlayerStats get averageStats => totalStats / totalMatches;
}
11 changes: 10 additions & 1 deletion lib/providers/players.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,18 @@ class _PlayersNotifier extends ChangeNotifier {
notifyListeners();
}

/// Set the timedStatsType
/// Set the timedStatsType and recalculate the timedStats
void setTimedStatsType(data_classes.TimedStatsType? value) {
timedStatsType = value ?? data_classes.TimedStatsType.days1;

if (combinedMatches != null) {
timedStats = utilities.getPlayerTimedStats(
combinedMatches!,
timedStatsType,
playerId,
);
}

notifyListeners();
}

Expand Down
13 changes: 9 additions & 4 deletions lib/screens/home/home_player_timed_stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "package:dartx/dartx.dart";
import "package:flutter/material.dart";
import "package:flutter_hooks/flutter_hooks.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:paladinsedge/constants/index.dart" as constants;
import "package:paladinsedge/data_classes/index.dart" as data_classes;
import "package:paladinsedge/providers/index.dart" as providers;
import "package:paladinsedge/utilities/index.dart" as utilities;
Expand Down Expand Up @@ -93,10 +94,14 @@ class HomePlayerTimedStats extends HookConsumerWidget {
padding: const EdgeInsets.symmetric(horizontal: 10),
children: utilities.insertBetween(
[
widgets.PlayerStatsCard(
title: "Matches",
stat: timedStats.totalMatches,
),
if (timedStats.totalMatches >
constants.timedStatsWinRateThreshold)
widgets.PlayerStatsCard(
title: "Win Rate",
stat: 0,
statString: "${timedStats.winRateFormatted}%",
color: timedStats.winRateColor,
),
widgets.PlayerStatsCard(
title: "Win - Loss",
stat: 0,
Expand Down

0 comments on commit 1e70a0f

Please sign in to comment.