我正在为车队管理创建一个Flutter应用程序,我有以下课程。
class Journeys extends Table {
IntColumn get journeyId => integer().autoIncrement()();
DateTimeColumn get startTime => dateTime()();
DateTimeColumn get endTime => dateTime()();
RealColumn get risk => real().withDefault(Constant(0.0))();
//RealColumn get totalDistance => real().withDefault(Constant(0.0))();//in meters
}
class RoutePoints extends Table{
IntColumn get routePointId => integer().autoIncrement()();
IntColumn get journeyId => integer()();
RealColumn get latitude => real().withDefault(Constant(0.0))();// Latitude, in degrees
RealColumn get longitude => real().withDefault(Constant(0.0))(); // Longitude, in degrees
RealColumn get accuracy => real().withDefault(Constant(0.0))(); // Estimated horizontal accuracy of this location, radial, in meters
RealColumn get altitude => real().withDefault(Constant(0.0))();// In meters above the WGS 84 reference ellipsoid
RealColumn get speed => real().withDefault(Constant(0.0))(); // In meters/second
RealColumn get heading => real().withDefault(Constant(0.0))(); //Heading is the horizontal direction of travel of this device, in degrees
DateTimeColumn get timeGps => dateTime()(); //timestamp of the LocationData
}
class Calls extends Table {
IntColumn get callId => integer().autoIncrement()();
IntColumn get journeyId => integer()();
TextColumn get type => text().withLength(min: 1, max: 50)();
DateTimeColumn get duration => dateTime()();
}
class Violations extends Table{
IntColumn get violationId => integer().autoIncrement()();
IntColumn get journeyId => integer()();
DateTimeColumn get startTime => dateTime()();
DateTimeColumn get endTime => dateTime()();
TextColumn get type => text().withLength(min: 1, max: 50)();
IntColumn get severity => integer()();
RealColumn get classificationAccuracy => real().withDefault(Constant(0.0))();
}
class JourneyWithDetails{
final Journey journeyDetail;
final List<RoutePoint> routePointsDetail;
final List <Call> callsDetail;
final List <Violation> violationsDetail;
JourneyWithDetails({this.journeyDetail,this.routePointsDetail,this.callsDetail,this.violationsDetail});
}
我想获得所有旅程及其相关细节的信息流。 我已经编写了以下代码,但是需要修改。
// inside the database class:
Stream<List<JourneyWithDetails>> watchAllJourniesWithDetails() {
return (select(journeys)
..orderBy(([
(j) => OrderingTerm(expression: j.journeyId),
])))
.join([leftOuterJoin(routePoints, routePoints.journeyId.equalsExp(journeys.journeyId)),
leftOuterJoin(calls, calls.journeyId.equalsExp(journeys.journeyId)),
leftOuterJoin(violations, violations.journeyId.equalsExp(journeys.journeyId)),
]).watch()
.map((rows) {
// final groupedData = <Journey, List<RoutePoint>>{};
for (final row in rows) {
final journeyDetail= row.readTable(journeys);
final routePointsDetail= row.readTable(routePoints);
final callsDetail=row.readTable(calls);
final violationsDetail=row.readTable(violations);
}
return [
// for (final entry in groupedData.entries)
// CategoryWithTasks(category: entry.key, tasks: entry.value)
];
});
}
我还尝试了以下代码来获取所有旅程的列表,但由于没有语法错误,因为停泊的原因无法将rowResult转换为指定表类型的列表:
Future<List<JourneyWithDetails>> loadJourneysWithDetails() async {
final rows = await select(journeys).join([
innerJoin(routePoints, routePoints.journeyId.equalsExp(journeys.journeyId)),
innerJoin(calls, calls.journeyId.equalsExp(journeys.journeyId)),
innerJoin(violations, violations.journeyId.equalsExp(journeys.journeyId)),
]).get();
return rows.map((resultRow) {
return JourneyWithDetails(
journeyDetail: resultRow.readTable(journeys),
routePointsDetail:resultRow.readTable(routePoints),
callsDetail: resultRow.readTable(calls),
violationsDetail: resultRow.readTable(violations),
);
}).toList();
}
}
此外,我想包含我从API接收到的JSON对象,以便您为我的用例提供最佳实现策略的建议。
Trips:{
“1”:{
“startTime”: "2020-06-22T09:39:39.999Z",
“endTime”: "2020-06-22T09:42:04.999Z",
“risk”: "0.0",
“RoutePoints”:{"2020-06-22T09:39:39.999Z":{"odometer":167.5,"coords":{"latitude":24.2048918,"longitude":55.6783522,"accuracy":3.6,"speed":6.11,"heading":249.64,"altitude":225.3}},"2020-06-22T09:39:40.999Z":{"odometer":173.8,"coords":{"latitude":24.2048717,"longitude":55.6782945,"accuracy":3.5,"speed":6.05,"heading":248.44,"altitude":225.3}},"2020-06-22T09:42:04.999Z":{"odometer":519.2,"coords":{"latitude":24.2055217,"longitude":55.6797709,"accuracy":4.2,"speed":0.87,"heading":109.14,"altitude":223.2}}}
}
“2”:{
“startTime”: "2020-06-22T09:58:22.000Z",
“endTime”: "2020-06-22T10:00:15.472Z",
“risk”: "0.0",
"Calls":{},
"Violations":{},
“RoutePoints”:{"2020-06-22T09:58:22.000Z":{"odometer":918.8,"coords":{"latitude":24.204932,"longitude":55.678551,"accuracy":3.9,"speed":6.15,"heading":251.04,"altitude":220.9}},"2020-06-22T09:58:23.000Z":{"odometer":924.4,"coords":{"latitude":24.2049181,"longitude":55.6784972,"accuracy":3.9,"speed":5.86,"heading":253.78,"altitude":220.9}},"2020-06-22T09:58:24.000Z":{"odometer":930.1,"coords":{"latitude":24.204905,"longitude":55.6784433,"accuracy":3.9,"speed":5.85,"heading":252.26,"altitude":220.9}},"2020-06-22T09:58:25.000Z":{"odometer":935.9,"coords":{"latitude":24.2048893,"longitude":55.678389,"accuracy":3.9,"speed":6.11,"heading":250.51,"altitude":220.9}},"2020-06-22T10:00:15.472Z":{"odometer":1665.6,"coords":{"latitude":24.2054417,"longitude":55.6796837,"accuracy":4.7,"speed":1.07,"heading":14.33,"altitude":223.2}}}
}
}