コード例 #1
0
ファイル: RTest.cs プロジェクト: ashenfern/FFCF_Application
        public static List<double> GetCorrespondingData(Enums.Data data, int productId)
        {
            FFCEntities db = new FFCEntities();
            List<double> values  = new List<double>();

            if (data == Enums.Data.Daily)
            {
                var list = db.sp_Forecast_GetProductCountYearDayByProductId(productId).ToList();
                values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();
            }
            else if (data == Enums.Data.Day)
            {
                var list = db.sp_Forecast_GetProductCountDayByProductId(productId).ToList();
                values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();
            }

            return values;
        }
コード例 #2
0
        public static List <double> GetCorrespondingData(DataPeriod data, int productId)
        {
            FFCEntities   db     = new FFCEntities();
            List <double> values = new List <double>();

            if (data == DataPeriod.Daily)
            {
                var list = db.sp_Forecast_GetProductCountYearDayByProductId(productId).ToList();
                values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();
            }
            else if (data == DataPeriod.Day)
            {
                var list = db.sp_Forecast_GetProductCountDayByProductId(productId).ToList();
                values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();
            }

            return(values);
        }
コード例 #3
0
        public static void TestMethod2()
        {
            FFCEntities db   = new FFCEntities();
            var         list = db.sp_Forecast_GetProductCountYearDayByProductId(1).ToList();

            List <double> values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();

            REngine.SetEnvironmentVariables();
            // There are several options to initialize the engine, but by default the following suffice:
            REngine engine = REngine.GetInstance();

            // .NET Framework array to R vector.
            NumericVector testTs = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99, 1000 });

            //NumericVector testTs = engine.CreateNumericVector(new double[] { 1,2,3,4,5,6});
            //NumericVector testTs = engine.CreateNumericVector(values);

            //DataFrame datafrate = engine.CreateDataFrame(new List<string> { },);

            engine.SetSymbol("testTs", testTs);

            // Direct parsing from R script.
            //NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();

            //auto arima for monthly
            engine.Evaluate("tsValue <- ts(testTs, frequency=1, start=c(2010, 1, 1))");
            engine.Evaluate("library(forecast)");
            engine.Evaluate("arimaFit <- Arima(tsValue)");
            engine.Evaluate("fcast <- forecast(tsValue, h=5)");

            var           a         = engine.Evaluate("fcast <- forecast(tsValue, h=5)").AsCharacter();
            NumericVector forecasts = engine.Evaluate("fcast$mean").AsNumeric();

            foreach (var item in forecasts)
            {
                Console.WriteLine(item);
            }

            engine.Dispose();
        }
コード例 #4
0
ファイル: RTest.cs プロジェクト: ashenfern/FFCF_Application
        public static void TestMethod2()
        {
            FFCEntities db = new FFCEntities();
            var list = db.sp_Forecast_GetProductCountYearDayByProductId(1).ToList();

            List<double> values = list.Select(r => Double.Parse(r.Count.ToString())).ToList();

            REngine.SetEnvironmentVariables();
            // There are several options to initialize the engine, but by default the following suffice:
            REngine engine = REngine.GetInstance();

            // .NET Framework array to R vector.
            NumericVector testTs = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99, 1000 });
            //NumericVector testTs = engine.CreateNumericVector(new double[] { 1,2,3,4,5,6});
            //NumericVector testTs = engine.CreateNumericVector(values);

            //DataFrame datafrate = engine.CreateDataFrame(new List<string> { },);

            engine.SetSymbol("testTs", testTs);

            // Direct parsing from R script.
            //NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric();

            //auto arima for monthly
            engine.Evaluate("tsValue <- ts(testTs, frequency=1, start=c(2010, 1, 1))");
            engine.Evaluate("library(forecast)");
            engine.Evaluate("arimaFit <- Arima(tsValue)");
            engine.Evaluate("fcast <- forecast(tsValue, h=5)");

            var a = engine.Evaluate("fcast <- forecast(tsValue, h=5)").AsCharacter();
            NumericVector forecasts = engine.Evaluate("fcast$mean").AsNumeric();

            foreach (var item in forecasts)
            {
                Console.WriteLine(item);
            }

            engine.Dispose();
        }