25-12-1/1
This commit is contained in:
@@ -52,31 +52,58 @@ class DriverBehaviorController extends GetxController {
|
||||
double totalSpeed = 0;
|
||||
int hardBrakes = 0;
|
||||
double totalDistance = 0;
|
||||
|
||||
// متغيرات للمقارنة مع النقطة السابقة
|
||||
double? prevLat, prevLng;
|
||||
DateTime? prevTime;
|
||||
|
||||
// ترتيب البيانات حسب الوقت لضمان دقة الحساب (اختياري لكن مفضل)
|
||||
// data.sort((a, b) => a['created_at'].compareTo(b['created_at']));
|
||||
|
||||
for (var item in data) {
|
||||
double speed = item['speed'] ?? 0;
|
||||
double lat = item['lat'] ?? 0;
|
||||
double lng = item['lng'] ?? 0;
|
||||
double acc = item['acceleration'] ?? 0;
|
||||
// 1. قراءة البيانات بالأسماء الصحيحة من الجدول
|
||||
double lat = item['latitude'] ?? item['lat'] ?? 0.0;
|
||||
double lng = item['longitude'] ?? item['lng'] ?? 0.0;
|
||||
double acc = item['acceleration'] ?? 0.0;
|
||||
|
||||
if (speed > maxSpeed) maxSpeed = speed;
|
||||
totalSpeed += speed;
|
||||
// قراءة الوقت لحساب السرعة
|
||||
DateTime currentTime =
|
||||
DateTime.tryParse(item['created_at'].toString()) ?? DateTime.now();
|
||||
|
||||
// ✅ Hard brake threshold
|
||||
double currentSpeed = 0;
|
||||
|
||||
// 2. حساب السرعة والمسافة إذا وجدت نقطة سابقة
|
||||
if (prevLat != null && prevLng != null && prevTime != null) {
|
||||
double distKm = _calculateDistance(prevLat, prevLng, lat, lng);
|
||||
int timeDiffSeconds = currentTime.difference(prevTime).inSeconds;
|
||||
|
||||
if (timeDiffSeconds > 0) {
|
||||
// السرعة (كم/س) = (المسافة بالكيلومتر * 3600) / الزمن بالثواني
|
||||
currentSpeed = (distKm * 3600) / timeDiffSeconds;
|
||||
}
|
||||
|
||||
totalDistance += distKm;
|
||||
}
|
||||
|
||||
// تحديث القيم الإحصائية
|
||||
if (currentSpeed > maxSpeed) maxSpeed = currentSpeed;
|
||||
totalSpeed += currentSpeed;
|
||||
|
||||
// حساب الفرملة القوية (يعتمد على التسارع المحفوظ مسبقاً)
|
||||
if (acc.abs() > 3.0) hardBrakes++;
|
||||
|
||||
// ✅ Distance between points
|
||||
if (prevLat != null && prevLng != null) {
|
||||
totalDistance += _calculateDistance(prevLat, prevLng, lat, lng);
|
||||
}
|
||||
// حفظ النقطة الحالية لتكون هي "السابقة" في الدورة التالية
|
||||
prevLat = lat;
|
||||
prevLng = lng;
|
||||
prevTime = currentTime;
|
||||
}
|
||||
|
||||
double avgSpeed = totalSpeed / data.length;
|
||||
// تجنب القسمة على صفر
|
||||
double avgSpeed = (data.length > 1) ? totalSpeed / (data.length - 1) : 0;
|
||||
|
||||
// حساب تقييم السلوك
|
||||
double behaviorScore = 100 - (hardBrakes * 5) - ((maxSpeed > 100) ? 10 : 0);
|
||||
behaviorScore = behaviorScore.clamp(0, 100);
|
||||
behaviorScore = behaviorScore.clamp(0.0, 100.0);
|
||||
|
||||
return {
|
||||
'max_speed': maxSpeed,
|
||||
|
||||
@@ -35,7 +35,7 @@ class DurationController extends GetxController {
|
||||
getStaticDriver() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
var res = await CRUD().getWallet(
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.driverStatistic,
|
||||
payload: {'driverID': box.read(BoxName.driverID)});
|
||||
if (res == 'failure') {
|
||||
|
||||
@@ -51,7 +51,7 @@ class HomeCaptainController extends GetxController {
|
||||
String totalMoneyInSEFER = '0';
|
||||
String totalDurationToday = '0';
|
||||
Timer? timer;
|
||||
late LatLng myLocation = const LatLng(32, 36);
|
||||
late LatLng myLocation = const LatLng(33.5138, 36.2765);
|
||||
String totalPoints = '0';
|
||||
String countRefuse = '0';
|
||||
bool mapType = false;
|
||||
@@ -99,7 +99,7 @@ class HomeCaptainController extends GetxController {
|
||||
|
||||
isActive = !isActive;
|
||||
if (isActive) {
|
||||
if (double.parse(totalPoints) > -300) {
|
||||
if (double.parse(totalPoints) > -30000) {
|
||||
locationController.startLocationUpdates();
|
||||
HapticFeedback.heavyImpact();
|
||||
// locationBackController.startBackLocation();
|
||||
@@ -188,22 +188,25 @@ class HomeCaptainController extends GetxController {
|
||||
|
||||
// late GoogleMapController mapHomeCaptainController;
|
||||
GoogleMapController? mapHomeCaptainController;
|
||||
// final locationController = Get.find<LocationController>();
|
||||
|
||||
// --- FIX 2: Smart Map Creation ---
|
||||
void onMapCreated(GoogleMapController controller) {
|
||||
mapHomeCaptainController = controller;
|
||||
controller.getVisibleRegion();
|
||||
// Animate camera to user location (optional)
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(Get.find<LocationController>().myLocation),
|
||||
);
|
||||
}
|
||||
|
||||
// قم بإنشائه مباشرة
|
||||
// final MapController mapController = MapController();
|
||||
// bool isMapReady = false;
|
||||
// void onMapReady() {
|
||||
// isMapReady = true;
|
||||
// print("Map is ready to be moved!");
|
||||
// }
|
||||
// Check actual location before moving camera
|
||||
var currentLoc = locationController.myLocation;
|
||||
if (currentLoc.latitude != 0 && currentLoc.longitude != 0) {
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(currentLoc),
|
||||
);
|
||||
} else {
|
||||
// Optional: Move to default city view instead of ocean
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLngZoom(myLocation, 10),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void savePeriod(Duration period) {
|
||||
final periods = box.read<List<dynamic>>(BoxName.periods) ?? [];
|
||||
@@ -234,7 +237,14 @@ class HomeCaptainController extends GetxController {
|
||||
getlocation() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
// This ensures we try to get a fix, but map doesn't crash if it fails
|
||||
await Get.find<LocationController>().getLocation();
|
||||
|
||||
var loc = Get.find<LocationController>().myLocation;
|
||||
if (loc.latitude != 0) {
|
||||
myLocation = loc;
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
@@ -267,7 +277,7 @@ class HomeCaptainController extends GetxController {
|
||||
void onInit() async {
|
||||
// await locationBackController.requestLocationPermission();
|
||||
Get.put(FirebaseMessagesController());
|
||||
// addToken();
|
||||
addToken();
|
||||
await getlocation();
|
||||
onButtonSelected();
|
||||
getDriverRate();
|
||||
@@ -283,61 +293,27 @@ class HomeCaptainController extends GetxController {
|
||||
getRefusedOrderByCaptain();
|
||||
box.write(BoxName.statusDriverLocation, 'off');
|
||||
locationController.addListener(() {
|
||||
// فقط إذا كان السائق "متصل" والخريطة جاهزة
|
||||
// Only animate if active, map is ready, AND location is valid (not 0,0)
|
||||
if (isActive && mapHomeCaptainController != null) {
|
||||
mapHomeCaptainController!.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: locationController.myLocation, // الموقع الجديد
|
||||
zoom: 17.5,
|
||||
tilt: 50.0,
|
||||
bearing: locationController.heading, // اتجاه السيارة
|
||||
var loc = locationController.myLocation;
|
||||
|
||||
if (loc.latitude != 0 && loc.longitude != 0) {
|
||||
mapHomeCaptainController!.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: loc,
|
||||
zoom: 17.5,
|
||||
tilt: 50.0,
|
||||
bearing: locationController.heading,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
// LocationController().getLocation();
|
||||
super.onInit();
|
||||
}
|
||||
// void getRefusedOrderByCaptain() async {
|
||||
// // Get today's date in YYYY-MM-DD format
|
||||
// String today = DateTime.now().toString().substring(0, 10);
|
||||
|
||||
// String driverId = box.read(BoxName.driverID).toString();
|
||||
|
||||
// String customQuery = '''
|
||||
// SELECT COUNT(*) AS count
|
||||
// FROM ${TableName.driverOrdersRefuse}
|
||||
// WHERE driver_id = '$driverId'
|
||||
// AND DATE(created_at) = '$today'
|
||||
// ''';
|
||||
|
||||
// try {
|
||||
// List<Map<String, dynamic>> results =
|
||||
// await sql.getCustomQuery(customQuery);
|
||||
// countRefuse = results[0]['count'].toString();
|
||||
// update();
|
||||
// if (int.parse(countRefuse) > 3) {
|
||||
// box.write(BoxName.statusDriverLocation, 'on');
|
||||
// locationController.stopLocationUpdates();
|
||||
// Get.defaultDialog(
|
||||
// // backgroundColor: CupertinoColors.destructiveRed,
|
||||
// barrierDismissible: false,
|
||||
// title: 'You Are Stopped For this Day !'.tr,
|
||||
// content: Text(
|
||||
// 'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
|
||||
// .tr,
|
||||
// style: AppStyle.title,
|
||||
// ),
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Ok , See you Tomorrow'.tr,
|
||||
// onPressed: () => Get.back()));
|
||||
// } else {
|
||||
// box.write(BoxName.statusDriverLocation, 'off');
|
||||
// }
|
||||
// } catch (e) {}
|
||||
// }
|
||||
|
||||
addToken() async {
|
||||
String? fingerPrint = await storage.read(key: BoxName.fingerPrint);
|
||||
@@ -346,14 +322,8 @@ class HomeCaptainController extends GetxController {
|
||||
'captain_id': (box.read(BoxName.driverID)).toString(),
|
||||
'fingerPrint': (fingerPrint).toString()
|
||||
};
|
||||
Log.print('payload: ${payload}');
|
||||
// Log.print('payload: ${payload}');
|
||||
CRUD().post(link: AppLink.addTokensDriver, payload: payload);
|
||||
|
||||
await CRUD().post(
|
||||
link: "${AppLink.paymentServer}/ride/firebase/addDriver.php",
|
||||
payload: payload);
|
||||
// MapDriverController().driverCallPassenger();
|
||||
// box.write(BoxName.statusDriverLocation, 'off');
|
||||
}
|
||||
|
||||
getPaymentToday() async {
|
||||
@@ -468,6 +438,7 @@ class HomeCaptainController extends GetxController {
|
||||
void dispose() {
|
||||
activeTimer?.cancel();
|
||||
stopTimer();
|
||||
mapHomeCaptainController?.dispose(); // Dispose controller
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -188,7 +188,7 @@ class OrderRequestController extends GetxController {
|
||||
if (remainingTime == 0 && _timerActive) {
|
||||
if (applied == false) {
|
||||
endTimer();
|
||||
refuseOrder(orderID);
|
||||
//refuseOrder(orderID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,29 +211,6 @@ class OrderRequestController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void refuseOrder(
|
||||
orderID,
|
||||
) async {
|
||||
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
|
||||
'driver_id': box.read(BoxName.driverID),
|
||||
'order_id': (orderID),
|
||||
'status': 'Refused'
|
||||
});
|
||||
await CRUD().post(link: AppLink.updateRides, payload: {
|
||||
'id': (orderID),
|
||||
'status': 'Refused',
|
||||
'driver_id': box.read(BoxName.driverID),
|
||||
});
|
||||
// if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
// CRUD().post(link: '${AppLink.endPoint}/rides/update.php', payload: {
|
||||
// 'id': (orderID),
|
||||
// 'status': 'Refused',
|
||||
// 'driver_id': box.read(BoxName.driverID),
|
||||
// });
|
||||
// }
|
||||
update();
|
||||
}
|
||||
|
||||
addRideToNotificationDriverString(
|
||||
orderID,
|
||||
String startLocation,
|
||||
|
||||
Reference in New Issue
Block a user