コード例 #1
0
        public void CalcualteLimits()
        {
            var parameters = ucParameters.GetParameters();

            parameters[DictionaryParameter.StartDate] = (new DateTime(2015, 2, 7)).ToShortDateString();
            List <DemandGapOneRow> demandGapData;

            var sb = new StringBuilder();

            using (var dataAccess = new DemandGapDataAccess(parameters))
            {
                var data = dataAccess.GetDemandGapStepOne();
                //var data2 = dataAccess.GetDemandGapOne(data);
                //var data2 = dataAccess.GetDemandGapStepOneViz();
                //ucDgVis.GridData = data2.ToList();

                demandGapData = data.ToList();
                DemandGapCalculations.CalculateGap(demandGapData);
                demandGapData = demandGapData.ToList();
                ucDemanGapStageOneGrid.GridData = demandGapData;


                //ucDemandGapOne.GridData = data2;

                //var spread = dataAccess.GetSpreadForLocation();
                // ucSpread.GridData = spread;
            }

            List <MonthlyLimitRow> monthlyData;
            List <WeeklyLimitRow>  weeklyData;

            using (var dataAccess = new MonthlyAddLimitDataAccess())
            {
                monthlyData = dataAccess.GetMonthlyLimitRows(2);
                weeklyData  = dataAccess.GetWeekLyLimitRows(3);
            }

            using (var dataAccess = new VehicleDistributionDataAccess())
            {
                if (parameters[DictionaryParameter.CarGroup] != string.Empty &&
                    (!parameters[DictionaryParameter.CarClass].Contains(LocationQueryable.Separator)))
                {
                    var carClassId = int.Parse(parameters[DictionaryParameter.CarClass]);
                    using (var lookup = new LookupDataAccess())
                    {
                        var splitCarGroupIds = lookup.FindCarGroupsInCarClass(carClassId);
                        monthlyData = monthlyData.Where(d => splitCarGroupIds.Contains(d.GetCarGroupId())).ToList();
                    }
                }

                var calculatedAdds = DemandGapCalculations.AssignGroupOne(demandGapData, monthlyData, weeklyData);
                sb.AppendLine("Additions Step 1 Generated:" + calculatedAdds.Sum(d => d.Amount));
                DemandGapCalculations.FillGapsFromMonthlyLimits(demandGapData, monthlyData, weeklyData, calculatedAdds);
                sb.AppendLine("Additions Step 1.1 Generated:" + calculatedAdds.Sum(d => d.Amount));

                dataAccess.FillNames(calculatedAdds);

                ucResult.GridData = calculatedAdds;
            }

            //ucDemanGapStageOneGrid.UpdateUpdatePanel();
            //ucDemandGapOne.UpdateUpdatePanel();

            ucMonthlyLimit.LoadData(monthlyData);
            ucWeeklyLimit.LoadData(weeklyData);


            sb.AppendLine("Total Monthly assigned:" + monthlyData.Sum(d => d.Assigned));
            sb.AppendLine("Total Weekly assigned:" + weeklyData.Sum(d => d.Assigned));
            Session[FaoCalculationTextSummary] = sb.ToString();

            Session[FaoCalculationStarted] = "Finished";
        }
