public void Acceptance()
        {
            const int NUMBER_OF_SIMULATIONS   = 1000;
            const int GRANULARITY_OF_FORECAST = 20;

            var repo        = new HistoryRepository(REPO_PATH);
            var forecasting = new Forecasting(new MonteCarloSimulation(), NUMBER_OF_SIMULATIONS, GRANULARITY_OF_FORECAST);
            var sut         = new RequestHandler(repo, forecasting);

            var newHistory = new NewHistoryDto {
                Id             = "abc",
                Name           = "test history",
                Email          = "*****@*****.**",
                HistoricalData = new[] {
                    new DatapointDto {
                        Value = 1f, Tags = new[] { "a" }
                    },
                    new DatapointDto {
                        Value = 2f, Tags = new[] { "a" }
                    }
                },
                HistoricalDataToParse = "2;a,x\n3;a\n3;a\n4;a\n10;b,x\n10;b\n20;b\n20;b\n30;b,x"
            };

            var historyId = sut.Create_history(newHistory);

            Assert.AreEqual("abc", historyId);

            var history = sut.Load_history_by_id(historyId);

            Assert.AreEqual("test history", history.Name);
            Assert.AreEqual(11, history.HistoricalData.Length);
            Assert.AreEqual(new[] { "a", "b", "x" }, history.Tags);

            history = sut.Load_history_by_name("test history");

            Assert.AreEqual("*****@*****.**", history.Email);

            var forecast = sut.Calculate_forecast(historyId,
                                                  new[] {
                new FeatureDto {
                    Quantity = 2, Tags = new[] { "a" }
                },
                new FeatureDto {
                    Quantity = 1, Tags = new[] { "b" }
                },
            });

            // only prognosises with p>=0.5
            Assert.IsTrue(forecast.Distribution.Select(p => p.Count).Sum() >= 500);
        }
        public string Create_history(NewHistoryDto newhistory)
        {
            var parsedData = HistoricalCsvDataParser.Parse(newhistory.HistoricalDataToParse);

            var history = new History {
                Id             = newhistory.Id,
                Email          = newhistory.Email,
                Name           = newhistory.Name,
                HistoricalData = newhistory.HistoricalData.Select(d => new History.Datapoint {
                    Value = d.Value, Tags = d.Tags
                })
                                 .Concat(parsedData)
                                 .ToArray(),
                LastUsed = DateTime.Now.ToUniversalTime()
            };

            return(_repo.Store_history(history));
        }
Пример #3
0
        public string Create_history([Payload] NewHistoryDto newhistory)
        {
            Console.WriteLine($"create history: {newhistory.Id}, {newhistory.Name}, {newhistory.Email}, historical data: {newhistory.HistoricalData.Length}");

            return(__RequestHandler().Create_history(newhistory));
        }