Exemplo n.º 1
0
        /// <summary>
        /// Get the number of blocks for the equipment type
        /// </summary>
        /// <param name="item"></param>
        /// <param name="configuration"></param>
        public static int GetNumberOfBlocks(HetEquipment item, IConfiguration configuration)
        {
            int numberOfBlocks = -1;

            try
            {
                SeniorityScoringRules scoringRules = new SeniorityScoringRules(configuration);

                numberOfBlocks = item.DistrictEquipmentType.EquipmentType.IsDumpTruck ?
                                 scoringRules.GetTotalBlocks("DumpTruck") + 1 : scoringRules.GetTotalBlocks() + 1;
            }
            catch
            {
                // do nothing
            }

            return(numberOfBlocks);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the number of blocks for this type of equipment
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private int GetNumberOfBlocks(RentalRequest item)
        {
            int numberOfBlocks = -1;

            try
            {
                SeniorityScoringRules scoringRules = new SeniorityScoringRules(_configuration);

                numberOfBlocks = item.DistrictEquipmentType.EquipmentType.IsDumpTruck ?
                                 scoringRules.GetTotalBlocks("DumpTruck") : scoringRules.GetTotalBlocks();
            }
            catch
            {
                // do nothing
            }

            return(numberOfBlocks);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Recalculate the block assignment for each piece of equipment
        /// </summary>
        /// <param name="performContext"></param>
        /// <param name="seniorityScoringRules"></param>
        /// <param name="dbContext"></param>
        /// <param name="systemId"></param>
        public static void ProcessBlocks(PerformContext performContext, string seniorityScoringRules, DbAppContext dbContext, string systemId)
        {
            try
            {
                performContext.WriteLine("*** Recalculating Equipment Block Assignment ***");
                Debug.WriteLine("Recalculating Equipment Block Assignment");

                int    ii = 0;
                string _oldTableProgress = "BlockAssignment_Progress";
                string _newTable         = "BlockAssignment";

                // check if the block assignment has already been completed
                int startPoint = ImportUtility.CheckInterMapForStartPoint(dbContext, _oldTableProgress, BcBidImport.SigId, _newTable);

                if (startPoint == BcBidImport.SigId)    // this means the assignment job is complete
                {
                    performContext.WriteLine("*** Recalculating Equipment Block Assignment is complete from the former process ***");
                    return;
                }

                // ************************************************************
                // cleanup old block assignment status records
                // ************************************************************
                List <ImportMap> importMapList = dbContext.ImportMaps
                                                 .Where(x => x.OldTable == _oldTableProgress &&
                                                        x.NewTable == _newTable)
                                                 .ToList();

                foreach (ImportMap importMap in importMapList)
                {
                    dbContext.ImportMaps.Remove(importMap);
                }

                dbContext.SaveChanges();

                // ************************************************************
                // get processing rules
                // ************************************************************
                SeniorityScoringRules scoringRules = new SeniorityScoringRules(seniorityScoringRules);

                // ************************************************************
                // get all local areas
                // (using active equipment to minimize the results)
                // ************************************************************
                List <LocalArea> localAreas = dbContext.Equipments
                                              .Include(x => x.LocalArea)
                                              .Where(x => x.Status == Equipment.StatusApproved &&
                                                     x.ArchiveCode == "N")
                                              .Select(x => x.LocalArea)
                                              .Distinct()
                                              .ToList();

                // ************************************************************
                // get all district equipment types
                // (using active equipment to minimize the results)
                // ************************************************************
                List <DistrictEquipmentType> equipmentTypes = dbContext.Equipments
                                                              .Include(x => x.DistrictEquipmentType)
                                                              .Where(x => x.Status == Equipment.StatusApproved &&
                                                                     x.ArchiveCode == "N")
                                                              .Select(x => x.DistrictEquipmentType)
                                                              .Distinct()
                                                              .ToList();

                // ************************************************************************
                // iterate the data and update the assugnment blocks
                // (seniority is already calculated)
                // ************************************************************************
                Debug.WriteLine("Recalculating Equipment Block Assignment - Local Area Record Count: " + localAreas.Count);

                foreach (LocalArea localArea in localAreas)
                {
                    foreach (DistrictEquipmentType districtEquipmentType in equipmentTypes)
                    {
                        // get the associated equipment type
                        EquipmentType equipmentTypeRecord = dbContext.EquipmentTypes.FirstOrDefault(x => x.Id == districtEquipmentType.EquipmentTypeId);

                        if (equipmentTypeRecord == null)
                        {
                            throw new DataException(string.Format("Invalid District Equipment Type. No associated Equipment Type record (District Equipment Id: {0})", districtEquipmentType.Id));
                        }

                        // get rules
                        int blockSize   = equipmentTypeRecord.IsDumpTruck ? scoringRules.GetBlockSize("DumpTruck") : scoringRules.GetBlockSize();
                        int totalBlocks = equipmentTypeRecord.IsDumpTruck ? scoringRules.GetTotalBlocks("DumpTruck") : scoringRules.GetTotalBlocks();

                        // assign blocks
                        SeniorityListExtensions.AssignBlocks(dbContext, localArea.Id, districtEquipmentType.Id, blockSize, totalBlocks, false);

                        // save change to database periodically to avoid frequent writing to the database
                        if (ii++ % 1000 == 0)
                        {
                            try
                            {
                                Debug.WriteLine("Recalculating Equipment Block Assignment - Index: " + ii);
                                ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, ii.ToString(), BcBidImport.SigId, _newTable);
                                dbContext.SaveChangesForImport();
                            }
                            catch (Exception e)
                            {
                                performContext.WriteLine("Error saving data " + e.Message);
                            }
                        }
                    }
                }

                // ************************************************************
                // save final set of updates
                // ************************************************************
                try
                {
                    performContext.WriteLine("*** Recalculating Equipment Block Assignment is Done ***");
                    Debug.WriteLine("Recalculating Equipment Block Assignment is Done");
                    ImportUtility.AddImportMapForProgress(dbContext, _oldTableProgress, BcBidImport.SigId.ToString(), BcBidImport.SigId, _newTable);
                    dbContext.SaveChangesForImport();
                }
                catch (Exception e)
                {
                    string temp = string.Format("Error saving data (Record: {0}): {1}", ii, e.Message);
                    performContext.WriteLine(temp);
                    throw new DataException(temp);
                }
            }
            catch (Exception e)
            {
                performContext.WriteLine("*** ERROR ***");
                performContext.WriteLine(e.ToString());
                throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Seniority List view model
        /// </summary>
        /// <param name="model"></param>
        /// <param name="scoringRules"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static SeniorityViewModel ToSeniorityViewModel(this Equipment model, SeniorityScoringRules scoringRules, DbAppContext context)
        {
            var dto = new SeniorityViewModel();

            if (model != null)
            {
                int numberOfBlocks = 0;

                // get number of blocks for this equiment type
                if (model.DistrictEquipmentType != null)
                {
                    numberOfBlocks = model.DistrictEquipmentType.EquipmentType.IsDumpTruck
                        ? scoringRules.GetTotalBlocks("DumpTruck") + 1
                        : scoringRules.GetTotalBlocks() + 1;
                }

                // get equipment seniority
                float seniority = 0F;
                if (model.Seniority != null)
                {
                    seniority = (float)model.Seniority;
                }

                // get equipment block number
                int blockNumber = 0;
                if (model.BlockNumber != null)
                {
                    blockNumber = (int)model.BlockNumber;
                }

                // get equipment block number
                int numberInBlock = 0;
                if (model.NumberInBlock != null)
                {
                    numberInBlock = (int)model.NumberInBlock;
                }

                // *************************************************************
                // Map data to view model
                // *************************************************************
                dto.Id = model.Id;

                if (model.DistrictEquipmentType != null)
                {
                    dto.EquipmentType = model.DistrictEquipmentType.DistrictEquipmentName;
                }

                if (model.Owner != null)
                {
                    dto.OwnerName = model.Owner.OrganizationName;
                    dto.OwnerId   = model.OwnerId;
                }

                dto.SeniorityString = dto.FormatSeniorityString(seniority, blockNumber, numberOfBlocks);

                // format the seniority value
                dto.Seniority = string.Format("{0:0.###}", model.Seniority);

                dto.Make          = model.Make;
                dto.Model         = model.Model;
                dto.Size          = model.Size;
                dto.EquipmentCode = model.EquipmentCode;

                dto.YearsRegistered = model.YearsOfService.ToString();

                // calculate and format the ytd hours
                float tempHours = model.GetYtdServiceHours(context);
                dto.YtdHours = string.Format("{0:0.###}", tempHours);

                // format the hours
                dto.HoursYearMinus1 = string.Format("{0:0.###}", model.ServiceHoursLastYear);
                dto.HoursYearMinus2 = string.Format("{0:0.###}", model.ServiceHoursTwoYearsAgo);
                dto.HoursYearMinus3 = string.Format("{0:0.###}", model.ServiceHoursThreeYearsAgo);

                // get last called value


                dto.SenioritySortOrder = dto.CalculateSenioritySortOrder(blockNumber, numberInBlock);
            }

            return(dto);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Equipment view model
        /// </summary>
        /// <param name="model"></param>
        /// <param name="scoringRules"></param>
        /// <returns></returns>
        public static EquipmentViewModel ToViewModel(this Equipment model, SeniorityScoringRules scoringRules)
        {
            var dto = new EquipmentViewModel();

            if (model != null)
            {
                int numberOfBlocks = 0;

                // get number of blocks for this equiment type
                if (model.DistrictEquipmentType != null)
                {
                    numberOfBlocks = model.DistrictEquipmentType.EquipmentType.IsDumpTruck
                        ? scoringRules.GetTotalBlocks("DumpTruck") + 1
                        : scoringRules.GetTotalBlocks() + 1;
                }

                // get equipment seniority
                float seniority = 0F;
                if (model.Seniority != null)
                {
                    seniority = (float)model.Seniority;
                }

                // get equipment block number
                int blockNumber = 0;
                if (model.BlockNumber != null)
                {
                    blockNumber = (int)model.BlockNumber;
                }

                // get equipment block number
                int numberInBlock = 0;
                if (model.NumberInBlock != null)
                {
                    numberInBlock = (int)model.NumberInBlock;
                }

                // *************************************************************
                // Map data to ciew model
                // *************************************************************
                dto.Id = model.Id;

                if (model.DistrictEquipmentType != null)
                {
                    dto.EquipmentType = model.DistrictEquipmentType.DistrictEquipmentName;
                }

                if (model.Owner != null)
                {
                    dto.OwnerName = model.Owner.OrganizationName;
                    dto.OwnerId   = model.OwnerId;
                }

                dto.SeniorityString = dto.FormatSeniorityString(seniority, blockNumber, numberOfBlocks);

                dto.IsHired = dto.CheckIsHired(model.RentalAgreements);

                dto.Make               = model.Make;
                dto.Model              = model.Model;
                dto.Size               = model.Size;
                dto.EquipmentCode      = model.EquipmentCode;
                dto.AttachmentCount    = dto.CalculateAttachmentCount(model.EquipmentAttachments);
                dto.LastVerifiedDate   = model.LastVerifiedDate;
                dto.SenioritySortOrder = dto.CalculateSenioritySortOrder(blockNumber, numberInBlock);
            }

            return(dto);
        }