public virtual void ProcessOrder() { // Artificially advance the time to the next order waiting to be created // This is a fail safe, just in case the the processing of orders don't advance time enough if (!warehouse.HasOrders) { orderStreamer.AdvanceTime(); } // Keep processing orders while there are orders if (warehouse.HasOrders) { Order order; // If there isn't time for delivery the order should be moved to next day delivery if (!warehouse.HasTimeToDeliverNextOrder(orderStreamer.CurrentTime)) { warehouse.MoveNextOrderToNextDay(); } else if (warehouse.TrySendNextOrder(out order)) // Try to send the order out of the warehouse { // Create a delivered order and track its status and times DeliveredOrder outboundOrder = new DeliveredOrder(order.Id); outboundOrder.OrderPlaced = order.Created; outboundOrder.DepartureTime = orderStreamer.CurrentTime; outboundOrder.DeliveredTime = outboundOrder.DepartureTime; // Time traveled to the destination double travelMinutes = warehouse.GetOrderDeliveryMinutes(order); outboundOrder.DeliveredTime = outboundOrder.DeliveredTime.AddMinutes(travelMinutes); // Total time traveled, includes to destination and returning back to the warehouse travelMinutes += warehouse.GetOrderReturnMinutes(order); completedOrders.Add(outboundOrder); deliveredOrderAction(outboundOrder); switch (outboundOrder.GetRating()) { case OrderHelper.RatingType.Detractor: detractors++; break; case OrderHelper.RatingType.Promoter: promoters++; break; } warehouse.DockDrone(); // Update the mock global time (will also bring more new orders depending on the time) orderStreamer.AddMinutesToTime(travelMinutes); } } }
public static RatingType GetRatingType(DeliveredOrder deliveredOrder) { int decimalPlaces = 2; Double elapsedHours = Math.Round((deliveredOrder.DeliveredTime - deliveredOrder.OrderPlaced).TotalHours, decimalPlaces); RatingType rating = RatingType.Promoter; if (elapsedHours >= DETRACTOR_HOUR_LIMIT) { rating = RatingType.Detractor; } else if (elapsedHours >= NEUTRAL_HOUR_LIMIT) { rating = RatingType.Neutral; } return(rating); }