History graph fix

This commit is contained in:
dan63047 2024-10-21 02:05:23 +03:00
parent 6a615f8234
commit bf87f3a8e5
3 changed files with 17 additions and 17 deletions

View File

@ -10,6 +10,7 @@ import 'package:tetra_stats/gen/strings.g.dart';
import 'package:tetra_stats/main.dart';
import 'package:tetra_stats/services/crud_exceptions.dart';
import 'package:tetra_stats/utils/numers_formats.dart';
import 'package:tetra_stats/views/destination_home.dart';
import 'package:tetra_stats/views/main_view_tiles.dart';
import 'package:tetra_stats/widgets/text_timestamp.dart';
@ -132,7 +133,7 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
super.initState();
}
Future<List<Map<Stats, List<_HistoryChartSpot>>>> getHistoryData(bool fetchHistory) async {
Future<Map<int, Map<Stats, List<_HistoryChartSpot>>>> getHistoryData(bool fetchHistory) async {
if(fetchHistory){
try{
var history = await teto.fetchAndsaveTLHistory(widget.searchFor);
@ -151,15 +152,12 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
List<List<TetraLeague>> states = await Future.wait<List<TetraLeague>>([
teto.getStates(widget.searchFor, season: 1), teto.getStates(widget.searchFor, season: 2),
]);
List<Map<Stats, List<_HistoryChartSpot>>> historyData = []; // [season][metric][spot]
Map<int, Map<Stats, List<_HistoryChartSpot>>> historyData = {}; // [season][metric][spot]
for (int season = 0; season < currentSeason; season++){
if (states[season].length >= 2){
Map<Stats, List<_HistoryChartSpot>> statsMap = {};
for (var stat in Stats.values) statsMap[stat] = [for (var tl in states[season]) if (tl.getStatByEnum(stat) != null) _HistoryChartSpot(tl.timestamp, tl.gamesPlayed, tl.rank, tl.getStatByEnum(stat)!.toDouble())];
historyData.add(statsMap);
}else{
historyData.add({});
break;
historyData[season] = statsMap;
}
}
fetchData = false;
@ -184,7 +182,7 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
}
Widget getHistoryGraph(){
return FutureBuilder<List<Map<Stats, List<_HistoryChartSpot>>>>(
return FutureBuilder<Map<int, Map<Stats, List<_HistoryChartSpot>>>>(
future: getHistoryData(fetchData),
builder: (context, snapshot) {
switch (snapshot.connectionState){
@ -194,7 +192,8 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
return const Center(child: CircularProgressIndicator());
case ConnectionState.done:
if (snapshot.hasData){
List<_HistoryChartSpot> selectedGraph = snapshot.data![_season][_Ychart]!;
if (snapshot.data!.isEmpty || !snapshot.data!.containsKey(_season)) return ErrorThingy(eText: "Not enough data");
List<_HistoryChartSpot> selectedGraph = snapshot.data![_season]![_Ychart]!;
yAxisTitle = chartsShortTitles[_Ychart]!;
// TODO: this graph can Krash
return SfCartesianChart(

View File

@ -980,7 +980,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
case ConnectionState.done:
if (snapshot.hasError){ return FutureError(snapshot); }
if (snapshot.hasData){
if (!snapshot.data!.success) return FetchResultError(snapshot.data!);
if (!snapshot.data!.success) return ErrorThingy(data: snapshot.data!);
blitzBetterThanRankAverage = (snapshot.data!.summaries!.league.rank != "z" && snapshot.data!.summaries!.blitz != null && snapshot.data!.summaries!.league.rank != "x+") ? snapshot.data!.summaries!.blitz!.stats.score > blitzAverages[snapshot.data!.summaries!.league.rank]! : null;
sprintBetterThanRankAverage = (snapshot.data!.summaries!.league.rank != "z" && snapshot.data!.summaries!.sprint != null && snapshot.data!.summaries!.league.rank != "x+") ? snapshot.data!.summaries!.sprint!.stats.finalTime < sprintAverages[snapshot.data!.summaries!.league.rank]! : null;
if (snapshot.data!.summaries!.sprint != null) {

View File

@ -1385,7 +1385,7 @@ class _NewUserThingyState extends State<NewUserThingy> with SingleTickerProvider
label: _addToTrackAnim.value < 0.5 ? Container(
transform: Matrix4.translationValues(0, firstButtonPosition, 0),
child: Opacity(
opacity: min(1, firstButtonOpacity),
opacity: max(min(1, firstButtonOpacity), 0),
child: Text(_addToTrackAnimController.isAnimating && _addToTrackAnim.status == AnimationStatus.forward ? "Done!" : "Track")
)
) : Container(
@ -2169,17 +2169,18 @@ class FutureError extends StatelessWidget{
}
}
class FetchResultError extends StatelessWidget{
final FetchResults data;
class ErrorThingy extends StatelessWidget{
final FetchResults? data;
final String? eText;
FetchResultError(this.data);
ErrorThingy({this.data, this.eText});
@override
Widget build(BuildContext context) {
IconData icon = Icons.error_outline;
String errText = "";
String errText = eText??"";
String? subText;
switch (data.exception.runtimeType){
if (data?.exception != null) switch (data!.exception!.runtimeType){
case TetrioPlayerNotExist:
icon = Icons.search_off;
errText = t.errors.noSuchUser;
@ -2190,7 +2191,7 @@ class FetchResultError extends StatelessWidget{
errText = t.errors.discordNotAssigned;
subText = t.errors.discordNotAssignedSub;
case ConnectionIssue:
var err = data.exception as ConnectionIssue;
var err = data!.exception as ConnectionIssue;
errText = t.errors.connection(code: err.code, message: err.message);
break;
case TetrioForbidden:
@ -2214,7 +2215,7 @@ class FetchResultError extends StatelessWidget{
errText = t.errors.clientException;
break;
default:
errText = data.exception.toString();
errText = data!.exception.toString();
}
return TweenAnimationBuilder(
duration: Durations.medium3,