Beispiel #1
0
        public void OutputIndex(IndexOutputRequest indexOutputRequest)
        {
            IndexParameter      indexParameter      = IndexParameterParser.ParseIndexParameter();
            DictionaryParameter dictionaryParameter = DictionaryParameterParser.ParseDictionaryParameter();

            if (indexParameter.IsPresent)
            {
                List <string> dictionaryWords = DictionaryFileLoader.ReadWords();

                int unknwonWordsCount = EnumerableHelpers.CountUnknownWords(
                    distinctWords: indexOutputRequest.DistinctWords,
                    dictionaryWords: dictionaryWords);

                if (dictionaryParameter.IsPresent)
                {
                    DisplayOutput.WriteResourceLine(
                        resourceIdent: "INDEX_WITH_UNKNOWN",
                        placeholderValues: unknwonWordsCount);
                }
                else
                {
                    DisplayOutput.WriteResourceLine(
                        resourceIdent: "INDEX");
                }

                DisplayWords(
                    distinctWords: indexOutputRequest.DistinctWords,
                    dictionaryWords: dictionaryWords);
            }
        }
Beispiel #2
0
        private void TransferDropdownValue(DictionaryParameter paramType, DropDownList ddl)
        {
            if (SessionStoredReservationParameters[paramType] != string.Empty)
            {
                ddl.SelectedValue = SessionStoredReservationParameters[paramType];
                int paramLevel;
                switch (paramType)
                {
                case DictionaryParameter.CheckOutLocation:
                    paramLevel = 3;
                    break;

                case DictionaryParameter.CheckOutLocationGroup:
                case DictionaryParameter.CheckOutArea:
                    paramLevel = 2;
                    break;

                case DictionaryParameter.CheckOutPool:
                case DictionaryParameter.CheckOutRegion:
                    paramLevel = 1;
                    break;

                default:
                    paramLevel = 0;
                    break;
                }
                FillDropDowns(false, paramLevel, SessionStoredReservationParameters, false, false, true);
            }
        }
        private void TransferDropdownValue(DictionaryParameter paramType, DropDownList ddl)
        {
            if (SessionStoredAvailabilityParameters.ContainsValueAndIsntEmpty(paramType))
            {
                ddl.SelectedValue = SessionStoredAvailabilityParameters[paramType];
                int paramLevel;
                switch (paramType)
                {
                case DictionaryParameter.CheckOutLocation:

                case DictionaryParameter.Location:
                    paramLevel = 3;
                    break;

                case DictionaryParameter.CheckOutLocationGroup:
                case DictionaryParameter.LocationGroup:
                case DictionaryParameter.CheckOutArea:
                case DictionaryParameter.Area:
                    paramLevel = 2;
                    break;

                case DictionaryParameter.CheckOutPool:
                case DictionaryParameter.Pool:
                case DictionaryParameter.CheckOutRegion:
                case DictionaryParameter.Region:
                    paramLevel = 1;
                    break;

                default:
                    paramLevel = 0;
                    break;
                }
                FillDropDowns(true, paramLevel, SessionStoredAvailabilityParameters, false, false);
            }
        }
Beispiel #4
0
        public List <string> ReadWords()
        {
            DictionaryParameter dictionaryParameter = DictionaryParameterParser.ParseDictionaryParameter();

            string path = dictionaryParameter.FileName;

            if (dictionaryParameter.IsPresent &&
                !FileSystem.File.Exists(path: path))
            {
                DisplayOutput.WriteErrorResourceLine(
                    resourceIdent: "FILE_NOT_FOUND",
                    placeholderValues: path);
                return(new List <string>());
            }

            if (!dictionaryParameter.IsPresent)
            {
                return(new List <string>());
            }

            return(FileSystem
                   .File
                   .ReadAllLines(path: path)
                   .ToEmptyIfNullList());
        }
