History graph fix
This commit is contained in:
parent
6a615f8234
commit
bf87f3a8e5
|
@ -10,6 +10,7 @@ import 'package:tetra_stats/gen/strings.g.dart';
|
||||||
import 'package:tetra_stats/main.dart';
|
import 'package:tetra_stats/main.dart';
|
||||||
import 'package:tetra_stats/services/crud_exceptions.dart';
|
import 'package:tetra_stats/services/crud_exceptions.dart';
|
||||||
import 'package:tetra_stats/utils/numers_formats.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/views/main_view_tiles.dart';
|
||||||
import 'package:tetra_stats/widgets/text_timestamp.dart';
|
import 'package:tetra_stats/widgets/text_timestamp.dart';
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
|
||||||
super.initState();
|
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){
|
if(fetchHistory){
|
||||||
try{
|
try{
|
||||||
var history = await teto.fetchAndsaveTLHistory(widget.searchFor);
|
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>>([
|
List<List<TetraLeague>> states = await Future.wait<List<TetraLeague>>([
|
||||||
teto.getStates(widget.searchFor, season: 1), teto.getStates(widget.searchFor, season: 2),
|
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++){
|
for (int season = 0; season < currentSeason; season++){
|
||||||
if (states[season].length >= 2){
|
if (states[season].length >= 2){
|
||||||
Map<Stats, List<_HistoryChartSpot>> statsMap = {};
|
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())];
|
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);
|
historyData[season] = statsMap;
|
||||||
}else{
|
|
||||||
historyData.add({});
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetchData = false;
|
fetchData = false;
|
||||||
|
@ -184,7 +182,7 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getHistoryGraph(){
|
Widget getHistoryGraph(){
|
||||||
return FutureBuilder<List<Map<Stats, List<_HistoryChartSpot>>>>(
|
return FutureBuilder<Map<int, Map<Stats, List<_HistoryChartSpot>>>>(
|
||||||
future: getHistoryData(fetchData),
|
future: getHistoryData(fetchData),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
switch (snapshot.connectionState){
|
switch (snapshot.connectionState){
|
||||||
|
@ -194,7 +192,8 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
case ConnectionState.done:
|
case ConnectionState.done:
|
||||||
if (snapshot.hasData){
|
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]!;
|
yAxisTitle = chartsShortTitles[_Ychart]!;
|
||||||
// TODO: this graph can Krash
|
// TODO: this graph can Krash
|
||||||
return SfCartesianChart(
|
return SfCartesianChart(
|
||||||
|
|
|
@ -980,7 +980,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
|
||||||
case ConnectionState.done:
|
case ConnectionState.done:
|
||||||
if (snapshot.hasError){ return FutureError(snapshot); }
|
if (snapshot.hasError){ return FutureError(snapshot); }
|
||||||
if (snapshot.hasData){
|
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;
|
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;
|
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) {
|
if (snapshot.data!.summaries!.sprint != null) {
|
||||||
|
|
|
@ -1385,7 +1385,7 @@ class _NewUserThingyState extends State<NewUserThingy> with SingleTickerProvider
|
||||||
label: _addToTrackAnim.value < 0.5 ? Container(
|
label: _addToTrackAnim.value < 0.5 ? Container(
|
||||||
transform: Matrix4.translationValues(0, firstButtonPosition, 0),
|
transform: Matrix4.translationValues(0, firstButtonPosition, 0),
|
||||||
child: Opacity(
|
child: Opacity(
|
||||||
opacity: min(1, firstButtonOpacity),
|
opacity: max(min(1, firstButtonOpacity), 0),
|
||||||
child: Text(_addToTrackAnimController.isAnimating && _addToTrackAnim.status == AnimationStatus.forward ? "Done!" : "Track")
|
child: Text(_addToTrackAnimController.isAnimating && _addToTrackAnim.status == AnimationStatus.forward ? "Done!" : "Track")
|
||||||
)
|
)
|
||||||
) : Container(
|
) : Container(
|
||||||
|
@ -2169,17 +2169,18 @@ class FutureError extends StatelessWidget{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FetchResultError extends StatelessWidget{
|
class ErrorThingy extends StatelessWidget{
|
||||||
final FetchResults data;
|
final FetchResults? data;
|
||||||
|
final String? eText;
|
||||||
|
|
||||||
FetchResultError(this.data);
|
ErrorThingy({this.data, this.eText});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
IconData icon = Icons.error_outline;
|
IconData icon = Icons.error_outline;
|
||||||
String errText = "";
|
String errText = eText??"";
|
||||||
String? subText;
|
String? subText;
|
||||||
switch (data.exception.runtimeType){
|
if (data?.exception != null) switch (data!.exception!.runtimeType){
|
||||||
case TetrioPlayerNotExist:
|
case TetrioPlayerNotExist:
|
||||||
icon = Icons.search_off;
|
icon = Icons.search_off;
|
||||||
errText = t.errors.noSuchUser;
|
errText = t.errors.noSuchUser;
|
||||||
|
@ -2190,7 +2191,7 @@ class FetchResultError extends StatelessWidget{
|
||||||
errText = t.errors.discordNotAssigned;
|
errText = t.errors.discordNotAssigned;
|
||||||
subText = t.errors.discordNotAssignedSub;
|
subText = t.errors.discordNotAssignedSub;
|
||||||
case ConnectionIssue:
|
case ConnectionIssue:
|
||||||
var err = data.exception as ConnectionIssue;
|
var err = data!.exception as ConnectionIssue;
|
||||||
errText = t.errors.connection(code: err.code, message: err.message);
|
errText = t.errors.connection(code: err.code, message: err.message);
|
||||||
break;
|
break;
|
||||||
case TetrioForbidden:
|
case TetrioForbidden:
|
||||||
|
@ -2214,7 +2215,7 @@ class FetchResultError extends StatelessWidget{
|
||||||
errText = t.errors.clientException;
|
errText = t.errors.clientException;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errText = data.exception.toString();
|
errText = data!.exception.toString();
|
||||||
}
|
}
|
||||||
return TweenAnimationBuilder(
|
return TweenAnimationBuilder(
|
||||||
duration: Durations.medium3,
|
duration: Durations.medium3,
|
||||||
|
|
Loading…
Reference in New Issue