public BookingsStats(BookingStatsTypes type, DateTime fromDate, DateTime toDate, string interval, DateTime[] intervalsValues, int[] bookingsAll, Dictionary <int, int[]> bookingsByResources) { Type = type.ToString(); FromDate = fromDate; ToDate = toDate; Interval = interval; IntervalsValues = intervalsValues; BookingsAll = bookingsAll; BookingsByResources = bookingsByResources; }
private DateTime GetBookingDateByType(Booking booking, BookingStatsTypes type) { switch (type) { case BookingStatsTypes.Creations: return(booking.CreatedTime); case BookingStatsTypes.Cancellations: case BookingStatsTypes.Terminations: return(booking.TerminationTime.Value); case BookingStatsTypes.Completions: return(booking.EndTime); default: throw new ApplicationException("Only creation, cancellation, termination, cmpletion type is allowed"); } }
private BookingsStats GetBookingStats(BookingStatsTypes type, IEnumerable <Booking> bookings, DateTime start, DateTime end, string interval, int[] ids) { int intervalsNumber = GetIntervalsNumber(start, end, interval); DateTime[] intervalsValues = GetIntervalValues(start, interval, intervalsNumber); int[] all = new int[intervalsNumber]; Dictionary <int, int[]> bookingsOfResource = new Dictionary <int, int[]>(); foreach (var booking in bookings) { int intervalIndex = GetIntervalIndex(start, GetBookingDateByType(booking, type), interval); all[intervalIndex]++; if (ids.Length == 0 || ids.Contains(booking.ResourceId)) { if (!bookingsOfResource.ContainsKey(booking.ResourceId)) { bookingsOfResource.Add(booking.ResourceId, new int[intervalsNumber]); } bookingsOfResource[booking.ResourceId][intervalIndex]++; } } return(new BookingsStats(type, start, end, interval, intervalsValues, all, bookingsOfResource)); }