Beispiel #5
0
        public void DictionaryParameterParserTests_Args_has_DictionaryParameter_Without_File_Expect_IsPresent_False()
        {
            _mockEnvironment
            .Setup(m => m.GetCommandLineArgs())
            .Returns(new[] { "-dictionary=" });

            DictionaryParameter actual = _systemUnderTest
                                         .ParseDictionaryParameter();

            Assert.NotNull(@object: actual);
            Assert.False(condition: actual.IsPresent);
        }
Beispiel #6
0
        public void DictionaryParameterParserTests_Args_is_empty_Expect_IsPresent_False()
        {
            _mockEnvironment
            .Setup(expression: m => m.GetCommandLineArgs())
            .Returns(value: Array.Empty <string>());

            DictionaryParameter actual = _systemUnderTest
                                         .ParseDictionaryParameter();

            Assert.NotNull(@object: actual);
            Assert.False(condition: actual.IsPresent);
        }
Beispiel #7
0
        public void DictionaryParameterParserTests_Args_have_no_Dictionary_Parameter_Expect_IsPresent_False()
        {
            _mockEnvironment
            .Setup(expression: m => m.GetCommandLineArgs())
            .Returns(value: new[] { "bla.txt" });

            DictionaryParameter actual = _systemUnderTest
                                         .ParseDictionaryParameter();

            Assert.NotNull(@object: actual);
            Assert.False(condition: actual.IsPresent);
        }
Beispiel #8
0
        public void DictionaryParameterParserTests_Args_has_DictionaryParameter_With_File_bla_txt_Expect_FileName_bla_txt()
        {
            _mockEnvironment
            .Setup(m => m.GetCommandLineArgs())
            .Returns(new[] { "-dictionary=bla.txt" });

            DictionaryParameter actual = _systemUnderTest
                                         .ParseDictionaryParameter();

            Assert.NotNull(@object: actual);
            Assert.Equal(expected: "bla.txt", actual: actual.FileName);
        }
Beispiel #9
0
        public virtual void InitParameters()
        {
            _params = new List<AlgorithmParameter>();
            // Add all available confidence computing methods
            DictionaryParameter confParam =
                new DictionaryParameter("Confidence Computing Method", "CONF");

            confParam.ValuesMap = new Dictionary<string, object>()
            {
                { "Two Against Two", ConfidenceMethod.TwoAgainstTwo },
                { "Two Against Max", ConfidenceMethod.TwoAgainstMax },
                { "Two Against Average", ConfidenceMethod.TwoAgainstAverage }
            };

            _params.Add(confParam);
        }
