Пример #1
0
        public void PredictionZeroTest()
        {
            //arrange
            double[] record = { 100, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0 };

            Algorithum a = new Algorithum(record, 3);

            //act
            double e = a.Prediction(1);

            //assert
            Assert.Zero(e, "The event is lower than expected");
        }
Пример #2
0
        public void SeasonalAdjustment()
        {
            //arrange
            //double[] record = { 72, 110, 117, 172, 76, 112, 130, 194, 78, 119, 128, 201 };
            double[] data = { 72, 110, 117, 172, 76, 112, 130, 194, 78 };

            Algorithum a = new Algorithum(data, 3);

            //act
            double e = a.Prediction(1);

            //assert
            Assert.GreaterOrEqual(e, 136, "The event is lower than expected");
            Assert.LessOrEqual(e, 140, "The event is greater than expected");
        }
Пример #3
0
        public void DecimalTest()
        {
            //arrange
            double[] record = { 72, 110, 117, 172, 76, 112, 130, 194, 78, 119, 128, 201 };

            Algorithum a = new Algorithum(record, 3);

            //act
            double e = a.Prediction(1);

            string[] res       = e.ToString().Split('.');
            int      precision = res[1].Length;

            //assert
            Assert.IsTrue(precision == 3, "The precision is not to 3 decimal places");
        }
Пример #4
0
        //protected void btnDownload_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("PathToHttpHandler/DownloadFile.ashx");
        //}

        // GET: Report/Prediction?q=m|w
        public ActionResult Prediction(Guid?ProductID, int?Type)
        {
            PredictionChartViewModel chart = new PredictionChartViewModel();
            DateTime beginRange;

            if (ProductID == null || Type == null)
            {
                return(View(chart));
            }
            if (Type == (int)PredictType.MONTHLY && ProductID != null)
            {
                using (var ctx = new SalesDbContext())
                {
                    chart.Name      = "Monthly Sales Report";
                    chart.ProductID = (Guid)ProductID;
                    chart.Product   = ctx.Products.Where(x => x.ID == ProductID).FirstOrDefault();

                    chart.Type = PredictType.MONTHLY;

                    chart.Start = DateTime.Today.AddDays(-DateTime.Now.DayOfYear + 1);
                    chart.End   = chart.Start.AddYears(+2).AddDays(-1);

                    beginRange = DateTime.Today.AddDays(-DateTime.Now.DayOfYear + 1);

                    var sales = ctx.Sales.Where(x => x.Product.ID == ProductID)
                                .Where(x => x.Transaction.SaleTime >= beginRange)
                                .ToList();

                    List <double> list  = new List <double>();
                    DateTime      check = beginRange;
                    do
                    {
                        list.Add((double)sales
                                 .Where(x => x.Transaction.SaleTime.Date >= check)
                                 .Where(x => x.Transaction.SaleTime.Date < check.AddMonths(1))
                                 .Sum(i => i.QTY));
                        check = check.AddMonths(1);
                    } while (check <= chart.End);

                    Algorithum algorithum = new Algorithum(list.ToArray(), 3);

                    check = chart.Start;
                    int PredictCount = 0;
                    do
                    {
                        if (check <= DateTime.Today)
                        {
                            chart.CurrentCycle.Add(check.Date, new PredictModel()
                            {
                                Value = (double)sales.Where(x => x.Transaction.SaleTime.Date >= check)
                                        .Where(x => x.Transaction.SaleTime.Date < check.AddMonths(1))
                                        .Sum(i => i.QTY),
                                IsPredict = false
                            });
                        }
                        else if (check < chart.Start.AddYears(1))
                        {
                            chart.CurrentCycle.Add(check, new PredictModel()
                            {
                                Value     = algorithum.Prediction(++PredictCount),
                                IsPredict = true
                            });
                        }
                        else
                        {
                            chart.NextCycle.Add(check, new PredictModel()
                            {
                                Value     = algorithum.Prediction(++PredictCount),
                                IsPredict = true
                            });
                        }
                        check = check.AddMonths(1);
                    } while (check < chart.Start.AddYears(2));
                }
            }
            else
            {
                using (var ctx = new SalesDbContext())
                {
                    chart.Name      = "Weekly Sales Report";
                    chart.ProductID = (Guid)ProductID;
                    chart.Product   = ctx.Products.Where(x => x.ID == ProductID).FirstOrDefault();

                    chart.Type = PredictType.WEEKLY;

                    chart.Start = DateTime.Today.AddDays(-(int)DateTime.Now.DayOfWeek);
                    chart.End   = chart.Start.AddDays(14);

                    beginRange = DateTime.Today.AddDays((double)(DateTime.Now.DayOfWeek - 35));

                    var sales = ctx.Sales.Where(x => x.Product.ID == ProductID)
                                .Where(x => x.Transaction.SaleTime >= beginRange)
                                .ToList();

                    List <double> list  = new List <double>();
                    DateTime      check = beginRange;
                    do
                    {
                        list.Add((double)sales.Where(x => x.Transaction.SaleTime.Date == check).Sum(i => i.QTY));
                        check = check.AddDays(1);
                    } while (check <= chart.End);

                    Algorithum algorithum = new Algorithum(list.ToArray(), 7);

                    check = chart.Start;
                    int PredictCount = 0;
                    do
                    {
                        if (check <= DateTime.Today)
                        {
                            chart.CurrentCycle.Add(check.Date, new PredictModel()
                            {
                                Value     = (double)sales.Where(x => x.Transaction.SaleTime.Date == check).Sum(i => i.QTY),
                                IsPredict = false
                            });
                        }
                        else if (check < chart.Start.Date.AddDays(7))
                        {
                            chart.CurrentCycle.Add(check, new PredictModel()
                            {
                                Value     = algorithum.Prediction(++PredictCount),
                                IsPredict = true
                            });
                        }
                        else
                        {
                            chart.NextCycle.Add(check, new PredictModel()
                            {
                                Value     = algorithum.Prediction(++PredictCount),
                                IsPredict = true
                            });
                        }
                        check = check.AddDays(1);
                    } while (check < chart.Start.AddDays(14));
                }
            }

            return(View(chart));
        }