public MainWindowViewModel() { server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection( RegisteredTfsConnections.GetProjectCollections().First().Uri); workItemStore = (WorkItemStore)server.GetService(typeof(WorkItemStore)); versionControl = server.GetService<VersionControlServer>(); buildServer = (IBuildServer)server.GetService(typeof(IBuildServer)); historyLoader = new HistoryLoader(versionControl); loadHistoryCommand = new DelegateCommand(LoadHistory); }
private void Button_Click(object sender, RoutedEventArgs e) { HistoryLoader history = new HistoryLoader(); DateTime currentDate = DateTime.Today; var hs = history.LoadHistory(_security.secId, currentDate.AddDays(-60).ToString("yyyy-MM-dd").Replace('.', '-'), currentDate.ToString("yyyy-MM-dd").Replace('.', '-')); var prices = hs.Select(p => (float)p.close).ToArray(); var ml = new MLContext(); var dataView = ml.Data.LoadFromEnumerable(hs); var inputColumnName = "floatClose"; var outputColumnName = nameof(ForecastResult.Forecast); var model = ml.Forecasting.ForecastBySsa(outputColumnName, inputColumnName, 10, 20, prices.Length, 5); var transformer = model.Fit(dataView); var forecastEngine = transformer.CreateTimeSeriesEngine <History, ForecastResult>(ml); var forecast = forecastEngine.Predict(); //последняя точка основного графика: var lastHistoryPoint = new DateModel { DateTime = currentDate = DateTime.Parse(hs.Last().tradeDate), Value = hs.Last().floatClose }; Dispatcher.Invoke(() => { List <DateModel> predictedPrices = new List <DateModel>(); predictedPrices.Add(lastHistoryPoint); for (int i = 0; i < forecast.Forecast.Length; ++i) { DateModel dm = new DateModel { DateTime = currentDate.AddDays(i + 1), Value = forecast.Forecast[i] }; predictedPrices.Add(dm); } var forecastSeries = new LineSeries { Title = "Прогноз", LineSmoothness = 0, PointGeometrySize = 3, PointForeground = Brushes.Red, }; forecastSeries.Values = new ChartValues <DateModel>(predictedPrices); SeriesCollection.Add(forecastSeries); }); }
void LoadHistory() { HistoryLoader history = new HistoryLoader(); var hs = history.LoadHistory(_security.secId, DateTime.Today.AddDays(-60).ToString("yyyy-MM-dd").Replace('.', '-'), DateTime.Today.ToString("yyyy-MM-dd").Replace('.', '-')); var prices = hs.Select(s => new DateModel { DateTime = DateTime.ParseExact(s.tradeDate, "yyyy-MM-dd", CultureInfo.InvariantCulture), Value = s.close }).ToArray(); Dispatcher.Invoke(() => { var series = new LineSeries { Title = "Цена", LineSmoothness = 0, PointGeometrySize = 3, PointForeground = Brushes.Gray }; series.Values = new ChartValues <DateModel>(prices); SeriesCollection.Add(series); }); }