From 8d7bccfac0ae6ad236b26d982305b95b3c7ac143 Mon Sep 17 00:00:00 2001 From: dan63047 Date: Tue, 17 Sep 2024 01:37:25 +0300 Subject: [PATCH] Trying to do cutoffs --- lib/data_objects/cutoff_tetrio.dart | 24 +++++-- lib/views/main_view_tiles.dart | 97 +++++++++++++++++++++++++++-- lib/views/ranks_averages_view.dart | 8 +-- 3 files changed, 115 insertions(+), 14 deletions(-) diff --git a/lib/data_objects/cutoff_tetrio.dart b/lib/data_objects/cutoff_tetrio.dart index 586192a..da51e00 100644 --- a/lib/data_objects/cutoff_tetrio.dart +++ b/lib/data_objects/cutoff_tetrio.dart @@ -5,20 +5,32 @@ class CutoffTetrio { late double percentile; late double tr; late double targetTr; - late double apm; - late double pps; - late double vs; + late double? apm; + late double? pps; + late double? vs; late int count; late double countPercentile; + CutoffTetrio({ + required this.pos, + required this.percentile, + required this.tr, + required this.targetTr, + required this.apm, + required this.pps, + required this.vs, + required this.count, + required this.countPercentile + }); + CutoffTetrio.fromJson(Map json, int total){ pos = json['pos']; percentile = json['percentile'].toDouble(); tr = json['tr'].toDouble(); targetTr = json['targettr'].toDouble(); - apm = json['apm'].toDouble(); - pps = json['pps'].toDouble(); - vs = json['vs'].toDouble(); + apm = json['apm']?.toDouble(); + pps = json['pps']?.toDouble(); + vs = json['vs']?.toDouble(); count = json['count']; countPercentile = count / total; } diff --git a/lib/views/main_view_tiles.dart b/lib/views/main_view_tiles.dart index 578473c..704bc05 100644 --- a/lib/views/main_view_tiles.dart +++ b/lib/views/main_view_tiles.dart @@ -10,6 +10,7 @@ import 'package:syncfusion_flutter_charts/charts.dart'; import 'package:syncfusion_flutter_gauges/gauges.dart'; import 'package:tetra_stats/data_objects/badge.dart'; import 'package:tetra_stats/data_objects/beta_record.dart'; +import 'package:tetra_stats/data_objects/cutoff_tetrio.dart'; import 'package:tetra_stats/data_objects/distinguishment.dart'; import 'package:tetra_stats/data_objects/est_tr.dart'; import 'package:tetra_stats/data_objects/nerd_stats.dart'; @@ -210,6 +211,14 @@ class _MainState extends State with TickerProviderStateMixin { } } +class FetchCutoffsResults{ + late bool success; + CutoffsTetrio? cutoffs; + Exception? exception; + + FetchCutoffsResults(this.success, this.cutoffs, this.exception); +} + class DestinationCutoffs extends StatefulWidget{ final BoxConstraints constraints; @@ -220,12 +229,92 @@ class DestinationCutoffs extends StatefulWidget{ } class _DestinationCutoffsState extends State { + + Future fetch() async { + TetrioPlayerFromLeaderboard top1; + CutoffsTetrio cutoffs; + List requests = await Future.wait([ + teto.fetchCutoffsTetrio(), + teto.fetchTopOneFromTheLeaderboard(), + ]); + cutoffs = requests[0]; + top1 = requests[1]; + cutoffs.data["top1"] = CutoffTetrio( + pos: 1, + percentile: 0.00, + tr: top1.tr, + targetTr: 25000, + apm: top1.apm, + pps: top1.pps, + vs: top1.vs, + count: 1, + countPercentile: 0.0 + ); + return cutoffs; + } + @override Widget build(BuildContext context) { - return Column( - children: [ - Card(), - ] + return FutureBuilder( + future: fetch(), + builder: (context, snapshot) { + switch (snapshot.connectionState){ + case ConnectionState.none: + case ConnectionState.waiting: + return const Center(child: CircularProgressIndicator()); + case ConnectionState.active: + case ConnectionState.done: + if (snapshot.hasData){ + return Column( + children: [ + Card( + child: Center(child: Text("Tetra League State")), + ), + Card( + child: Padding( + padding: const EdgeInsets.fromLTRB(20.0, 8.0, 20.0, 8.0), + child: SfLinearGauge( + minimum: 0.00000000, + maximum: 25000.0000, + showTicks: false, + showLabels: false, + ranges: [ + for (var cutoff in snapshot.data!.data.keys) LinearGaugeRange( + position: LinearElementPosition.outside, + startValue: snapshot.data!.data[cutoff]!.tr, + startWidth: 20.0, + endWidth: 20.0, + endValue: switch (cutoff){ + "top1" => 25000.00, + "x+" => snapshot.data!.data["top1"]!.tr, + _ => snapshot.data!.data[ranks[ranks.indexOf(cutoff)+1]]!.tr + }, + color: cutoff != "top1" ? rankColors[cutoff] : null, + //shaderCallback: (bounds) { + // make shader blyat + // }, + ), + for (var cutoff in snapshot.data!.data.keys) LinearGaugeRange( + position: LinearElementPosition.inside, + startValue: snapshot.data!.data[cutoff]!.targetTr, + endValue: switch (cutoff){ + "top1" => 25000.00, + "x+" => snapshot.data!.data["top1"]!.targetTr, + _ => snapshot.data!.data[ranks[ranks.indexOf(cutoff)+1]]!.targetTr + }, + color: cutoff != "top1" ? rankColors[cutoff] : null, + ) + ], + ), + ), + ), + ] + ); + } + if (snapshot.hasError){ return FutureError(snapshot); } + } + return Text("huh?"); + } ); } } diff --git a/lib/views/ranks_averages_view.dart b/lib/views/ranks_averages_view.dart index cd10535..a368d35 100644 --- a/lib/views/ranks_averages_view.dart +++ b/lib/views/ranks_averages_view.dart @@ -114,19 +114,19 @@ class RanksAverages extends State { ), Padding( padding: const EdgeInsets.only(right: 8.0), - child: Text(f2.format(snapshot.data!.data[rank]!.apm), textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: Colors.white, shadows: textShadow)), + child: Text(snapshot.data?.data[rank]?.apm != null ? f2.format(snapshot.data!.data[rank]!.apm) : "-.--", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.apm != null ? Colors.white : Colors.grey, shadows: textShadow)), ), Padding( padding: const EdgeInsets.only(right: 8.0), - child: Text(f2.format(snapshot.data!.data[rank]!.pps), textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: Colors.white, shadows: textShadow)), + child: Text(snapshot.data?.data[rank]?.pps != null ? f2.format(snapshot.data!.data[rank]!.pps) : "-.--", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.pps != null ? Colors.white : Colors.grey, shadows: textShadow)), ), Padding( padding: const EdgeInsets.only(right: 8.0), - child: Text(f2.format(snapshot.data!.data[rank]!.vs), textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: Colors.white, shadows: textShadow)), + child: Text(snapshot.data?.data[rank]?.vs != null ? f2.format(snapshot.data!.data[rank]!.vs) : "-.--", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.vs != null ? Colors.white : Colors.grey, shadows: textShadow)), ), Padding( padding: const EdgeInsets.only(right: 8.0), - child: Text("${f3.format(snapshot.data!.data[rank]!.apm / (snapshot.data!.data[rank]!.pps * 60))} APP\n${f3.format(snapshot.data!.data[rank]!.vs / snapshot.data!.data[rank]!.apm)} VS/APM", textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100, color: Colors.white, shadows: textShadow)), + child: Text("${snapshot.data?.data[rank]?.apm != null && snapshot.data?.data[rank]?.pps != null ? f3.format(snapshot.data!.data[rank]!.apm! / (snapshot.data!.data[rank]!.pps! * 60)) : "-.---"} APP\n${snapshot.data?.data[rank]?.apm != null && snapshot.data?.data[rank]?.vs != null ? f3.format(snapshot.data!.data[rank]!.vs! / snapshot.data!.data[rank]!.apm!) : "-.---"} VS/APM", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.apm != null && snapshot.data?.data[rank]?.pps != null && snapshot.data?.data[rank]?.vs != null ? Colors.white : Colors.grey, shadows: textShadow)), ), Padding( padding: const EdgeInsets.only(right: 8.0),