コード例 #2
0
        public void CalcualteLimits()
        {
            try
            {
                var parameters = ucParameters.GetParameters();
                List <WeeklyMaxMinValues> demandGapData;
                var      sb = new StringBuilder();
                var      stepToCalculateTo = int.Parse(ddlStage.SelectedValue);
                DateTime currentDay;

                using (var dataAccess = new DemandGapDataAccess(parameters))
                {
                    currentDay = dataAccess.GetLastHistoryTimestamp();
                    var weeksToCalculate = int.Parse(tbWeeks.Text);

                    //Constant 12 weeks for history calculations
                    parameters[DictionaryParameter.StartDate]         = (currentDay.AddDays(-84)).ToShortDateString();
                    parameters[DictionaryParameter.EndDate]           = (currentDay).ToShortDateString();
                    parameters[DictionaryParameter.ForecastStartDate] = (currentDay).ToShortDateString();

                    var endDate = currentDay.AddDays(weeksToCalculate * 7).Next(DayOfWeek.Sunday);
                    parameters[DictionaryParameter.ForecastEndDate] = (endDate).ToShortDateString();

                    var minComSegScenarioId      = int.Parse(ddlMinCommSeg.SelectedValue);
                    var maxFleetFactorScenarioId = int.Parse(ddlMaxFleetFactor.SelectedValue);

                    demandGapData = dataAccess.CalculateMinMax(minComSegScenarioId, maxFleetFactorScenarioId, 0);


                    ucDgcProgress.CurrentProgress = DemandGapCalculationStep.CalculateMinAndMax;
                    var sw = new Stopwatch();
                    sw.Start();
                    DemandGapOneCalculations.CalculateGap(demandGapData);

                    demandGapData = demandGapData.ToList();
                    sw.Stop();
                    var xx = sw.Elapsed;

                    sw.Reset();
                    sw.Start();
                    var rankingData = dataAccess.GetFinanceEntities();
                    sw.Stop();
                    var yy = sw.Elapsed;
                    sw.Reset();
                    sw.Start();
                    DemandGapOneCalculations.AttachRankingsToDemandGaps(demandGapData, rankingData);

                    sw.Stop();
                    var zz = sw.Elapsed;
                    sw.Reset();
                    sw.Start();

                    demandGapData = demandGapData.OrderBy(d => d.RankFromRevenue).ToList();
                    sw.Stop();
                    var qq = sw.Elapsed;
                    ucDemanGapStageOneGrid.GridData = demandGapData;
                }

                List <MonthlyLimitRow> monthlyData;
                List <WeeklyLimitRow>  weeklyData;

                int?carSegmentId = null;
                if (parameters.ContainsValueAndIsntEmpty(DictionaryParameter.CarSegment))
                {
                    carSegmentId = int.Parse(parameters[DictionaryParameter.CarSegment]);
                }

                using (var dataAccess = new MonthlyAddLimitDataAccess())
                {
                    monthlyData = dataAccess.GetMonthlyLimitRows(carSegmentId, currentDay);
                    weeklyData  = dataAccess.GetWeekLyLimitRows(carSegmentId, currentDay);
                }

                using (var dataAccess = new VehicleDistributionDataAccess())
                {
                    if (parameters[DictionaryParameter.CarGroup] != string.Empty &&
                        (!parameters[DictionaryParameter.CarClass].Contains(LocationQueryable.Separator)))
                    {
                        var carClassId = int.Parse(parameters[DictionaryParameter.CarClass]);
                        using (var lookup = new LookupDataAccess())
                        {
                            var splitCarGroupIds = lookup.FindCarGroupsInCarClass(carClassId);
                            monthlyData = monthlyData.Where(d => splitCarGroupIds.Contains(d.GetCarGroupId())).ToList();
                        }
                    }

                    ucDgcProgress.CurrentProgress = DemandGapCalculationStep.StepOneCarGroup;
                    var calculatedAdds = DemandGapOneCalculations.FillGapOneCarGroup(demandGapData, monthlyData,
                                                                                     weeklyData);

                    sb.AppendLine("Additions Step 1 Generated:" + calculatedAdds.Sum(d => d.Amount));

                    if (stepToCalculateTo > 1)
                    {
                        ucDgcProgress.CurrentProgress = DemandGapCalculationStep.StepOneCarClass;
                        DemandGapOneCalculations.FillGapOneCarClass(demandGapData, monthlyData, weeklyData,
                                                                    calculatedAdds);
                        sb.AppendLine("Additions Step 1.1 Generated:" + calculatedAdds.Sum(d => d.Amount));
                    }

                    if (stepToCalculateTo > 2)
                    {
                        ucDgcProgress.CurrentProgress = DemandGapCalculationStep.StepTwoCarGroup;
                        DemandGapOneCalculations.FillGapTwoCarGroup(demandGapData, monthlyData, weeklyData,
                                                                    calculatedAdds);
                        sb.AppendLine("Additions Step 2 Generated:" + calculatedAdds.Sum(d => d.Amount));
                    }

                    if (stepToCalculateTo > 3)
                    {
                        ucDgcProgress.CurrentProgress = DemandGapCalculationStep.StepTwoCarClass;
                        DemandGapOneCalculations.FillGapTwoCarClass(demandGapData, monthlyData, weeklyData,
                                                                    calculatedAdds);
                        sb.AppendLine("Additions Step 2.1 Generated:" + calculatedAdds.Sum(d => d.Amount));
                    }


                    dataAccess.FillNames(calculatedAdds);


                    var distinctContributionData = from dgd in demandGapData
                                                   group dgd by new { CarGroupId = dgd.GetCarGroupId(), LocationId = dgd.GetLocationId() }
                    into groupedData
                        select new
                    {
                        groupedData.Key.CarGroupId,
                        groupedData.Key.LocationId,
                        groupedData.First().Contribution
                    };
                    var additionEntities = from ca in calculatedAdds
                                           join dgd in distinctContributionData on new { ca.CarGroupId, ca.LocationId }
                    equals new { dgd.CarGroupId, dgd.LocationId }
                    into jdgd
                    from joinedDcd in jdgd.DefaultIfEmpty()
                    select new AdditionEntity
                    {
                        Year         = ca.Year,
                        IsoWeek      = ca.IsoWeek,
                        CarGroupId   = ca.CarGroupId,
                        LocationId   = ca.LocationId,
                        CarGroup     = ca.CarGroup,
                        Location     = ca.Location,
                        Amount       = ca.Amount,
                        Contribution = joinedDcd == null ? 0 : (double)joinedDcd.Contribution
                    };

                    ucResult.GridData = additionEntities.ToList();
                }
                ucMonthlyLimit.LoadData(monthlyData);
                ucWeeklyLimit.LoadData(weeklyData);

                sb.AppendLine("Total Monthly assigned: " + monthlyData.Sum(d => d.Assigned));
                sb.AppendLine("Total Weekly assigned: " + weeklyData.Sum(d => d.Assigned));
                SummaryText = sb.ToString();

                ucDgcProgress.CurrentProgress = DemandGapCalculationStep.Complete;
            }
            catch (Exception e)
            {
                SummaryText = e.ToString();
                ucDgcProgress.CurrentProgress = DemandGapCalculationStep.Error;
            }
        }