Beispiel #10
0
        protected List <ComparisonRow> GetHistoryComparisonData(DictionaryParameter comparisonType)
        {
            var groupedData = GetGroupedVehicleHistoryQuery(comparisonType);

            if (groupedData == null)
            {
                return(new List <ComparisonRow>());
            }
            var compData = from gd in groupedData
                           select new ComparisonRow
            {
                Key            = gd.Key,
                FleetCount     = gd.Count(),
                NonRevCount    = gd.Sum(d => d.IsNonRev ? 1 : 0),
                ReasonsEntered = gd.Sum(d => d.RemarkId == null ? 0 : 1),
            };
            var returned = compData.ToList();

            return(returned);
        }
 internal static bool ContainsValueAndIsntEmpty(this Dictionary <DictionaryParameter, string> dictionary, DictionaryParameter parameter)
 {
     return(dictionary.ContainsKey(parameter) && dictionary[parameter] != string.Empty);
 }
        private List <AgeingRow> GetCurrentAgeRowData(DictionaryParameter comparisonType)
        {
            var vehicles = BaseVehicleDataAccess.GetVehicleQueryable(Parameters, DataContext, true, true);

            if (vehicles == null)
            {
                return(new List <AgeingRow>());
            }



            IQueryable <IGrouping <string, Vehicle> > groupedData;

            switch (comparisonType)
            {
            case DictionaryParameter.OperationalStatusGrouping:
                groupedData = from v in vehicles
                              group v by v.Operational_Status.OperationalStatusCode
                              into gd
                              select gd;

                break;

            case DictionaryParameter.KciGrouping:
                groupedData = from v in vehicles
                              group v by v.Operational_Status.KCICode
                              into gd
                              select gd;

                break;

            default:
                return(null);
            }

            IEnumerable <int> selectedOperStats = null;

            if (Parameters.ContainsKey(DictionaryParameter.OperationalStatuses))
            {
                if (Parameters[DictionaryParameter.OperationalStatuses] == string.Empty)
                {
                    return(null);
                }
                selectedOperStats = Parameters[DictionaryParameter.OperationalStatuses].Split(',').Select(int.Parse);
            }

            IEnumerable <int> selectedMovementTypes = null;

            if (Parameters.ContainsKey(DictionaryParameter.MovementTypes))
            {
                if (Parameters[DictionaryParameter.MovementTypes] == string.Empty)
                {
                    return(null);
                }
                selectedMovementTypes = Parameters[DictionaryParameter.MovementTypes].Split(',').Select(int.Parse);
            }

            var compData = from gd in groupedData
                           select new AgeingRow
            {
                Key         = gd.Key,
                FleetCount  = gd.Count(),
                NonRevCount = gd.Sum(d => d.IsNonRev &&
                                     (selectedOperStats == null || selectedOperStats.Contains(d.LastOperationalStatusId)) &&
                                     (selectedMovementTypes == null || selectedMovementTypes.Contains(d.LastMovementTypeId))
                                                        ? 1 : 0),
                Ages = gd.Where(d =>
                                d.IsNonRev &&
                                (selectedOperStats == null || selectedOperStats.Contains(d.LastOperationalStatusId)) &&
                                (selectedMovementTypes == null || selectedMovementTypes.Contains(d.LastMovementTypeId))
                                ).Select(d => d.DaysSinceLastRevenueMovement).ToList()
            };
            var returned = compData.ToList();

            return(returned);
        }
        public IQueryable <IGrouping <string, Vehicle> > GetSingleKeyGroupedVehicle(DictionaryParameter comparisonType)
        {
            var vehicles = BaseVehicleDataAccess.GetVehicleQueryable(Parameters, DataContext, true, true);

            IQueryable <IGrouping <string, Vehicle> > groupedData;


            switch (comparisonType)
            {
            case DictionaryParameter.LocationCountry:
                groupedData = from v in vehicles
                              join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                              group v by l.COUNTRy1.country_description
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Pool:

                groupedData = from v in vehicles
                              join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                              group v by l.CMS_LOCATION_GROUP.CMS_POOL.cms_pool1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.LocationGroup:

                groupedData = from v in vehicles
                              join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                              group v by l.CMS_LOCATION_GROUP.cms_location_group1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Area:

                groupedData = from v in vehicles
                              join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                              group v by l.OPS_AREA.ops_area1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Region:

                groupedData = from v in vehicles
                              join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                              group v by l.OPS_AREA.OPS_REGION.ops_region1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Location:

                groupedData = from v in vehicles
                              group v by v.LastLocationCode
                              into gd
                              select gd;
                break;

            case DictionaryParameter.OwningCountry:

                groupedData = from v in vehicles
                              join cg in DataContext.CAR_GROUPs on new { v.CarGroup, v.OwningCountry } equals
                new { CarGroup = cg.car_group1, OwningCountry = cg.CAR_CLASS.CAR_SEGMENT.country }
                group v by cg.CAR_CLASS.CAR_SEGMENT.COUNTRy1.country_description
                into gd
                select gd;
                break;

            case DictionaryParameter.CarSegment:


                groupedData = from v in vehicles
                              join cg in DataContext.CAR_GROUPs on new { v.CarGroup, v.OwningCountry } equals
                new { CarGroup = cg.car_group1, OwningCountry = cg.CAR_CLASS.CAR_SEGMENT.country }
                group v by cg.CAR_CLASS.CAR_SEGMENT.car_segment1
                into gd
                select gd;
                break;

            case DictionaryParameter.CarClass:
                groupedData = from v in vehicles
                              join cg in DataContext.CAR_GROUPs on new { v.CarGroup, v.OwningCountry } equals
                new { CarGroup = cg.car_group1, OwningCountry = cg.CAR_CLASS.CAR_SEGMENT.country }
                group v by cg.CAR_CLASS.car_class1
                into gd
                select gd;
                break;

            case DictionaryParameter.CarGroup:

                groupedData = from v in vehicles
                              group v by v.CarGroup
                              into gd
                              select gd;

                break;

            default:
                return(null);
            }


            return(groupedData);
        }
 internal static DateTime GetDateFromDictionary(this Dictionary <DictionaryParameter, string> dictionary, DictionaryParameter key)
 {
     if (dictionary.ContainsKey(key))
     {
         DateTime returned;
         DateTime.TryParse(dictionary[key], out returned);
         return(returned);
     }
     return(DateTime.MinValue);
 }
