Ejemplo n.º 1
0
        public static List <DayActualEntity> GetLocationCarGroups(IMainFilterEntity mfe, DateTime toDate)
        {
            List <DayActualEntity> feaData, adjustments, buffers, reservationsCheckIn, reservationsCheckOut, emptyHolders;

            //var sw = new Stopwatch();
            //sw.Start();


            using (var db = new MarsDBDataContext())
            {
                emptyHolders = DayActualEntityRetrievers.GetPoolingEmptyAlertsHolders(db, mfe);
                buffers      = DayActualEntityRetrievers.GetBuffersForAlerts(mfe, db);
                adjustments  = DayActualEntityRetrievers.GetCurrentAdditionDeletion(mfe, true, db, true);
                feaData      = DayActualEntityRetrievers.GetFeaFullForAlerts(mfe, db).ToList();
            }

            using (var db = new PoolingDataClassesDataContext())
            {
                reservationsCheckIn  = DayActualEntityRetrievers.GetPoolingCheckInDataForAlerts(db, mfe);
                reservationsCheckOut = DayActualEntityRetrievers.GetPoolingCheckOutDataForAlerts(db, mfe);
            }

            var alertsList           = new List <DayActualEntity>();
            var now                  = DateTime.Now.GetDateAndHourOnlyByCountry(mfe.Country);
            var hourUntilEndOfPeriod = (toDate - now).TotalHours;


            for (int i = 0; i < hourUntilEndOfPeriod; i++)
            {
                int timeSlot    = i;
                var feaD        = feaData.AsParallel().Where(d => d.Tme == timeSlot).OrderBy(d => d.Label).ToList();
                var bufferD     = buffers.AsParallel().OrderBy(d => d.Label).ToList();
                var adjustmentD = adjustments.AsParallel().Where(d => d.Tme == timeSlot).OrderBy(d => d.Label).ToList();
                var resInD      = reservationsCheckIn.AsParallel().Where(d => d.Tme == timeSlot).OrderBy(d => d.Label).ToList();
                var resOutD     = reservationsCheckOut.AsParallel().Where(d => d.Tme == timeSlot).OrderBy(d => d.Label).ToList();

                foreach (var d in emptyHolders)
                {
                    //var feaEntity = d;
                    var feaEntity          = feaD.FirstOrDefault(f => f.Label == d.Label);
                    var bufferEntity       = bufferD.FirstOrDefault(f => f.Label == d.Label);
                    var adjustmentEntity   = adjustmentD.FirstOrDefault(f => f.Label == d.Label);
                    var resCheckInsEntity  = resInD.FirstOrDefault(f => f.Label == d.Label);
                    var resCheckOutsEntity = resOutD.FirstOrDefault(f => f.Label == d.Label);

                    DayActualEntity entityToAdd;

                    var lbl                = d.Label;
                    var previousBalance    = alertsList.Where(a => a.Label == lbl).OrderByDescending(a => a.Tme).FirstOrDefault();
                    var previousBalanceInt = previousBalance == null ? 0 : previousBalance.Balance;

                    if (feaEntity == null && bufferEntity == null &&
                        adjustmentEntity == null && resCheckInsEntity == null && resCheckOutsEntity == null)
                    {
                        if (previousBalanceInt != 0)
                        {
                            entityToAdd = new DayActualEntity
                            {
                                Tme     = i,
                                Label   = d.Label,
                                Balance = previousBalanceInt
                            };

                            alertsList.Add(entityToAdd);
                        }
                        continue;
                    }



                    var feaAvailable     = feaEntity == null ? 0 : feaEntity.Available;
                    var feaOffset        = feaEntity == null ? 0 : feaEntity.Offset;
                    var adjustment       = adjustmentEntity == null ? 0 : adjustmentEntity.AddditionDeletion;
                    var buffer           = bufferEntity == null ? 0 : bufferEntity.Buffer;
                    var reservations     = resCheckOutsEntity == null ? 0 : resCheckOutsEntity.Reservations;
                    var resCheckInOffset = resCheckInsEntity == null ? 0 : resCheckInsEntity.Offset;



                    var available = i == 0
                        ? feaAvailable + adjustment
                        : previousBalanceInt + buffer;

                    var balance = available
                                  - reservations + (feaOffset + resCheckInOffset)
                                  - buffer + adjustment;

                    entityToAdd = new DayActualEntity
                    {
                        Tme     = i,
                        Label   = d.Label,
                        Balance = balance
                    };

                    alertsList.Add(entityToAdd);

                    //if (balance < 0)
                    //{
                    //    if (i == 0)
                    //    {
                    //        alertsList.Add(entityToAdd);
                    //    }
                    //    else
                    //    {
                    //        OnlyAddNewOrHigherEntities(alertsList, entityToAdd, now);
                    //    }
                    //}
                }
            }


            return(alertsList);
        }
        public static List <DayActualEntity> CalculateTopics(bool hourlyTimeSlots, int timeSlots, IMainFilterEntity mfe
                                                             , bool withLabels, bool siteQ = false)
        {
            var returned = new List <DayActualEntity>();
            List <DayActualEntity> feaData, adjustments, checkInData, checkOutData;
            var bufferData = new List <DayActualEntity>();
            int buffer     = 0;

            using (var db = new MarsDBDataContext())
            {
                db.Log = new DebugTextWriter();

                feaData = withLabels
                            ? DayActualEntityRetrievers.GetFeaDataWithLabel(mfe, hourlyTimeSlots, db, siteQ)
                            : DayActualEntityRetrievers.GetFeaData(mfe, hourlyTimeSlots, db);


                adjustments = withLabels
                            ? DayActualEntityRetrievers.GetAdditionDeletionDataWithLabels(mfe, hourlyTimeSlots, db, siteQ)
                            : DayActualEntityRetrievers.GetCurrentAdditionDeletion(mfe, hourlyTimeSlots, db);
                if (withLabels)
                {
                    bufferData = DayActualEntityRetrievers.GetBuffersWithLabels(mfe, db, siteQ);
                }
                else
                {
                    buffer = DayActualEntityRetrievers.GetBuffers(mfe, db);
                }
            }
            using (var db = new PoolingDataClassesDataContext())
            {
                checkInData = withLabels
                            ? DayActualEntityRetrievers.GetPoolingCheckInDataWithLabels(mfe, hourlyTimeSlots, db, siteQ)
                            : DayActualEntityRetrievers.GetPoolingCheckInData(mfe, hourlyTimeSlots, db);
                checkOutData = withLabels
                            ? DayActualEntityRetrievers.GetPoolingCheckOutDataWithLabels(mfe, hourlyTimeSlots, db, siteQ)
                            : DayActualEntityRetrievers.GetPoolingCheckOutData(mfe, hourlyTimeSlots, db);
            }

            var emptyHolder = new DayActualEntity();


            var checkInLocations  = checkInData.Select(d => d.Label).Distinct().ToList();
            var checkOutLocations = checkInData.Select(d => d.Label).Distinct().ToList();
            var labels            = withLabels ? GetLabels(mfe, siteQ) : new List <string> {
                null
            };

            if (withLabels)
            {
                labels.AddRange(checkInLocations);
                labels.AddRange(checkOutLocations);
                labels = labels.Distinct().ToList();
            }

            for (var i = 0; i < timeSlots; i++)
            {
                foreach (var lbl in labels)
                {
                    var fea = feaData.FirstOrDefault(d => d.Tme == i && (d.Label == lbl)) ?? emptyHolder;
                    var adj = adjustments.FirstOrDefault(d => d.Tme == i && (d.Label == lbl)) ?? emptyHolder;

                    var ci           = checkInData.FirstOrDefault(d => d.Tme == i && (d.Label == lbl)) ?? emptyHolder;
                    var co           = checkOutData.FirstOrDefault(d => d.Tme == i && (d.Label == lbl)) ?? emptyHolder;
                    var bufferHolder = bufferData.FirstOrDefault(d => d.Label == lbl) ?? emptyHolder;
                    if (withLabels)
                    {
                        buffer = bufferHolder.Buffer;
                    }
                    var previousBalance    = returned.FirstOrDefault(d => d.Tme == i - 1 && (d.Label == lbl));
                    var previousBalanceInt = previousBalance == null ? 0 : previousBalance.Balance;


                    var available = i == 0
                        ? fea.Available + adj.AddditionDeletion
                        : previousBalanceInt + buffer;



                    var balance = available
                                  //+ fea.Opentrips
                                  - co.Reservations + (fea.Offset + ci.Offset)
                                  - buffer + adj.AddditionDeletion;

                    var dae = new DayActualEntity
                    {
                        Tme                     = i,
                        Label                   = lbl,
                        Available               = available,
                        Opentrips               = fea.Opentrips,
                        Reservations            = co.Reservations,
                        OnewayRes               = co.OnewayRes,
                        GoldServiceReservations = co.GoldServiceReservations,
                        PrepaidReservations     = 0,      // co.PrepaidReservations,
                        Checkin                 = fea.Checkin + ci.Checkin,
                        OnewayCheckin           = fea.OnewayCheckin + ci.OnewayCheckin,
                        Offset                  = fea.Offset + ci.Offset,
                        LocalCheckIn            = fea.LocalCheckIn,// + ci.LocalCheckIn,
                        Balance                 = balance,
                        Buffer                  = buffer,
                        AddditionDeletion       = adj.AddditionDeletion,
                        JustAdditions           = adj.JustAdditions,
                        JustDeletions           = adj.JustDeletions,
                    };
                    returned.Add(dae);

                    if (string.IsNullOrEmpty(lbl))
                    {
                        break;
                    }
                }
            }


            return(returned);
        }
