From fd8c1fc16d5bc2e73bcb2c4a6a50c283f38bcbd1 Mon Sep 17 00:00:00 2001 From: dan63047 Date: Sat, 22 Jul 2023 15:07:57 +0300 Subject: [PATCH] small fixes --- README.md | 2 +- lib/views/main_view.dart | 38 +++++++++++++++++++++----------------- pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 38428dc..c189774 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ If you want an app, you can find it [here](https://github.com/dan63047/TetraStat # Available functionality - Advanced stats for players - Rank cutoffs and averages -- Sqlite Database and service, that can work with it +- Sqlite database, that can store all data - Comparison to players, rank averages, and player stats from the past - Stats Calculator - Player history in charts diff --git a/lib/views/main_view.dart b/lib/views/main_view.dart index 79f1a14..3eb4a25 100644 --- a/lib/views/main_view.dart +++ b/lib/views/main_view.dart @@ -81,7 +81,7 @@ class _MainState extends State with SingleTickerProviderStateMixin { @override void initState() { - teto.open(); + initDB(); _scrollController = ScrollController(); _tabController = TabController(length: 6, vsync: this); if (widget.player != null){ @@ -111,6 +111,10 @@ class _MainState extends State with SingleTickerProviderStateMixin { }); } + void initDB() async{ + await teto.open(); + } + Future fetch(String nickOrID, {bool fetchHistory = false}) async { TetrioPlayer me = await teto.fetchPlayer(nickOrID); _searchFor = me.userId; @@ -121,6 +125,22 @@ class _MainState extends State with SingleTickerProviderStateMixin { List states = []; TetraLeagueAlpha? compareWith; var uniqueTL = {}; + if (isTracking){ + await teto.storeState(me); + await teto.saveTLMatchesFromStream(await teto.getTLStream(me.userId)); + tlMatches.addAll(await teto.getTLMatchesbyPlayerID(me.userId)); + for (var match in tlStream.records) { + if (!tlMatches.contains(match)) tlMatches.add(match); + } + tlMatches.sort((a, b) { + if(a.timestamp.isBefore(b.timestamp)) return 1; + if(a.timestamp.isAtSameMomentAs(b.timestamp)) return 0; + if(a.timestamp.isAfter(b.timestamp)) return -1; + return 0; + }); + } else{ + tlMatches = tlStream.records; + } if(fetchHistory) await teto.fetchAndsaveTLHistory(_searchFor); states.addAll(await teto.getPlayer(me.userId)); for (var element in states) { @@ -151,22 +171,6 @@ class _MainState extends State with SingleTickerProviderStateMixin { DropdownMenuItem(value: [for (var tl in uniqueTL) if (tl.estTr != null) FlSpot(tl.timestamp.millisecondsSinceEpoch.toDouble(), tl.estTr!.esttr)], child: Text(t.statCellNum.estOfTR.replaceAll(RegExp(r'\n'), " "))), DropdownMenuItem(value: [for (var tl in uniqueTL) if (tl.esttracc != null) FlSpot(tl.timestamp.millisecondsSinceEpoch.toDouble(), tl.esttracc!)], child: Text(t.statCellNum.accOfEst.replaceAll(RegExp(r'\n'), " "))), ]; - if (isTracking){ - await teto.storeState(me); - await teto.saveTLMatchesFromStream(await teto.getTLStream(me.userId)); - tlMatches.addAll(await teto.getTLMatchesbyPlayerID(me.userId)); - for (var match in tlStream.records) { - if (!tlMatches.contains(match)) tlMatches.add(match); - } - tlMatches.sort((a, b) { - if(a.timestamp.isBefore(b.timestamp)) return 1; - if(a.timestamp.isAtSameMomentAs(b.timestamp)) return 0; - if(a.timestamp.isAfter(b.timestamp)) return -1; - return 0; - }); - } else{ - tlMatches = tlStream.records; - } Map records = await teto.fetchRecords(me.userId); return [me, records, states, tlMatches, compareWith, isTracking]; } diff --git a/pubspec.yaml b/pubspec.yaml index 9e168fd..cf7078e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: tetra_stats description: Track your and other player stats in TETR.IO publish_to: 'none' -version: 1.0.0+5 +version: 1.0.1+6 environment: sdk: '>=2.19.6 <3.0.0'