Beispiel #15
0
        public override void InitParameters()
        {
            _params = new List<AlgorithmParameter>();

            DictionaryParameter meanParam =
                new DictionaryParameter("Mean Computing Method", "MEAN");

            meanParam.ValuesMap = new Dictionary<string, object>()
            {
                { "Simple Average", MeanMethods.SimpleAverage },
                { "Weighted Average", MeanMethods.WeightedAverage }
            };

            _params.Add(meanParam);

            DictionaryParameter costParam =
                new DictionaryParameter("Cost Computing Method", "COST");

            costParam.ValuesMap = new Dictionary<string, object>()
            {
                { "E(||d - m||) / n^2", CostMethods.DistanceToMean },
                { "E(||d - m||^2) / n^4", CostMethods.DistanceSquredToMean },
                { "E(||d - m||) / n*sqrt(n)", CostMethods.DistanceSquredToMeanRoot }
            };

            _params.Add(costParam);
        }
        protected IQueryable <IGrouping <StringDateGrouping, FleetHistory> > GetTwoKeyGroupedAvailabilityHistory(DictionaryParameter comparisonType)
        {
            var avHistory = GetAvailabilityHistory();

            IQueryable <IGrouping <StringDateGrouping, FleetHistory> > groupedData;


            switch (comparisonType)
            {
            case DictionaryParameter.LocationCountry:
                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.LOCATION.COUNTRy1.country_description, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.Pool:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.LOCATION.CMS_LOCATION_GROUP.CMS_POOL.cms_pool1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.LocationGroup:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.LOCATION.CMS_LOCATION_GROUP.cms_location_group1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.Area:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.LOCATION.OPS_AREA.ops_area1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.Region:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.LOCATION.OPS_AREA.OPS_REGION.ops_region1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.Location:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.LOCATION.location1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.OwningCountry:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.COUNTRy1.country_description, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.CarSegment:


                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.CAR_GROUP.CAR_CLASS.CAR_SEGMENT.car_segment1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.CarClass:
                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.CAR_GROUP.CAR_CLASS.car_class1, Date = v.Timestamp
                }
                into gd
                select gd;
                break;

            case DictionaryParameter.CarGroup:

                groupedData = from v in avHistory
                              group v by new StringDateGrouping {
                    Key = v.CAR_GROUP.car_group1, Date = v.Timestamp
                }
                into gd
                select gd;

                break;

            default:
                return(null);
            }


            return(groupedData);
        }
