ok that works faster but i still need some tests
This commit is contained in:
parent
38ec643a01
commit
9ed6ddb33d
|
@ -1375,7 +1375,11 @@ class TetraLeague {
|
||||||
apm = json['apm']?.toDouble();
|
apm = json['apm']?.toDouble();
|
||||||
pps = json['pps']?.toDouble();
|
pps = json['pps']?.toDouble();
|
||||||
vs = json['vs']?.toDouble();
|
vs = json['vs']?.toDouble();
|
||||||
decaying = json['decaying'] ?? false;
|
decaying = switch(json['decaying'].runtimeType){
|
||||||
|
int => json['decaying'] == 1,
|
||||||
|
bool => json['decaying'],
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
standing = json['standing'] ?? -1;
|
standing = json['standing'] ?? -1;
|
||||||
percentile = json['percentile'] != null ? json['percentile'].toDouble() : rankCutoffs[rank];
|
percentile = json['percentile'] != null ? json['percentile'].toDouble() : rankCutoffs[rank];
|
||||||
standingLocal = json['standing_local'] ?? -1;
|
standingLocal = json['standing_local'] ?? -1;
|
||||||
|
@ -1402,8 +1406,7 @@ class TetraLeague {
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
data['id'] = id;
|
data['id'] = id+timestamp.millisecondsSinceEpoch.toRadixString(16);
|
||||||
data['timestamp'] = timestamp.millisecondsSinceEpoch;
|
|
||||||
if (gamesPlayed > 0) data['gamesplayed'] = gamesPlayed;
|
if (gamesPlayed > 0) data['gamesplayed'] = gamesPlayed;
|
||||||
if (gamesWon > 0) data['gameswon'] = gamesWon;
|
if (gamesWon > 0) data['gameswon'] = gamesWon;
|
||||||
if (tr >= 0) data['tr'] = tr;
|
if (tr >= 0) data['tr'] = tr;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'dart:developer' as developer;
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:sqflite/sql.dart';
|
import 'package:sqflite/sql.dart';
|
||||||
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||||
import 'package:tetra_stats/data_objects/tetra_stats.dart';
|
import 'package:tetra_stats/data_objects/tetra_stats.dart';
|
||||||
import 'package:tetra_stats/data_objects/tetrio_multiplayer_replay.dart';
|
import 'package:tetra_stats/data_objects/tetrio_multiplayer_replay.dart';
|
||||||
import 'package:tetra_stats/main.dart' show packageInfo;
|
import 'package:tetra_stats/main.dart' show packageInfo;
|
||||||
|
@ -72,7 +73,6 @@ const String createTetrioTLReplayStats = '''
|
||||||
const String createTetrioLeagueTable = '''
|
const String createTetrioLeagueTable = '''
|
||||||
CREATE TABLE IF NOT EXISTS "tetrioLeague" (
|
CREATE TABLE IF NOT EXISTS "tetrioLeague" (
|
||||||
"id" TEXT NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
"timestamp" INTEGER NOT NULL,
|
|
||||||
"gamesplayed" INTEGER NOT NULL DEFAULT 0,
|
"gamesplayed" INTEGER NOT NULL DEFAULT 0,
|
||||||
"gameswon" INTEGER NOT NULL DEFAULT 0,
|
"gameswon" INTEGER NOT NULL DEFAULT 0,
|
||||||
"tr" REAL,
|
"tr" REAL,
|
||||||
|
@ -93,7 +93,8 @@ const String createTetrioLeagueTable = '''
|
||||||
"next_rank" TEXT,
|
"next_rank" TEXT,
|
||||||
"next_at" INTEGER NOT NULL DEFAULT -1,
|
"next_at" INTEGER NOT NULL DEFAULT -1,
|
||||||
"percentile_rank" TEXT NOT NULL DEFAULT 'z',
|
"percentile_rank" TEXT NOT NULL DEFAULT 'z',
|
||||||
"season" INTEGER NOT NULL DEFAULT 1
|
"season" INTEGER NOT NULL DEFAULT 1,
|
||||||
|
PRIMARY KEY("id")
|
||||||
)
|
)
|
||||||
''';
|
''';
|
||||||
|
|
||||||
|
@ -592,6 +593,7 @@ class TetrioService extends DB {
|
||||||
// that one api returns csv instead of json
|
// that one api returns csv instead of json
|
||||||
List<List<dynamic>> csv = const CsvToListConverter().convert(response.body)..removeAt(0);
|
List<List<dynamic>> csv = const CsvToListConverter().convert(response.body)..removeAt(0);
|
||||||
List<TetraLeague> history = [];
|
List<TetraLeague> history = [];
|
||||||
|
Batch batch = db.batch();
|
||||||
for (List<dynamic> entry in csv){ // each entry is one state
|
for (List<dynamic> entry in csv){ // each entry is one state
|
||||||
TetraLeague state = TetraLeague(
|
TetraLeague state = TetraLeague(
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -617,8 +619,9 @@ class TetrioService extends DB {
|
||||||
season: 1
|
season: 1
|
||||||
);
|
);
|
||||||
history.add(state);
|
history.add(state);
|
||||||
await db.insert(tetrioLeagueTable, state.toJson(), conflictAlgorithm: ConflictAlgorithm.replace);
|
batch.insert(tetrioLeagueTable, state.toJson(), conflictAlgorithm: ConflictAlgorithm.replace);
|
||||||
}
|
}
|
||||||
|
batch.commit();
|
||||||
return history;
|
return history;
|
||||||
case 404:
|
case 404:
|
||||||
developer.log("fetchTLHistory: Probably, history doesn't exist", name: "services/tetrio_crud", error: response.statusCode);
|
developer.log("fetchTLHistory: Probably, history doesn't exist", name: "services/tetrio_crud", error: response.statusCode);
|
||||||
|
@ -1112,12 +1115,20 @@ class TetrioService extends DB {
|
||||||
Future<void> storeState(TetraLeague league) async {
|
Future<void> storeState(TetraLeague league) async {
|
||||||
await ensureDbIsOpen();
|
await ensureDbIsOpen();
|
||||||
final db = getDatabaseOrThrow();
|
final db = getDatabaseOrThrow();
|
||||||
List<Map> test = await db.query(tetrioLeagueTable, where: '"id" = ? AND "gamesplayed" = ? AND "rd" = ?', whereArgs: [league.id, league.gamesPlayed, league.rd]);
|
List<Map> test = await db.query(tetrioLeagueTable, where: '"id" LIKE ? AND "gamesplayed" = ? AND "rd" = ?', whereArgs: ["${league.id}%", league.gamesPlayed, league.rd]);
|
||||||
if (test.isEmpty) {
|
if (test.isEmpty) {
|
||||||
await db.insert(tetrioLeagueTable, league.toJson());
|
await db.insert(tetrioLeagueTable, league.toJson());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<TetraLeague>> getHistory(String id, {int season = currentSeason}) async {
|
||||||
|
await ensureDbIsOpen();
|
||||||
|
final db = getDatabaseOrThrow();
|
||||||
|
List<Map> raw = await db.query(tetrioLeagueTable, where: '"id" = ? AND "season" = ?', whereArgs: [id, season]);
|
||||||
|
List<TetraLeague> result = [for (var entry in raw) TetraLeague.fromJson(entry as Map<String, dynamic>, DateTime.fromMillisecondsSinceEpoch(int.parse(entry["id"].substring(24), radix: 16)), entry["season"], entry["id"].substring(0, 24))];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// Remove state (which is [tetrioPlayer]) from the local database
|
/// Remove state (which is [tetrioPlayer]) from the local database
|
||||||
// Future<void> deleteState(TetrioPlayer tetrioPlayer) async {
|
// Future<void> deleteState(TetrioPlayer tetrioPlayer) async {
|
||||||
// await ensureDbIsOpen();
|
// await ensureDbIsOpen();
|
||||||
|
|
|
@ -217,7 +217,7 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
|
|
||||||
// Making list of Tetra League matches
|
// Making list of Tetra League matches
|
||||||
bool isTracking = await teto.isPlayerTracking(me.userId);
|
bool isTracking = await teto.isPlayerTracking(me.userId);
|
||||||
List<TetrioPlayer> states = [];
|
List<TetraLeague> states = await teto.getHistory(me.userId);
|
||||||
TetraLeague? compareWith;
|
TetraLeague? compareWith;
|
||||||
Set<TetraLeague> uniqueTL = {};
|
Set<TetraLeague> uniqueTL = {};
|
||||||
List<TetraLeagueAlphaRecord> storedRecords = await teto.getTLMatchesbyPlayerID(me.userId); // get old matches
|
List<TetraLeagueAlphaRecord> storedRecords = await teto.getTLMatchesbyPlayerID(me.userId); // get old matches
|
||||||
|
@ -277,8 +277,8 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
// if (uniqueTL.isEmpty) uniqueTL.add(summaries.league);
|
// if (uniqueTL.isEmpty) uniqueTL.add(summaries.league);
|
||||||
// }
|
// }
|
||||||
// Also i need previous Tetra League State for comparison if avaliable
|
// Also i need previous Tetra League State for comparison if avaliable
|
||||||
if (uniqueTL.length >= 2){
|
if (states.length >= 2){
|
||||||
compareWith = uniqueTL.toList().elementAtOrNull(uniqueTL.length - 2);
|
compareWith = states.elementAtOrNull(states.length - 2);
|
||||||
chartsData = <DropdownMenuItem<List<_HistoryChartSpot>>>[ // Dumping charts data into dropdown menu items, while cheking if every entry is valid
|
chartsData = <DropdownMenuItem<List<_HistoryChartSpot>>>[ // Dumping charts data into dropdown menu items, while cheking if every entry is valid
|
||||||
DropdownMenuItem(value: [for (var tl in uniqueTL) if (tl.gamesPlayed > 9) _HistoryChartSpot(tl.timestamp, tl.gamesPlayed, tl.rank, tl.tr)], child: Text(t.statCellNum.tr)),
|
DropdownMenuItem(value: [for (var tl in uniqueTL) if (tl.gamesPlayed > 9) _HistoryChartSpot(tl.timestamp, tl.gamesPlayed, tl.rank, tl.tr)], child: Text(t.statCellNum.tr)),
|
||||||
DropdownMenuItem(value: [for (var tl in uniqueTL) if (tl.gamesPlayed > 9) _HistoryChartSpot(tl.timestamp, tl.gamesPlayed, tl.rank, tl.glicko!)], child: const Text("Glicko")),
|
DropdownMenuItem(value: [for (var tl in uniqueTL) if (tl.gamesPlayed > 9) _HistoryChartSpot(tl.timestamp, tl.gamesPlayed, tl.rank, tl.glicko!)], child: const Text("Glicko")),
|
||||||
|
@ -312,7 +312,7 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
changePlayer(me.userId);
|
changePlayer(me.userId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return [me, summaries, news, tlStream, recentZenith, recentZenithEX];
|
return [me, summaries, news, tlStream, recentZenith, recentZenithEX, states];
|
||||||
//return [me, records, states, tlMatches, compareWith, isTracking, news, topTR, recent, sprint, blitz, tlMatches.elementAtOrNull(0)?.timestamp];
|
//return [me, records, states, tlMatches, compareWith, isTracking, news, topTR, recent, sprint, blitz, tlMatches.elementAtOrNull(0)?.timestamp];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
child: TLThingy(
|
child: TLThingy(
|
||||||
tl: snapshot.data![1].league,
|
tl: snapshot.data![1].league,
|
||||||
userID: snapshot.data![0].userId,
|
userID: snapshot.data![0].userId,
|
||||||
states: const [], //snapshot.data![2],
|
states: snapshot.data![6],
|
||||||
//topTR: snapshot.data![7]?.tr,
|
//topTR: snapshot.data![7]?.tr,
|
||||||
//lastMatchPlayed: snapshot.data![11],
|
//lastMatchPlayed: snapshot.data![11],
|
||||||
bot: snapshot.data![0].role == "bot",
|
bot: snapshot.data![0].role == "bot",
|
||||||
|
|
Loading…
Reference in New Issue