2024-04-29 22:45:11 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2024-04-20 22:37:31 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:syncfusion_flutter_gauges/gauges.dart';
|
2024-05-01 23:12:52 +00:00
|
|
|
import 'package:tetra_stats/data_objects/glicko.dart';
|
2024-04-20 22:37:31 +00:00
|
|
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
2024-04-29 22:45:11 +00:00
|
|
|
import 'package:tetra_stats/utils/numers_formats.dart';
|
2024-04-20 22:37:31 +00:00
|
|
|
|
|
|
|
class TLProgress extends StatelessWidget{
|
2024-08-16 22:40:09 +00:00
|
|
|
final TetraLeague tlData;
|
2024-04-20 22:37:31 +00:00
|
|
|
final double? nextRankTRcutoff;
|
|
|
|
final double? previousRankTRcutoff;
|
2024-05-01 23:12:52 +00:00
|
|
|
final double? nextRankGlickoCutoff;
|
|
|
|
final double? previousGlickoCutoff;
|
2024-04-20 22:37:31 +00:00
|
|
|
final double? nextRankTRcutoffTarget;
|
|
|
|
final double? previousRankTRcutoffTarget;
|
|
|
|
|
2024-08-06 22:24:31 +00:00
|
|
|
const TLProgress({super.key, required this.tlData, this.nextRankTRcutoff, this.previousRankTRcutoff, this.nextRankGlickoCutoff, this.previousGlickoCutoff, this.nextRankTRcutoffTarget, this.previousRankTRcutoffTarget});
|
2024-04-20 22:37:31 +00:00
|
|
|
|
|
|
|
double getBarPosition(){
|
2024-05-01 23:12:52 +00:00
|
|
|
return min(max(0, 1 - (tlData.standing - tlData.nextAt)/(tlData.prevAt - tlData.nextAt)), 1);
|
2024-04-20 22:37:31 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 22:45:11 +00:00
|
|
|
double? getBarTR(double tr){
|
|
|
|
return min(max(0, (tr - previousRankTRcutoff!)/(nextRankTRcutoff! - previousRankTRcutoff!)), 1);
|
2024-04-20 22:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-08-06 22:24:31 +00:00
|
|
|
if (tlData.prevAt < 0 && tlData.nextAt < 0 && nextRankTRcutoff == null && previousRankTRcutoff == null && nextRankGlickoCutoff == null && previousGlickoCutoff == null && nextRankTRcutoffTarget == null && previousRankTRcutoffTarget == null) return Container();
|
2024-05-01 23:12:52 +00:00
|
|
|
final glickoForWin = rate(tlData.glicko!, tlData.rd!, 0.06, [[tlData.glicko!, tlData.rd!, 1]], {})[0]-tlData.glicko!;
|
2024-04-20 22:37:31 +00:00
|
|
|
return Padding(
|
2024-05-02 22:26:12 +00:00
|
|
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
|
2024-05-01 23:12:52 +00:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2024-08-06 22:24:31 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
RichText(
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
text: TextSpan(
|
|
|
|
style: const TextStyle(color: Colors.white, fontFamily: "Eurostile Round", fontSize: 12),
|
|
|
|
children: [
|
|
|
|
if (tlData.prevAt > 0) TextSpan(text: "№ ${f0.format(tlData.prevAt)}"),
|
|
|
|
if (tlData.prevAt > 0 && previousRankTRcutoff != null) const TextSpan(text: "\n"),
|
2024-08-16 22:40:09 +00:00
|
|
|
if (previousRankTRcutoff != null) TextSpan(text: "${f2.format(previousRankTRcutoff)} (${comparef2.format(previousRankTRcutoff!-tlData.tr)}) TR"),
|
2024-08-06 22:24:31 +00:00
|
|
|
if ((tlData.prevAt > 0 || previousRankTRcutoff != null) && previousGlickoCutoff != null) const TextSpan(text: "\n"),
|
|
|
|
if (previousGlickoCutoff != null) TextSpan(text: (tlData.standing > tlData.prevAt || ((tlData.glicko!-previousGlickoCutoff!)/glickoForWin < 0.5 && tlData.percentileRank != "d")) ? t.demotionOnNextLoss : t.numOfdefeats(losses: f2.format((tlData.glicko!-previousGlickoCutoff!)/glickoForWin)), style: TextStyle(color: (tlData.standing > tlData.prevAt || ((tlData.glicko!-previousGlickoCutoff!)/glickoForWin < 0.5 && tlData.percentileRank != "d")) ? Colors.redAccent : null))
|
|
|
|
]
|
|
|
|
)
|
2024-05-02 22:26:12 +00:00
|
|
|
),
|
2024-09-01 21:44:19 +00:00
|
|
|
const Spacer(),
|
2024-08-06 22:24:31 +00:00
|
|
|
RichText(
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
text: TextSpan(
|
|
|
|
style: const TextStyle(color: Colors.white, fontFamily: "Eurostile Round", fontSize: 12),
|
|
|
|
children: [
|
|
|
|
if (tlData.nextAt > 0) TextSpan(text: "№ ${f0.format(tlData.nextAt)}"),
|
|
|
|
if (tlData.nextAt > 0 && nextRankTRcutoff != null) const TextSpan(text: "\n"),
|
2024-08-16 22:40:09 +00:00
|
|
|
if (nextRankTRcutoff != null) TextSpan(text: "${f2.format(nextRankTRcutoff)} (${comparef2.format(nextRankTRcutoff!-tlData.tr)}) TR"),
|
2024-08-06 22:24:31 +00:00
|
|
|
if ((tlData.nextAt > 0 || nextRankTRcutoff != null) && nextRankGlickoCutoff != null) const TextSpan(text: "\n"),
|
2024-08-17 23:39:20 +00:00
|
|
|
if (nextRankGlickoCutoff != null) TextSpan(text: (tlData.standing < tlData.nextAt || ((nextRankGlickoCutoff!-tlData.glicko!)/glickoForWin < 0.5 && ((tlData.rank != "x+" && tlData.rank != "z") || tlData.percentileRank != "x+"))) ? t.promotionOnNextWin : t.numOfVictories(wins: f2.format((nextRankGlickoCutoff!-tlData.glicko!)/glickoForWin)), style: TextStyle(color: (tlData.standing < tlData.nextAt || ((nextRankGlickoCutoff!-tlData.glicko!)/glickoForWin < 0.5 && tlData.percentileRank != "x+")) ? Colors.greenAccent : null))
|
2024-08-06 22:24:31 +00:00
|
|
|
]
|
|
|
|
)
|
2024-05-02 22:26:12 +00:00
|
|
|
)
|
2024-08-06 22:24:31 +00:00
|
|
|
],
|
2024-05-02 22:26:12 +00:00
|
|
|
),
|
2024-05-01 23:12:52 +00:00
|
|
|
SfLinearGauge(
|
|
|
|
minimum: 0,
|
|
|
|
maximum: 1,
|
|
|
|
interval: 1,
|
|
|
|
ranges: [
|
2024-08-16 22:40:09 +00:00
|
|
|
if (previousRankTRcutoff != null && nextRankTRcutoff != null) LinearGaugeRange(endValue: getBarTR(tlData.tr)!, color: Theme.of(context).colorScheme.primary, position: LinearElementPosition.cross)
|
2024-06-15 22:49:57 +00:00
|
|
|
else if (tlData.standing != -1) LinearGaugeRange(endValue: getBarPosition(), color: Theme.of(context).colorScheme.primary, position: LinearElementPosition.cross),
|
2024-05-01 23:12:52 +00:00
|
|
|
if (previousRankTRcutoff != null && previousRankTRcutoffTarget != null) LinearGaugeRange(endValue: getBarTR(previousRankTRcutoffTarget!)!, color: Colors.greenAccent, position: LinearElementPosition.inside),
|
2024-05-04 20:04:48 +00:00
|
|
|
if (nextRankTRcutoff != null && nextRankTRcutoffTarget != null && previousRankTRcutoff != null) LinearGaugeRange(startValue: getBarTR(nextRankTRcutoffTarget!)!, endValue: 1, color: Colors.yellowAccent, position: LinearElementPosition.inside)
|
2024-05-01 23:12:52 +00:00
|
|
|
],
|
|
|
|
markerPointers: [
|
2024-08-16 22:40:09 +00:00
|
|
|
LinearShapePointer(value: (previousRankTRcutoff != null && nextRankTRcutoff != null) ? getBarTR(tlData.tr)! : getBarPosition(), position: LinearElementPosition.cross, shapeType: LinearShapePointerType.diamond, color: Colors.white, height: 20),
|
|
|
|
if (tlData.standing != -1) LinearWidgetPointer(offset: 4, position: LinearElementPosition.outside, value: (previousRankTRcutoff != null && nextRankTRcutoff != null) ? getBarTR(tlData.tr)! : getBarPosition(), child: Text("№ ${NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: 0).format(tlData.standing)}", style: const TextStyle(fontSize: 14),))
|
2024-05-01 23:12:52 +00:00
|
|
|
],
|
|
|
|
isMirrored: true,
|
|
|
|
showTicks: true,
|
2024-05-02 22:26:12 +00:00
|
|
|
showLabels: false
|
2024-05-01 23:12:52 +00:00
|
|
|
)
|
2024-05-02 22:26:12 +00:00
|
|
|
]
|
|
|
|
),
|
2024-04-20 22:37:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|