/** Update the report outputs based on the report's data. */ public void update() { synchronized (rides) { teslaStrikes = 0; totalCalories = 0; int totalDurations = 0; int completeRides = 0; Iterator<Ride> it = rides.iterator(); while (it.hasNext()) { Ride r = it.next(); totalDurations += r.getDuration(); teslaStrikes += r.getTesla() ? 1 : 0; totalCalories += r.getCalories(); completeRides += r.getCalories() == 0 ? 0 : 1; } usageRate = totalDurations / 3600.0f; completionRate = completeRides / (count() + 0.0001f); open = Utils.getHHWOpen(); uptime = Utils.getSystemUptime(); } }
public Driver searchDriver(Ride ride) throws SQLException { DispatchDAO dispatchDAO = new DispatchDAO(); ArrayList<Driver> freeDrivers = new ArrayList<Driver>(); Driver driver = null; // select driver whoose availability status is free and driver type is // taxi freeDrivers = dispatchDAO.getFreeDrivers(ride.getRidetype()); if (freeDrivers.size() != 0) { driver = freeDrivers.get(0); // update or insert into dispatch table String member_emailId = dispatchDAO.getCustomerByEmail(ride.getRequestid()); if (driver != null && member_emailId != null) { int status = dispatchDAO.insertDispatch( ride.getRideid(), driver.getMemberid(), driver.getVehicleId(), member_emailId); if (status != 0) { // notify customer and driver System.out.println( "Customer-Notification:-----Your ride will reach you at " + ride.getPickuptime()); System.out.println( "Driver-Notification:-----Your ride is waiting at " + ride.getPickuplocation() + " with Customer email: " + member_emailId); } // update vehicle and driver status dispatchDAO.updateDriverStatus("assigned", driver.getMemberid()); } } return driver; }
/** Prune the data to remove rides that aren't included in the report's reporting period. */ public void removeOld() { Calendar old = Calendar.getInstance(); old.setTime(new Date()); old.add(Calendar.MINUTE, -REPORT_PERIOD_MINS); long oldTS = old.getTime().getTime(); synchronized (rides) { Iterator<Ride> it = rides.iterator(); while (it.hasNext()) { Ride r = it.next(); long rideTS = r.getStopped().getTime(); if (rideTS < oldTS) { it.remove(); } } } }
public String SaveRide(Ride ride) { if (ride != null) { if (ride.getEmployeeName().equals("")) { return "Username Can't Be Empty."; } return "Post was successful."; } else { return "Post was unsuccessful."; } }