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; }
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); }
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(); }
private static void AddTestData(int branchId, List <DaySegment> listDaySegment, DateTime begin, DateTime end) { //Need to loop through each day //DateTime begin = DateTime.Today.AddDays(-365); //DateTime end = DateTime.Today; int count = 1; List <Transaction> finalTransactionList = new List <Transaction>(); List <DateTime> transactionTimeList = new List <DateTime>(); for (DateTime date = begin; date <= end; date = date.AddDays(1)) { Console.WriteLine(" ------ Day ------------" + count); //Loop through each segment day foreach (var segment in listDaySegment) { Console.WriteLine("-------Segment ---------" + segment.StartTime.ToString() + " To " + segment.EndTime.ToString()); int segmentValue = segment.SegmentRecordCount; int segmentCount = random.Next(segmentValue - 10, segmentValue + 10); //Add records for a segment on a day for (int i = 0; i < segmentCount; i++) { //Get the random transaction time DateTime transactionTime = date.Add(segment.StartTime.Add(new TimeSpan(0, random.Next(1, 120), random.Next(1, 60)))); Console.WriteLine(transactionTime.ToString()); transactionTimeList.Add(transactionTime); } } count++; } transactionTimeList.Sort(); List <Transaction> finalList = GetTransactionList(branchId, transactionTimeList); int transactionCount = finalList.Count; int batchSize = 2000; int j = 0; int batchIterations = transactionCount / batchSize; int remaning = transactionCount % batchSize; Console.WriteLine("Total record count is " + transactionCount); for (int i = 0; i < batchIterations; i++) { DateTime batchStart = DateTime.Now; context.Dispose(); context = new FFCEntities(); context.Configuration.AutoDetectChangesEnabled = false; context.Transactions.AddRange(finalList.GetRange(j, batchSize)); context.SaveChanges(); Console.WriteLine(String.Concat(j, " - ", j + batchSize, " Records inserted. Time Taken = ", (DateTime.Now - batchStart).ToString())); j = j + batchSize; } //Adding remaining records context.Dispose(); context = new FFCEntities(); context.Configuration.AutoDetectChangesEnabled = false; context.Transactions.AddRange(finalList.GetRange(j, remaning - 1)); context.SaveChanges(); Console.WriteLine(String.Concat(finalList.Count, " Transaction Are Updated")); }
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(); }
private static void AddTestData(int branchId, List<DaySegment> listDaySegment, DateTime begin, DateTime end) { //Need to loop through each day //DateTime begin = DateTime.Today.AddDays(-365); //DateTime end = DateTime.Today; int count = 1; List<Transaction> finalTransactionList = new List<Transaction>(); List<DateTime> transactionTimeList = new List<DateTime>(); for (DateTime date = begin; date <= end; date = date.AddDays(1)) { Console.WriteLine(" ------ Day ------------" + count); //Loop through each segment day foreach (var segment in listDaySegment) { Console.WriteLine("-------Segment ---------" + segment.StartTime.ToString() + " To " + segment.EndTime.ToString()); int segmentValue = segment.SegmentRecordCount; int segmentCount = random.Next(segmentValue - 10, segmentValue + 10); //Add records for a segment on a day for (int i = 0; i < segmentCount; i++) { //Get the random transaction time DateTime transactionTime = date.Add(segment.StartTime.Add(new TimeSpan(0, random.Next(1, 120), random.Next(1, 60)))); Console.WriteLine(transactionTime.ToString()); transactionTimeList.Add(transactionTime); } } count++; } transactionTimeList.Sort(); List<Transaction> finalList = GetTransactionList(branchId,transactionTimeList); int transactionCount = finalList.Count; int batchSize = 2000; int j = 0; int batchIterations = transactionCount / batchSize; int remaning = transactionCount % batchSize; Console.WriteLine("Total record count is " + transactionCount); for (int i = 0; i < batchIterations ; i++) { DateTime batchStart = DateTime.Now; context.Dispose(); context = new FFCEntities(); context.Configuration.AutoDetectChangesEnabled = false; context.Transactions.AddRange(finalList.GetRange(j, batchSize)); context.SaveChanges(); Console.WriteLine(String.Concat(j, " - ", j + batchSize, " Records inserted. Time Taken = ", (DateTime.Now - batchStart).ToString())); j = j + batchSize; } //Adding remaining records context.Dispose(); context = new FFCEntities(); context.Configuration.AutoDetectChangesEnabled = false; context.Transactions.AddRange(finalList.GetRange(j, remaning-1)); context.SaveChanges(); Console.WriteLine(String.Concat(finalList.Count, " Transaction Are Updated")); }