feat: add map time filtering function and optimized location processing
This commit is contained in:
@@ -319,6 +319,10 @@ class BLEService {
|
||||
'${now.millisecondsSinceEpoch}_${Random().nextInt(9999)}';
|
||||
recordData['receivedTimestamp'] = now.millisecondsSinceEpoch;
|
||||
|
||||
if (!recordData.containsKey('timestamp')) {
|
||||
recordData['timestamp'] = now.millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
_lastReceivedTime = now;
|
||||
_lastReceivedTimeController.add(_lastReceivedTime);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class DatabaseService {
|
||||
DatabaseService._internal();
|
||||
|
||||
static const String _databaseName = 'train_database';
|
||||
static const _databaseVersion = 2;
|
||||
static const _databaseVersion = 4;
|
||||
|
||||
static const String trainRecordsTable = 'train_records';
|
||||
static const String appSettingsTable = 'app_settings';
|
||||
@@ -43,6 +43,17 @@ class DatabaseService {
|
||||
await db.execute(
|
||||
'ALTER TABLE $appSettingsTable ADD COLUMN hideTimeOnlyRecords INTEGER NOT NULL DEFAULT 0');
|
||||
}
|
||||
if (oldVersion < 3) {
|
||||
await db.execute(
|
||||
'ALTER TABLE $appSettingsTable ADD COLUMN mapTimeFilter TEXT NOT NULL DEFAULT "unlimited"');
|
||||
}
|
||||
if (oldVersion < 4) {
|
||||
try {
|
||||
await db.execute(
|
||||
'ALTER TABLE $appSettingsTable ADD COLUMN mapTimeFilter TEXT NOT NULL DEFAULT "unlimited"');
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onCreate(Database db, int version) async {
|
||||
@@ -89,7 +100,8 @@ class DatabaseService {
|
||||
mergeRecordsEnabled INTEGER NOT NULL DEFAULT 0,
|
||||
hideTimeOnlyRecords INTEGER NOT NULL DEFAULT 0,
|
||||
groupBy TEXT NOT NULL DEFAULT 'trainAndLoco',
|
||||
timeWindow TEXT NOT NULL DEFAULT 'unlimited'
|
||||
timeWindow TEXT NOT NULL DEFAULT 'unlimited',
|
||||
mapTimeFilter TEXT NOT NULL DEFAULT 'unlimited'
|
||||
)
|
||||
''');
|
||||
|
||||
@@ -114,6 +126,7 @@ class DatabaseService {
|
||||
'hideTimeOnlyRecords': 0,
|
||||
'groupBy': 'trainAndLoco',
|
||||
'timeWindow': 'unlimited',
|
||||
'mapTimeFilter': 'unlimited',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,6 +148,31 @@ class DatabaseService {
|
||||
return result.map((json) => TrainRecord.fromDatabaseJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<List<TrainRecord>> getRecordsWithinTimeRange(Duration duration) async {
|
||||
final db = await database;
|
||||
final cutoffTime = DateTime.now().subtract(duration).millisecondsSinceEpoch;
|
||||
final result = await db.query(
|
||||
trainRecordsTable,
|
||||
where: 'timestamp >= ?',
|
||||
whereArgs: [cutoffTime],
|
||||
orderBy: 'timestamp DESC',
|
||||
);
|
||||
return result.map((json) => TrainRecord.fromDatabaseJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<List<TrainRecord>> getRecordsWithinReceivedTimeRange(
|
||||
Duration duration) async {
|
||||
final db = await database;
|
||||
final cutoffTime = DateTime.now().subtract(duration).millisecondsSinceEpoch;
|
||||
final result = await db.query(
|
||||
trainRecordsTable,
|
||||
where: 'receivedTimestamp >= ?',
|
||||
whereArgs: [cutoffTime],
|
||||
orderBy: 'receivedTimestamp DESC',
|
||||
);
|
||||
return result.map((json) => TrainRecord.fromDatabaseJson(json)).toList();
|
||||
}
|
||||
|
||||
Future<int> deleteRecord(String uniqueId) async {
|
||||
final db = await database;
|
||||
return await db.delete(
|
||||
|
||||
@@ -142,8 +142,29 @@ class MergeService {
|
||||
}
|
||||
|
||||
if (group.length >= 2) {
|
||||
final firstRecord = group.first;
|
||||
final train = firstRecord.train.trim();
|
||||
final loco = firstRecord.loco.trim();
|
||||
String uniqueGroupKey;
|
||||
|
||||
if (train.isNotEmpty &&
|
||||
train != "<NUL>" &&
|
||||
!train.contains("-----") &&
|
||||
loco.isNotEmpty &&
|
||||
loco != "<NUL>") {
|
||||
uniqueGroupKey = "train_or_loco:${train}_$loco";
|
||||
} else if (train.isNotEmpty &&
|
||||
train != "<NUL>" &&
|
||||
!train.contains("-----")) {
|
||||
uniqueGroupKey = "train_or_loco:train:$train";
|
||||
} else if (loco.isNotEmpty && loco != "<NUL>") {
|
||||
uniqueGroupKey = "train_or_loco:loco:$loco";
|
||||
} else {
|
||||
uniqueGroupKey = "train_or_loco:group_${mergedRecords.length}";
|
||||
}
|
||||
|
||||
mergedRecords.add(MergedTrainRecord(
|
||||
groupKey: "train_or_loco_group",
|
||||
groupKey: uniqueGroupKey,
|
||||
records: group,
|
||||
latestRecord: group.first,
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user