// public void AddToDb() { List <RequestResult> file = ParserTxtToResult.Parse(@"C:\Users\rafae\OneDrive\Рабочий стол\res.txt"); foreach (var item in file) { db.RequestResults.Add(item); } db.SaveChanges(); }
public async Task GetLastResultForDiffAsync_includes_differences() { // Arrange var expectedResult = new DiffResult { Id = Guid.NewGuid(), Differences = new InputDifference[] { new InputDifference(1, 2), new InputDifference(5, 6), new InputDifference(12, 4) } }; var options = new DbContextOptionsBuilder <ResultContext>() .UseInMemoryDatabase("resultsDb_notEmpty") .Options; var context = new ResultContext(options); var repository = new DiffResultsRepository(context); context.DiffResults.Add(expectedResult); context.SaveChanges(); // Act var result = await repository.GetLastResultForDiffAsync(expectedResult.DiffId); // Assert Assert.NotEmpty(result.Differences); Assert.All(result.Differences, diff => expectedResult.Differences.Contains(diff)); }
public MainWindow() { InitializeComponent(); db.RequestResults.Add(new RequestResult { Desctription = "Desct", Source = "Google", Url = "url.com" }); db.SaveChanges(); }
private void emtpyResultDBbySimulationNumber(SimulationNumber simNr) { var _simNr = simNr; using (_ctxResult) { _ctxResult.RemoveRange(entities: _ctxResult.SimulationJobs.Where(predicate: a => a.SimulationNumber.Equals(_simNr.Value))); _ctxResult.RemoveRange(entities: _ctxResult.Kpis.Where(predicate: a => a.SimulationNumber.Equals(_simNr.Value))); _ctxResult.RemoveRange(entities: _ctxResult.StockExchanges.Where(predicate: a => a.SimulationNumber.Equals(_simNr.Value))); _ctxResult.SaveChanges(); } }
public void CalculationResultDbInsertion(double firstOperand, string operatorSymbol, double secondOperand, double result) { using (var dbContext = new ResultContext()) { var calculation = new CalculationResult() { FirstOperand = firstOperand, OperatorSymble = operatorSymbol, SecondOperand = secondOperand, Result = result }; dbContext.Calculations.Add(calculation); dbContext.SaveChanges(); } }
public void BuildResults(int forId) { // return new Task(() => // { var toRemove = _resultCtx.Kpis.Where(x => x.KpiType == KpiType.AverageResult && x.SimulationConfigurationId == forId); _resultCtx.Kpis.RemoveRange(toRemove); _resultCtx.SaveChanges(); var toAdd = new List <Kpi>(); toAdd.Add(Timeliness(forId)); toAdd.Add(StockTotals(forId)); toAdd.Add(ThroughPutTimes(forId)); toAdd.Add(Utilization(forId)); toAdd.Add(Setup(forId)); toAdd.Add(CompletedOrders(forId)); _resultCtx.Kpis.AddRange(toAdd); _resultCtx.SaveChanges(); // }); }
public static void ConvertBackAndSave(ResultContext resultCtx, Configuration config, int simulationNumber) { var configs = new List <SimulationConfig>(); foreach (var item in config) { configs.Add(new SimulationConfig() { Property = item.Key.Name, PropertyValue = ((dynamic)item.Value).Value.ToString(), SimulationNumber = simulationNumber }); } resultCtx.SimulationConfigs.AddRange(configs); resultCtx.SaveChanges(); }
private static void CreateSimulation(ResultContext context, List <ConfigurationItem> items, string description) { _simulationId++; var configurationItems = new List <ConfigurationItem> { new ConfigurationItem { Property = "SimulationId", PropertyValue = _simulationId.ToString(), Description = description }, }; items.ForEach(x => configurationItems.Add(x)); context.ConfigurationItems.AddRange(configurationItems); context.SaveChanges(); AssertConfigurations(context, configurationItems, _simulationId); }
private static void AssertConfigurations(ResultContext context, List <ConfigurationItem> configurationItems, int simulationId) { var configurationRelations = new List <ConfigurationRelation>(); var simId = int.Parse(configurationItems.Single(x => x.Property == "SimulationId").PropertyValue); foreach (var item in configurationItems) { if (item.Id != 1) { configurationRelations.Add(new ConfigurationRelation { ParentItemId = simId, ChildItemId = item.Id, Id = simulationId }); } } context.ConfigurationRelations.AddRange(entities: configurationRelations); context.SaveChanges(); }
public async Task GetLastResultForDiffAsync_returns_last_result_for_a_given_diff_id() { // Arrange var expectedResult = new DiffResult { Id = Guid.NewGuid(), Timestamp = DateTime.Parse("2019-01-01") }; var options = new DbContextOptionsBuilder <ResultContext>() .UseInMemoryDatabase("resultsDb_lastResult") .Options; var context = new ResultContext(options); var repository = new DiffResultsRepository(context); context.DiffResults.AddRange(new DiffResult[] { new DiffResult { Id = Guid.NewGuid(), DiffId = expectedResult.DiffId, Timestamp = expectedResult.Timestamp.AddMilliseconds(-1) }, expectedResult, new DiffResult { Id = Guid.NewGuid(), DiffId = expectedResult.DiffId, Timestamp = expectedResult.Timestamp.AddHours(-1) }, new DiffResult { Id = Guid.NewGuid(), DiffId = expectedResult.DiffId, Timestamp = expectedResult.Timestamp.AddMinutes(-1) }, new DiffResult { Id = Guid.NewGuid(), DiffId = expectedResult.DiffId, Timestamp = expectedResult.Timestamp.AddSeconds(-1) }, new DiffResult { Id = Guid.NewGuid(), DiffId = Guid.NewGuid(), Timestamp = expectedResult.Timestamp } }); context.SaveChanges(); // Act var result = await repository.GetLastResultForDiffAsync(expectedResult.DiffId); // Assert Assert.Equal(result.Id, expectedResult.Id); Assert.Equal(result.Timestamp, expectedResult.Timestamp); Assert.Equal(result.DiffId, expectedResult.DiffId); }
public ActionResult Index(Calculate c, int FN, int SN, double TN, string calculate) { using (ResultContext db = new ResultContext()) { if (calculate == "add") { double i = (double)TN / 12 / 100; n = SN; double k = (i * Math.Pow(1 + i, n)) / (Math.Pow(1 + i, n) - 1); summ = (double)FN * k; total = summ; DateTime date = DateTime.Now; int id = 1; double AmountBody = total; double AmountPrecent = (double)FN / n; double remain = FN; for (int l = 0; l < n; l++) { Result p = new Result { id = id, date = date, AmountBody = AmountBody, AmountPercent = AmountPrecent, Remain = remain }; id++; date = date.AddDays(30); remain = remain - total; db.Results.Add(p); db.SaveChanges(); } c.result = total; } return(View(c)); } }
public static void DbInitialize(ResultContext context) { context.Database.EnsureCreated(); if (context.ConfigurationItems.Any()) { return; // DB has been seeded } var configurationItems = new List <ConfigurationItem>() { new ConfigurationItem { Property = "SimulationId", PropertyValue = _simulationId.ToString(), Description = "selfOrganizing with normal Queue" }, new ConfigurationItem { Property = "SimulationNumber", PropertyValue = "1", Description = "Default" }, new ConfigurationItem { Property = "SimulationKind", PropertyValue = "Default", Description = "Default" }, new ConfigurationItem { Property = "OrderArrivalRate", PropertyValue = "0,025", Description = "Default" }, new ConfigurationItem { Property = "OrderQuantity", PropertyValue = "1500", Description = "Default" }, new ConfigurationItem { Property = "EstimatedThroughPut", PropertyValue = "1920", Description = "Default" }, new ConfigurationItem { Property = "DebugAgents", PropertyValue = "false", Description = "Default" }, new ConfigurationItem { Property = "DebugSystem", PropertyValue = "false", Description = "Default" }, new ConfigurationItem { Property = "KpiTimeSpan", PropertyValue = "480", Description = "Default" }, new ConfigurationItem { Property = "MinDeliveryTime", PropertyValue = "1440", Description = "Default" }, new ConfigurationItem { Property = "MaxDeliveryTime", PropertyValue = "2400", Description = "Default" }, new ConfigurationItem { Property = "TransitionFactor", PropertyValue = "3", Description = "Default" }, new ConfigurationItem { Property = "MaxBucketSize", PropertyValue = "960", Description = "Default" }, new ConfigurationItem { Property = "TimePeriodForThroughputCalculation", PropertyValue = "1920", Description = "Default" }, new ConfigurationItem { Property = "Seed", PropertyValue = "1337", Description = "Default" }, new ConfigurationItem { Property = "SettlingStart", PropertyValue = "2880", Description = "Default" }, new ConfigurationItem { Property = "SimulationEnd", PropertyValue = "40320", Description = "Default" }, new ConfigurationItem { Property = "WorkTimeDeviation", PropertyValue = "0.2", Description = "Default" }, new ConfigurationItem { Property = "SaveToDB", PropertyValue = "true", Description = "Default" }, new ConfigurationItem { Property = "TimeToAdvance", PropertyValue = "0", Description = "Default" }, }; context.ConfigurationItems.AddRange(entities: configurationItems); context.SaveChanges(); AssertConfigurations(context, configurationItems, _simulationId); CreateSimulation(context, new List <ConfigurationItem> { new ConfigurationItem { Property = "OrderArrivalRate", PropertyValue = "0,0275" } }, "Higher Arrival Rate"); CreateSimulation(context, new List <ConfigurationItem> { new ConfigurationItem { Property = "OrderArrivalRate", PropertyValue = "0,02" } }, "Lower Arrival Rate"); CreateSimulation(context, new List <ConfigurationItem> { new ConfigurationItem { Property = "OrderArrivalRate", PropertyValue = "0,01" } }, "Super low Arrival Rate"); CreateSimulation(context, new List <ConfigurationItem> { new ConfigurationItem { Property = "EstimatedThroughPut", PropertyValue = "1440" } }, "Estimated Throguh Put: 1440"); _simulationId = 1; }
public static void DbInitialize(ResultContext context) { context.Database.EnsureCreated(); if (context.SimulationConfigurations.Any()) { return; // DB has been seeded } var simConfigs = new List <SimulationConfiguration>(); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 1 Name = "Lot 5, 24h, 24h, 0.2", Lotsize = 5, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.2 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 2 Name = "Lot 10, 24h, 24h, 0.2", Lotsize = 10, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.2 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 3 Name = "Lot 1, 8h, 8h, 0.2", Lotsize = 1, MaxCalculationTime = 480, OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 480, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.2 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 4 Name = "Lot 1, 28h, 24h, 0.2", Lotsize = 1, MaxCalculationTime = 1680, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.2 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 5 Name = "Lot 1, 24h, 24h, 0", Lotsize = 1, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.0 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 6 Name = "Lot 1, 24h, 24h, 0.2", Lotsize = 1, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.2 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 7 Name = "Lot 1, 24h, 24h, 0.4", Lotsize = 1, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.4 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 8 Name = "decentral dev 0", Lotsize = 1, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.0 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 9 Name = "decentral dev 0.2", Lotsize = 1, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.2 }); simConfigs.Add(item: new SimulationConfiguration() { //simconfigId = 10 Name = "decentral dev 0.4", Lotsize = 1, MaxCalculationTime = 1440, // test // 10080, // 7 days OrderQuantity = 600, Seed = 1340, ConsecutiveRuns = 1, OrderRate = 0.25, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 20160, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 2880, WorkTimeDeviation = 0.4 }); simConfigs.Add(item: new SimulationConfiguration { Name = "Test config", Lotsize = 1, MaxCalculationTime = 480, // test // 10080, // 7 days OrderQuantity = 550, Seed = 1338, ConsecutiveRuns = 1, OrderRate = 0.025, //0.25 Time = 0, RecalculationTime = 1440, SimulationEndTime = 21000, DecentralRuns = 0, CentralRuns = 0, DynamicKpiTimeSpan = 480, SettlingStart = 0, WorkTimeDeviation = 0 }); context.SimulationConfigurations.AddRange(entities: simConfigs); context.SaveChanges(); }