public bool IsAppointmentAddable(Appointment appointment, Dictionary <Tuple <string, string>, int> deltaTimeMatrix) { List <PathItemHandler> items = new List <PathItemHandler>(); Path.Appointments.ForEach(a => items.Add(new PathItemHandler(a))); for (int i = 0; i < Path.Constraints.Count; i++) { items.Add(new PathItemHandler(Path.Constraints[i], i)); } //Path.Constraints.ForEach(c => items.Add(new PathItemHandler(c))); items = items.OrderBy(i => i.StartTime).ToList <PathItemHandler>(); PathItemHandler lastItem = null; foreach (var item in items) { if (item.StartTime > appointment.Time) { if (GetDeadTime(new PathItemHandler(appointment), item, deltaTimeMatrix) >= new TimeSpan()) { if (lastItem == null || GetDeadTime(lastItem, new PathItemHandler(appointment), deltaTimeMatrix) > new TimeSpan()) { return(true); } } return(false); } else if (item.EndTime > appointment.Time) { return(false); } lastItem = item; } return(true); }
private TimeSpan GetDeadTime(PathItemHandler first, PathItemHandler second, Dictionary <Tuple <string, string>, int> deltaTimeMatrix) { if (deltaTimeMatrix.ContainsKey(new Tuple <string, string>(first.Id, second.Id))) { return(second.StartTime - first.EndTime - new TimeSpan(0, 0, deltaTimeMatrix[new Tuple <string, string>(first.Id, second.Id)])); } else { return(new TimeSpan(-1, 0, 0)); } }
public double GetOverallDeadTime(Dictionary <Tuple <string, string>, int> deltaTimeMatrix) { List <PathItemHandler> items = new List <PathItemHandler>(); Path.Appointments.ForEach(a => items.Add(new PathItemHandler(a))); for (int i = 0; i < Path.Constraints.Count; i++) { items.Add(new PathItemHandler(Path.Constraints[i], i)); } //Path.Constraints.ForEach(c => items.Add(new PathItemHandler(c))); items = items.OrderBy(i => i.StartTime).ToList <PathItemHandler>(); double diffInMinutes = 0; PathItemHandler before = items[0]; for (var i = 1; i < items.Count; i++) { diffInMinutes += GetDeadTime(before, items[i], deltaTimeMatrix).TotalMinutes; before = items[i]; } return(diffInMinutes); }
private TimeSpan GetDeadTime(PathItemHandler first, PathItemHandler second, Dictionary<Tuple<string, string>, int> deltaTimeMatrix) { if (deltaTimeMatrix.ContainsKey(new Tuple<string, string>(first.Id, second.Id))) return second.StartTime - first.EndTime - new TimeSpan(0, 0, deltaTimeMatrix[new Tuple<string, string>(first.Id, second.Id)]); else return new TimeSpan(-1, 0, 0); }