25-6-13/1
This commit is contained in:
@@ -19,9 +19,14 @@ class DbSql {
|
||||
String path = join(await getDatabasesPath(), 'my_database.db');
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: 1,
|
||||
onCreate: (db, version) async {
|
||||
await db.execute('''
|
||||
version: 3,
|
||||
onCreate: (db, version) async => await _createTables(db),
|
||||
onUpgrade: (db, oldVersion, newVersion) async => await _createTables(db),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _createTables(Database db) async {
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.carLocations}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
driver_id TEXT,
|
||||
@@ -31,7 +36,7 @@ class DbSql {
|
||||
updated_at TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.placesFavorite}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
latitude REAL,
|
||||
@@ -40,7 +45,7 @@ class DbSql {
|
||||
rate TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.recentLocations}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
latitude REAL,
|
||||
@@ -49,7 +54,7 @@ class DbSql {
|
||||
rate TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.driverOrdersRefuse}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
order_id TEXT UNIQUE,
|
||||
@@ -57,7 +62,7 @@ class DbSql {
|
||||
driver_id TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.rideLocation}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
order_id TEXT ,
|
||||
@@ -66,29 +71,31 @@ class DbSql {
|
||||
lng TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.faceDetectTimes}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
faceDetectTimes INTEGER
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.behavior}(
|
||||
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.behavior} (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
speed REAL,
|
||||
lat REAL,
|
||||
lng REAL,
|
||||
driver_id TEXT,
|
||||
latitude REAL,
|
||||
longitude REAL,
|
||||
acceleration REAL,
|
||||
timestamp TEXT
|
||||
)
|
||||
created_at TEXT,
|
||||
updated_at TEXT
|
||||
);
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.captainNotification}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
faceDetectTimes INTEGER
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.applyRideFromOverLay}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
start_location_lat TEXT,
|
||||
@@ -129,8 +136,6 @@ class DbSql {
|
||||
passenger_rate TEXT
|
||||
)
|
||||
''');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getAllData(String table) async {
|
||||
|
||||
@@ -1,52 +1,90 @@
|
||||
// lib/models/order_data.dart
|
||||
|
||||
class OrderData {
|
||||
final String customerName;
|
||||
final double distance;
|
||||
final double tripDistanceKm; // المسافة الكلية للرحلة بالكيلومتر
|
||||
final String price;
|
||||
final String startLocation;
|
||||
final String endLocation;
|
||||
final String passengerDistance;
|
||||
final String duration;
|
||||
final String startLocationAddress;
|
||||
final String endLocationAddress;
|
||||
|
||||
final double distanceToPassengerKm; // المسافة إلى الراكب بالكيلومتر
|
||||
final int tripDurationMinutes; // مدة الرحلة الكلية بالدقائق (مقربة لأعلى)
|
||||
final int
|
||||
durationToPassengerMinutes; // المدة إلى الراكب بالدقائق (مقربة لأعلى)
|
||||
|
||||
final String rideType;
|
||||
final String orderId;
|
||||
final String passengerId;
|
||||
final String passengerRate;
|
||||
|
||||
final String? rawStartCoordinates;
|
||||
final String? rawEndCoordinates;
|
||||
|
||||
OrderData({
|
||||
required this.customerName,
|
||||
required this.distance,
|
||||
required this.tripDistanceKm,
|
||||
required this.price,
|
||||
required this.startLocation,
|
||||
required this.endLocation,
|
||||
required this.passengerDistance,
|
||||
required this.duration,
|
||||
required this.startLocationAddress,
|
||||
required this.endLocationAddress,
|
||||
required this.distanceToPassengerKm,
|
||||
required this.tripDurationMinutes,
|
||||
required this.durationToPassengerMinutes,
|
||||
required this.rideType,
|
||||
required this.orderId,
|
||||
required this.passengerId,
|
||||
required this.passengerRate,
|
||||
this.rawStartCoordinates,
|
||||
this.rawEndCoordinates,
|
||||
});
|
||||
|
||||
// Factory constructor to create an OrderData instance from a List<dynamic>.
|
||||
// This handles parsing and provides default values for safety.
|
||||
// دالة مساعدة لتحويل الثواني إلى دقائق وتقريبها لأعلى
|
||||
static int _secondsToRoundedUpMinutes(String secondsString) {
|
||||
final seconds = double.tryParse(secondsString) ?? 0.0;
|
||||
if (seconds <= 0) return 0;
|
||||
return (seconds / 60)
|
||||
.ceil(); // .ceil() لتقريب الكسر لأعلى (مثلاً 0.1 دقيقة تصبح 1 دقيقة)
|
||||
}
|
||||
|
||||
factory OrderData.fromList(List<dynamic> list) {
|
||||
// بناءً على testList والافتراضات الجديدة:
|
||||
// list[4]: durationToRide (مدة الرحلة الكلية بالثواني)
|
||||
// list[5]: distance (المسافة الكلية للرحلة بالكيلومتر)
|
||||
// list[12]: distanceByPassenger (المسافة إلى الراكب بالمتر)
|
||||
// list[15]: durationToPassenger (المدة إلى الراكب بالثواني)
|
||||
|
||||
double distanceToPassengerMeters =
|
||||
list.length > 12 ? (double.tryParse(list[12].toString()) ?? 0.0) : 0.0;
|
||||
|
||||
return OrderData(
|
||||
customerName: list.length > 8 ? list[8].toString() : 'Unknown Customer',
|
||||
distance:
|
||||
tripDistanceKm:
|
||||
list.length > 5 ? (double.tryParse(list[5].toString()) ?? 0.0) : 0.0,
|
||||
price: list.length > 2 ? list[2].toString().split('.')[0] : '0',
|
||||
startLocation: list.length > 29 ? list[29].toString() : 'Unknown',
|
||||
endLocation: list.length > 30 ? list[30].toString() : 'Unknown',
|
||||
passengerDistance: list.length > 12 ? list[12].toString() : 'Unknown',
|
||||
duration: list.length > 4
|
||||
? (double.parse(list[4].toString()) / 60).toStringAsFixed(0)
|
||||
: 'Unknown',
|
||||
startLocationAddress:
|
||||
list.length > 29 ? list[29].toString() : 'Unknown Address',
|
||||
endLocationAddress:
|
||||
list.length > 30 ? list[30].toString() : 'Unknown Address',
|
||||
|
||||
distanceToPassengerKm:
|
||||
distanceToPassengerMeters / 1000.0, // تحويل من متر إلى كيلومتر
|
||||
|
||||
tripDurationMinutes:
|
||||
list.length > 4 ? _secondsToRoundedUpMinutes(list[4].toString()) : 0,
|
||||
durationToPassengerMinutes: list.length > 15
|
||||
? _secondsToRoundedUpMinutes(list[15].toString())
|
||||
: 0,
|
||||
|
||||
rideType:
|
||||
list.length > 31 ? _getRideType(list[31].toString()) : 'Unknown',
|
||||
orderId: list.length > 16 ? list[16].toString() : 'Unknown',
|
||||
passengerId: list.length > 7 ? list[7].toString() : 'Unknown',
|
||||
passengerRate: list.length > 33 ? list[33].toString() : 'Unknown',
|
||||
orderId: list.length > 16 ? list[16].toString() : 'N/A',
|
||||
passengerId: list.length > 7 ? list[7].toString() : 'N/A',
|
||||
passengerRate: list.length > 33 ? list[33].toString() : 'N/A',
|
||||
|
||||
rawStartCoordinates: list.isNotEmpty ? list[0].toString() : null,
|
||||
rawEndCoordinates: list.length > 1 ? list[1].toString() : null,
|
||||
);
|
||||
}
|
||||
|
||||
static String _getRideType(String type) {
|
||||
switch (type) {
|
||||
case 'Comfort':
|
||||
@@ -60,7 +98,50 @@ class OrderData {
|
||||
case 'Rayeh Gai':
|
||||
return 'رايح جاي';
|
||||
default:
|
||||
return '';
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, double?>? get startCoordinates {
|
||||
if (rawStartCoordinates == null) return null;
|
||||
final parts = rawStartCoordinates!.split(',');
|
||||
if (parts.length == 2) {
|
||||
return {
|
||||
'lat': double.tryParse(parts[0].trim()),
|
||||
'lng': double.tryParse(parts[1].trim())
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, double?>? get endCoordinates {
|
||||
if (rawEndCoordinates == null) return null;
|
||||
final parts = rawEndCoordinates!.split(',');
|
||||
if (parts.length == 2) {
|
||||
return {
|
||||
'lat': double.tryParse(parts[0].trim()),
|
||||
'lng': double.tryParse(parts[1].trim())
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'customerName': customerName,
|
||||
'tripDistanceKm': tripDistanceKm,
|
||||
'price': price,
|
||||
'startLocationAddress': startLocationAddress,
|
||||
'endLocationAddress': endLocationAddress,
|
||||
'distanceToPassengerKm': distanceToPassengerKm,
|
||||
'tripDurationMinutes': tripDurationMinutes,
|
||||
'durationToPassengerMinutes': durationToPassengerMinutes,
|
||||
'rideType': rideType,
|
||||
'orderId': orderId,
|
||||
'passengerId': passengerId,
|
||||
'passengerRate': passengerRate,
|
||||
'rawStartCoordinates': rawStartCoordinates,
|
||||
'rawEndCoordinates': rawEndCoordinates,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user