TL matches list bugfix

This commit is contained in:
dan63047 2024-02-01 17:38:11 +03:00
parent 97f5e95da3
commit 08ccf7f159
3 changed files with 8 additions and 7 deletions

View File

@ -228,7 +228,8 @@ class TetrioService extends DB {
saveReplayStats(data); // saving to DB for later saveReplayStats(data); // saving to DB for later
return data; return data;
} }
/// Gets and returns Top TR as a double for a player with given [id]. May return null if player top tr is unknown
/// Gets and returns Top TR for a player with given [id]. May return null if player top tr is unknown
/// or api is unavaliable (404). May throw an exception, if something else happens. /// or api is unavaliable (404). May throw an exception, if something else happens.
Future<double?> fetchTopTR(String id) async { Future<double?> fetchTopTR(String id) async {
try{ // read from cache try{ // read from cache
@ -287,7 +288,7 @@ class TetrioService extends DB {
// so i'm going to document only unique differences between them // so i'm going to document only unique differences between them
/// Retrieves Tetra League history from p1nkl0bst3r api for a player with given [id]. Returns a list of states /// Retrieves Tetra League history from p1nkl0bst3r api for a player with given [id]. Returns a list of states
/// (state = instance of player stats at some point of time). Can throw an exception if fails to retrieve data. /// (state = instance of [TetrioPlayer] at some point of time). Can throw an exception if fails to retrieve data.
Future<List<TetrioPlayer>> fetchAndsaveTLHistory(String id) async { Future<List<TetrioPlayer>> fetchAndsaveTLHistory(String id) async {
Uri url; Uri url;
if (kIsWeb) { if (kIsWeb) {
@ -835,7 +836,6 @@ class TetrioService extends DB {
} }
} }
/// Retrieves general stats of [user] (nickname or id) from Tetra Channel api. Returns [TetrioPlayer] object of this user. /// Retrieves general stats of [user] (nickname or id) from Tetra Channel api. Returns [TetrioPlayer] object of this user.
/// If [isItDiscordID] is true, function expects [user] to be a discord user id. Throws an exception if fails to retrieve. /// If [isItDiscordID] is true, function expects [user] to be a discord user id. Throws an exception if fails to retrieve.
Future<TetrioPlayer> fetchPlayer(String user, {bool isItDiscordID = false}) async { Future<TetrioPlayer> fetchPlayer(String user, {bool isItDiscordID = false}) async {

View File

@ -173,10 +173,13 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
TetraLeagueAlpha? compareWith; TetraLeagueAlpha? compareWith;
Set<TetraLeagueAlpha> uniqueTL = {}; Set<TetraLeagueAlpha> uniqueTL = {};
tlMatches = tlStream.records; tlMatches = tlStream.records;
var storedRecords = await teto.getTLMatchesbyPlayerID(me.userId); // get old matches
if (isTracking){ // if tracked - save data to local DB if (isTracking){ // if tracked - save data to local DB
await teto.storeState(me); await teto.storeState(me);
await teto.saveTLMatchesFromStream(tlStream); await teto.saveTLMatchesFromStream(tlStream);
var storedRecords = await teto.getTLMatchesbyPlayerID(me.userId); // get old matches }
// building list of TL matches
for (var match in storedRecords) { for (var match in storedRecords) {
// add stored match to list only if it missing from retrived ones // add stored match to list only if it missing from retrived ones
if (!tlMatches.contains(match)) tlMatches.add(match); if (!tlMatches.contains(match)) tlMatches.add(match);
@ -186,8 +189,7 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
if(a.timestamp.isAtSameMomentAs(b.timestamp)) return 0; if(a.timestamp.isAtSameMomentAs(b.timestamp)) return 0;
if(a.timestamp.isAfter(b.timestamp)) return -1; if(a.timestamp.isAfter(b.timestamp)) return -1;
return 0; return 0;
}); });
}
// Handling history // Handling history
if(fetchHistory) await teto.fetchAndsaveTLHistory(_searchFor); // Retrieve if needed if(fetchHistory) await teto.fetchAndsaveTLHistory(_searchFor); // Retrieve if needed

View File

@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart'; import 'package:syncfusion_flutter_gauges/gauges.dart';