Beispiel #17
0
        protected List <ComparisonRow> GetCurrentComparisonData(DictionaryParameter comparisonType)
        {
            var vehicles = BaseVehicleDataAccess.GetVehicleQueryable(Parameters, DataContext, true, true);

            if (vehicles == null)
            {
                return(new List <ComparisonRow>());
            }


            IQueryable <IGrouping <string, VehicleRemarkIdHolder> > groupedRemData = null;

            int minDays = 0;

            if (Parameters.ContainsKey(DictionaryParameter.MinDaysNonRev) &&
                Parameters[DictionaryParameter.MinDaysNonRev] != string.Empty)
            {
                minDays = int.Parse(Parameters[DictionaryParameter.MinDaysNonRev]);
            }

            var allRemarks = from r in DataContext.VehicleNonRevPeriodEntryRemarks
                             select r;

            IEnumerable <int> selectedOperStats = null;


            if (Parameters.ContainsValueAndIsntEmpty(DictionaryParameter.OperationalStatuses))
            {
                selectedOperStats = Parameters[DictionaryParameter.OperationalStatuses].Split(',').Select(int.Parse);
                allRemarks        = allRemarks.Where(d => selectedOperStats.Contains(d.VehicleNonRevPeriodEntry.VehicleNonRevPeriod.Vehicle.LastOperationalStatusId));
            }

            IEnumerable <int> selectedMovementTypes = null;

            if (Parameters.ContainsValueAndIsntEmpty(DictionaryParameter.MovementTypes))
            {
                selectedMovementTypes = Parameters[DictionaryParameter.MovementTypes].Split(',').Select(int.Parse);
                allRemarks            = allRemarks.Where(d => selectedMovementTypes.Contains(d.VehicleNonRevPeriodEntry.VehicleNonRevPeriod.Vehicle.LastMovementTypeId));
            }


            var remData = from rem in allRemarks
                          //join l in DataContext.LOCATIONs on rem.VehicleNonRevPeriodEntry.VehicleNonRevPeriod.Vehicle.LastLocationCode equals l.location1
                          where rem.VehicleNonRevPeriodEntry.VehicleNonRevPeriod.Active &&
                          (rem.VehicleNonRevPeriodEntry.VehicleNonRevPeriod.Vehicle.DaysSinceLastRevenueMovement >= minDays) &&
                          rem.ExpectedResolutionDate.Date >= DateTime.Now.Date
                          group rem by rem.VehicleNonRevPeriodEntry.VehicleNonRevPeriod.VehicleId
                          into g
                          join rem2 in DataContext.VehicleNonRevPeriodEntryRemarks
                          on g.Max(d => d.VehicleNonRevPeriodEntryRemarkId) equals rem2.VehicleNonRevPeriodEntryRemarkId
                          select new VehicleRemarkIdHolder
            {
                VehicleId = g.Key,
                ReasonId  = rem2.RemarkId
            };



            switch (comparisonType)
            {
            case DictionaryParameter.LocationCountry:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                 group rd by l.COUNTRy1.country_description
                                 into gd
                                 select gd;
                break;

            case DictionaryParameter.Pool:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                 group rd by l.CMS_LOCATION_GROUP.CMS_POOL.cms_pool1
                                 into gd
                                 select gd;

                break;

            case DictionaryParameter.LocationGroup:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                 group rd by l.CMS_LOCATION_GROUP.cms_location_group1
                                 into gd
                                 select gd;
                break;

            case DictionaryParameter.Area:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                 group rd by l.OPS_AREA.ops_area1
                                 into gd
                                 select gd;
                break;

            case DictionaryParameter.Region:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                 group rd by l.OPS_AREA.OPS_REGION.ops_region1
                                 into gd
                                 select gd;

                break;

            case DictionaryParameter.Location:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 group rd by v.LastLocationCode
                                 into gd
                                 select gd;
                break;

            case DictionaryParameter.OwningCountry:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join cg in DataContext.CAR_GROUPs on
                                 new { carG = v.CarGroup, country = v.OwningCountry }
                equals new { carG = cg.car_group1, country = cg.CAR_CLASS.CAR_SEGMENT.country }
                group rd by cg.CAR_CLASS.CAR_SEGMENT.COUNTRy1.country_description
                into gd
                select gd;

                break;

            case DictionaryParameter.CarSegment:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join cg in DataContext.CAR_GROUPs on
                                 new { carG = v.CarGroup, country = v.OwningCountry }
                equals new { carG = cg.car_group1, country = cg.CAR_CLASS.CAR_SEGMENT.country }
                group rd by cg.CAR_CLASS.CAR_SEGMENT.car_segment1
                into gd
                select gd;
                break;

            case DictionaryParameter.CarClass:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 join cg in DataContext.CAR_GROUPs on
                                 new { carG = v.CarGroup, country = v.OwningCountry }
                equals new { carG = cg.car_group1, country = cg.CAR_CLASS.CAR_SEGMENT.country }
                group rd by cg.CAR_CLASS.car_class1
                into gd
                select gd;
                break;

            case DictionaryParameter.CarGroup:
                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 group rd by v.CarGroup
                                 into gd
                                 select gd;
                break;

            case DictionaryParameter.OperationalStatusGrouping:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 group rd by v.Operational_Status.OperationalStatusCode
                                 into gd
                                 select gd;
                break;

            case DictionaryParameter.KciGrouping:

                groupedRemData = from rd in remData
                                 join v in vehicles on rd.VehicleId equals v.VehicleId
                                 group rd by v.Operational_Status.KCICode
                                 into gd
                                 select gd;

                break;

            default:
                return(null);
            }

            var groupedData = GetGroupedVehicleQueryable(comparisonType);

            var compData = from gd in groupedData
                           select new ComparisonRow
            {
                Key         = gd.Key,
                FleetCount  = gd.Count(),
                NonRevCount = gd.Sum(d => d.IsNonRev &&
                                     d.DaysSinceLastRevenueMovement >= minDays &&
                                     (selectedMovementTypes == null || selectedMovementTypes.Contains(d.LastMovementTypeId)) &&
                                     (selectedOperStats == null || selectedOperStats.Contains(d.LastOperationalStatusId))
                                    ? 1 : 0),
            };


            var reasonRows = from rd in groupedRemData
                             select new ComparisonRow
            {
                Key            = rd.Key,
                ReasonsEntered = rd.Sum(d => d.ReasonId > 0 ? 1 : 0)
            };

            var returned = compData.ToList();

            foreach (var cr in returned)
            {
                var keyToMatch = cr.Key;
                var reasonRow  = reasonRows.FirstOrDefault(d => d.Key == keyToMatch);
                if (reasonRow == null)
                {
                    continue;
                }

                cr.ReasonsEntered = reasonRow.ReasonsEntered;
            }

            return(returned);
        }
