public async Task <bool> InsertShuttleBus(ShuttleBus shuttleBus) { //delayed actual implementation due to this being out of scope for now _context.Add(shuttleBus); await _context.SaveChangesAsync(); return(true); }
private string GetFirstDepart(List <ShuttleBus> shuttles, long time) { long firstShuttle = 0; long departure = 0; List <ShuttleBus> departed = new List <ShuttleBus>(); //Iterate over time while shuttles need to depart do { Console.Write(time.ToString().PadLeft(rowWidth, time == arrival ? '=' : ' ')); bool hasDeparture = false; //iterate over the shuttles for (int i = 0; i < shuttles.Count; i++) { ShuttleBus shuttle = shuttles[i]; //check if our shuttle currently departs if (time == shuttle.Departures * (long)shuttle.ID) { hasDeparture = true; Console.Write("|" + ConsoleAssist.Center("D", rowWidth)); //are we at the bus stop yet? if (time >= arrival) { if (departed.Count == 0) {//this is the first bus, we can catch and it's departure time firstShuttle = (long)shuttle.ID; departure = time; } //track this shuttle as departed departed.Add(shuttle); } ++shuttle.Departures; } else { Console.Write("|" + ConsoleAssist.Center(".", rowWidth)); } } //if the time has no departure, reuse this line to save vertical screen space if (!hasDeparture && time != arrival) { Console.CursorLeft = 0; } else { Console.WriteLine("|"); } time++; //check if all shuttles are departed } while (shuttles.Except(departed).Count() > 0); return(string.Format("Departing: Shuttle {0} @{1} Result: {2}", firstShuttle, departure, firstShuttle * (departure - arrival))); }
// helper function to get amount of available seats from a booked bus public int GetAvailableSeatCountFromBookedBus(DateTime dateTime, string direction, string busId, int neededAmountOfSeats) { int requiredSeats = neededAmountOfSeats; ShuttleBus bus = _shuttleBusDAO.RetrieveShuttleBusById(busId); //find a proper way to get all passengers of a bus //currently this only gives you passengers of that schedule List <ShuttlePassenger> passengerList = GetShuttlePassengersOfBus(busId, dateTime, direction); if (passengerList.Count == bus.RetrieveShuttleBusCapacity()) { //this bus is full. go to next available bus. Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - Bus of Id " + bus.RetrieveId() + " already fully booked."); return(0); } //(current number of passengers) + (to-be-added passengers) is less or equal to (max capacity) if (passengerList.Count + requiredSeats <= bus.RetrieveShuttleBusCapacity()) { //possible to book all remaining needed seats under this bus. Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK/pass] - GOOD CAPACITY - Able to book " + requiredSeats + " amount of seats for bus " + bus.RetrieveId()); return(requiredSeats); } else { //current bus can take 'some' passengers, but not all. //get number of seats that we can put in 'right now' int possibleSeatsCount = bus.RetrieveShuttleBusCapacity() - passengerList.Count; Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - OVER CAPACITY - " + "Unable to book " + requiredSeats + " amount of seats for bus " + bus.RetrieveId()); Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - OVER CAPACITY - " + "Bus " + bus.RetrieveId() + " currently can offer " + (bus.RetrieveShuttleBusCapacity() - passengerList.Count) + " seats."); requiredSeats -= possibleSeatsCount; //update remaining amt of seats to add Debug.WriteLine("[GetAvailableSeatCountFromBookedBus - CHECK] - " + requiredSeats + " more seats needed."); return(bus.RetrieveShuttleBusCapacity() - passengerList.Count); } }
public string ReturnIndexOfLastItem() { ShuttleBus finalObject = _context.ShuttleBus.AsEnumerable().OrderByDescending(x => x.RetrieveId()).FirstOrDefault(); return(finalObject.RetrieveId()); }
/// <summary> /// Request to remove a new Shuttle Bus into the database /// </summary> /// <returns> /// returns true if removal is successful. returns false if not. /// </returns> public async Task <bool> RemoveShuttleBus(ShuttleBus shuttleBus) { //not scoped for implementation return(true); }
private string GetOrdered(List <ShuttleBus> shuttles) { bool orderedDeparture = true; long time = 0; //our reference shuttle (we need to go in the specified order, hence the constant) const int reference = 0; List <ShuttleBus> trackedDepart = new List <ShuttleBus>(); trackedDepart.Add(shuttles[0]); long trackDepartCount = 0; long stepSize = 1; rowWidth = 4; //progress over time loop do { orderedDeparture = true; Console.Write(time.ToString().PadLeft(rowWidth)); List <ShuttleBus> departed = new List <ShuttleBus>(); //check each Shuttle for this step for (int i = 0; i < shuttles.Count; i++) { ShuttleBus shuttle = shuttles[i]; //get the departures and make sure it is not before the required Time (time + offset) shuttle.Departures = time / (long)shuttle.ID; while (time + (long)(shuttle.Offset - shuttles[reference].Offset) > shuttle.Departures * (long)shuttle.ID) { ++shuttle.Departures; } //Check whether the shuttle departs at this time + offset timestamp (offset is always relative to our reference) if (time + (long)(shuttle.Offset - shuttles[reference].Offset) == shuttle.Departures * (long)shuttle.ID) { Console.Write("|" + ConsoleAssist.Center(shuttle.Offset.ToString(), rowWidth)); //Create a list of all shuttles that departed in the right order if (i == departed.Count) { departed.Add(shuttle); } } else {//the shuttle didn't depart as required Console.Write("|" + ConsoleAssist.Center(".", rowWidth)); orderedDeparture = false; } } //check if we had another shuttle departing if (departed.Count > (trackedDepart?.Count ?? 0)) { if (departed.Except(trackedDepart).Count() == departed.Count - trackedDepart.Count) {//adjust the step size and refresh our found departures stepSize = MathHelper.LeastCommonMultiple(stepSize, trackedDepart.Last().ID); Console.Write("|\t" + stepSize); trackDepartCount = time; trackedDepart = departed; } } Console.WriteLine("|"); //Go to the next time where the found shuttles depart together time += stepSize; } while (!orderedDeparture); return("First ordered Departure at " + (time + (shuttles[0].Offset - shuttles[reference].Offset) - stepSize)); }