Ejemplo n.º 3
0
        private static void OnlyAddNewOrHigherEntities(List <DayActualEntity> fullList, DayActualEntity entityToAdd, DateTime now)
        {
            if (entityToAdd.Tme > 0 && entityToAdd.Tme < 5)
            {
                if (fullList.Any(d => d.Label == entityToAdd.Label && d.Tme > 0 && d.Tme < 5))
                {
                    var holder = fullList.FirstOrDefault(d => d.Label == entityToAdd.Label &&
                                                         d.Tme > 0 && d.Tme < 5 &&
                                                         entityToAdd.Balance < d.Balance);
                    if (holder != null)
                    {
                        holder.Balance = entityToAdd.Balance;
                        holder.Tme     = entityToAdd.Tme;
                    }
                }
                else
                {
                    fullList.Add(entityToAdd);
                }
                return;
            }

            if (entityToAdd.Tme >= 5 && now.AddHours(entityToAdd.Tme).Day == now.Day)
            {
                if (fullList.Any(d => d.Label == entityToAdd.Label && d.Tme >= 5 && now.AddHours(d.Tme).Day == now.Day))
                {
                    var holder = fullList.FirstOrDefault(d => d.Label == entityToAdd.Label && entityToAdd.Tme >= 5 &&
                                                         now.AddHours(entityToAdd.Tme).Day == now.Day &&
                                                         entityToAdd.Balance < d.Balance);
                    if (holder != null)
                    {
                        holder.Balance = entityToAdd.Balance;
                        holder.Tme     = entityToAdd.Tme;
                    }
                }
                else
                {
                    fullList.Add(entityToAdd);
                }
                return;
            }

            if (fullList.Any(d => d.Label == entityToAdd.Label) && now.AddHours(entityToAdd.Tme).Day != now.Day)
            {
                var holder = fullList.FirstOrDefault(d => d.Label == entityToAdd.Label &&
                                                     now.AddHours(d.Tme).Day != now.Day &&
                                                     entityToAdd.Balance < d.Balance);
                if (holder != null)
                {
                    holder.Balance = entityToAdd.Balance;
                    holder.Tme     = entityToAdd.Tme;
                }
            }
            else
            {
                fullList.Add(entityToAdd);
            }
        }