Beispiel #18
0
        public IQueryable <IGrouping <string, VehicleHistory> > GetGroupedVehicleHistoryQuery(DictionaryParameter comparisonType)
        {
            var vehicleHistories = BaseVehicleDataAccess.GetVehicleHistoryQueryable(Parameters, DataContext, true, true);

            if (vehicleHistories == null)
            {
                return(null);
            }


            if (Parameters.ContainsKey(DictionaryParameter.OperationalStatuses))
            {
                if (Parameters[DictionaryParameter.OperationalStatuses] == string.Empty)
                {
                    return(null);
                }
                var selectedOperStats = Parameters[DictionaryParameter.OperationalStatuses].Split(',').Select(int.Parse);

                vehicleHistories = vehicleHistories.Where(d => selectedOperStats.Contains(d.OperationalStatusId));
            }

            if (Parameters.ContainsKey(DictionaryParameter.MovementTypes))
            {
                if (Parameters[DictionaryParameter.MovementTypes] == string.Empty)
                {
                    return(null);
                }
                var selectedMovementTypes = Parameters[DictionaryParameter.MovementTypes].Split(',').Select(int.Parse);
                vehicleHistories = vehicleHistories.Where(d => selectedMovementTypes.Contains(d.MovementTypeId));
            }

            var startDate = Parameters.GetDateFromDictionary(DictionaryParameter.StartDate);

            vehicleHistories = from hd in vehicleHistories
                               where hd.TimeStamp == startDate
                               select hd;

            IQueryable <IGrouping <string, VehicleHistory> > groupedData;

            switch (comparisonType)
            {
            case DictionaryParameter.LocationCountry:
                groupedData = from v in vehicleHistories
                              join l in DataContext.LOCATIONs on v.LocationCode equals l.location1
                              group v by l.COUNTRy1.country_description
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Pool:
                groupedData = from v in vehicleHistories
                              join l in DataContext.LOCATIONs on v.LocationCode equals l.location1
                              group v by l.CMS_LOCATION_GROUP.CMS_POOL.cms_pool1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.LocationGroup:
                groupedData = from v in vehicleHistories
                              join l in DataContext.LOCATIONs on v.LocationCode equals l.location1
                              group v by l.CMS_LOCATION_GROUP.cms_location_group1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Area:
                groupedData = from v in vehicleHistories
                              join l in DataContext.LOCATIONs on v.LocationCode equals l.location1
                              group v by l.OPS_AREA.ops_area1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Region:
                groupedData = from v in vehicleHistories
                              join l in DataContext.LOCATIONs on v.LocationCode equals l.location1
                              group v by l.OPS_AREA.OPS_REGION.ops_region1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.Location:
                groupedData = from v in vehicleHistories
                              join l in DataContext.LOCATIONs on v.LocationCode equals l.location1
                              group v by l.location1
                              into gd
                              select gd;
                break;

            case DictionaryParameter.OwningCountry:
                groupedData = from v in vehicleHistories
                              join cg in DataContext.CAR_GROUPs on
                              new { carG = v.Vehicle.CarGroup, country = v.Vehicle.OwningCountry }
                equals new { carG = cg.car_group1, country = cg.CAR_CLASS.CAR_SEGMENT.country }
                group v by cg.CAR_CLASS.CAR_SEGMENT.COUNTRy1.country_description
                into gd
                select gd;
                break;

            case DictionaryParameter.CarSegment:
                groupedData = from v in vehicleHistories
                              join cg in DataContext.CAR_GROUPs on
                              new { carG = v.Vehicle.CarGroup, country = v.Vehicle.OwningCountry }
                equals new { carG = cg.car_group1, country = cg.CAR_CLASS.CAR_SEGMENT.country }
                group v by cg.CAR_CLASS.CAR_SEGMENT.car_segment1
                into gd
                select gd;
                break;

            case DictionaryParameter.CarClass:
                groupedData = from v in vehicleHistories
                              join cg in DataContext.CAR_GROUPs on
                              new { carG = v.Vehicle.CarGroup, country = v.Vehicle.OwningCountry }
                equals new { carG = cg.car_group1, country = cg.CAR_CLASS.CAR_SEGMENT.country }
                group v by cg.CAR_CLASS.car_class1
                into gd
                select gd;
                break;

            case DictionaryParameter.CarGroup:
                groupedData = from v in vehicleHistories
                              group v by v.Vehicle.CarGroup
                              into gd
                              select gd;

                break;

            case DictionaryParameter.OperationalStatusGrouping:
                groupedData = from v in vehicleHistories
                              group v by v.Operational_Status.OperationalStatusCode
                              into gd
                              select gd;

                break;

            case DictionaryParameter.KciGrouping:
                groupedData = from v in vehicleHistories
                              group v by v.Operational_Status.KCICode
                              into gd
                              select gd;

                break;

            default:
                return(null);
            }
            return(groupedData);
        }
 internal static int GetIdFromDictionary(this Dictionary <DictionaryParameter, string> dictionary, DictionaryParameter key)
 {
     if (dictionary.ContainsKey(key))
     {
         int returned;
         int.TryParse(dictionary[key], out returned);
         return(returned);
     }
     return(0);
 }