示例#1
0
 public async void Delete(DashboardPrediction prediction)
 {
     if (await this.PersistenceService.DeleteStockWithId(prediction.StockId))
     {
         Messenger.Default.Send(new TrainStatusMessage($"Deleted {prediction.Name}"));
         this.Refresh();
     }
     else
     {
         Messenger.Default.Send(new TrainStatusMessage($"Could not delete {prediction.Name}"));
     }
 }
示例#2
0
 public void NavigateToTrainView(DashboardPrediction prediction)
 {
     this.NavigationService.Navigate("TrainView", null, prediction, this, true);
 }
示例#3
0
        private async Task LoadData()
        {
            try
            {
                if (this._cancellationTokenSource != null && this._cancellationTokenSource.Token.CanBeCanceled && !this._cancellationTokenSource.IsCancellationRequested)
                {
                    this._cancellationTokenSource.Cancel();
                    return;
                }

                this._cancellationTokenSource = new CancellationTokenSource();

                this.IsBusy = true;

                await this.LoadSettings().ConfigureAwait(false);

                this.SetPortfolio();

                // get list of all saved predictions
                var listBestPredictionsDtos = await this.PersistenceService.GetBestNetworkDTOs().ConfigureAwait(false);

                this.Predictions = new ObservableCollection <DashboardPrediction>();

                // for each
                foreach (var dto in listBestPredictionsDtos)
                {
                    if (this._cancellationTokenSource.Token.IsCancellationRequested)
                    {
                        return;
                    }

                    var stock = await this.PersistenceService.GetStockFromId(dto.StockId);

                    stock.HistoricalData = await this.DownloaderService.GetHistoricalData(stock, this._settings.StartDate, DateTime.Now, true).ConfigureAwait(false);

                    var dashboardPrediction = new DashboardPrediction {
                        Symbol = stock.Symbol, Name = stock.Name, StockId = stock.GetUniqueId()
                    };

                    lock (Locker)
                    {
                        Application.Current.Dispatcher?.Invoke(() => this.Predictions.Add(dashboardPrediction));
                    }

                    TrainingSession trainingSession;
                    try
                    {
                        trainingSession = await Task.Run(() => new TrainingSession(this.Portfolio, stock, dto, this._settings)).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        Messenger.Default.Send(new TrainStatusMessage($"Could setup training session for stock {stock.Name}: {ex.Message}", SeverityEnum.Error));
                        trainingSession = new TrainingSession(this.Portfolio, stock);
                    }

                    dashboardPrediction.TrainingSession  = trainingSession;
                    dashboardPrediction.Close            = trainingSession.Stock.HistoricalData?.Quotes?.LastOrDefault().Value?.Close ?? 0d;
                    dashboardPrediction.LastTrainingDate = dto.Timestamp;

                    if (trainingSession.Stock.HistoricalData != null)
                    {
                        dashboardPrediction.LastUpdate = trainingSession.Stock.HistoricalData.EndDate;
                    }
                }
            }
            finally
            {
                this.IsBusy = false;
                this._cancellationTokenSource = null;
            }
        }
示例#4
0
 public bool CanDelete(DashboardPrediction prediction)
 {
     return(prediction != null);
 }