Fix the LoadSessionFile method so that the BusyIndicator is displayed with the correct content.

This commit is contained in:
2025-02-18 19:09:20 -05:00
parent f0b765c5c8
commit 6fcb5f63ba
3 changed files with 149 additions and 93 deletions

View File

@@ -28,6 +28,7 @@ using Position = MarketData.Generator.CMMomentum.Position;
using TradeBlotter.UIUtils; using TradeBlotter.UIUtils;
using MarketData.Generator.Model; using MarketData.Generator.Model;
using MarketData.CNNProcessing; using MarketData.CNNProcessing;
using System.Runtime.InteropServices.WindowsRuntime;
namespace TradeBlotter.ViewModels namespace TradeBlotter.ViewModels
{ {
@@ -1120,39 +1121,60 @@ namespace TradeBlotter.ViewModels
return; return;
} }
} }
public bool LoadSessionFile() public bool LoadSessionFile()
{ {
if (!CMSessionManager.IsValidSessionFile(pathFileName)) return false; BusyIndicator = true;
initialPath = Path.GetDirectoryName(pathFileName); BusyContent = $"Loading {Utility.GetFileNameNoExtension(pathFileName)}...";
sessionParams=CMSessionManager.RestoreSession(pathFileName);
if (null == sessionParams) { MessageBox.Show(String.Format("Unable to open {0}", pathFileName)); pathFileName = null; return false; } Task workerTask = Task.Factory.StartNew(() =>
modelStatistics=CMMomentumBacktest.GetModelStatistics(sessionParams); {
modelPerformanceSeries=CMMomentumBacktest.GetModelPerformance(sessionParams); try
cmParams = sessionParams.CMParams; {
NVPCollection nvpCollection = sessionParams.CMParams.ToNVPCollection(); if (!CMSessionManager.IsValidSessionFile(pathFileName)) return false;
nvpDictionary = nvpCollection.ToDictionary(); initialPath = Path.GetDirectoryName(pathFileName);
nvpDictionaryKeys = new ObservableCollection<String>(nvpDictionary.Keys); sessionParams=CMSessionManager.RestoreSession(pathFileName);
selectedParameter = nvpDictionaryKeys[0]; if (null == sessionParams) { MessageBox.Show(String.Format("Unable to open {0}", pathFileName)); pathFileName = null; return false; }
positions = new CMPositionModelCollection(); modelStatistics=CMMomentumBacktest.GetModelStatistics(sessionParams);
positions.Add(sessionParams.ActivePositions); modelPerformanceSeries=CMMomentumBacktest.GetModelPerformance(sessionParams);
positions.Add(sessionParams.AllPositions); cmParams = sessionParams.CMParams;
UpdatePositionPrices(false); NVPCollection nvpCollection = sessionParams.CMParams.ToNVPCollection();
UpdatePositionRSI3(true); nvpDictionary = nvpCollection.ToDictionary();
RunPerformance(); nvpDictionaryKeys = new ObservableCollection<String>(nvpDictionary.Keys);
base.OnPropertyChanged("Parameters"); selectedParameter = nvpDictionaryKeys[0];
base.OnPropertyChanged("SelectedParameter"); positions = new CMPositionModelCollection();
base.OnPropertyChanged("ParameterValue"); positions.Add(sessionParams.ActivePositions);
base.OnPropertyChanged("Title"); positions.Add(sessionParams.AllPositions);
base.OnPropertyChanged("DisplayName"); UpdatePositionPrices(false);
base.OnPropertyChanged("AllPositions"); UpdatePositionRSI3(true);
base.OnPropertyChanged("CanMonitor"); RunPerformance();
base.OnPropertyChanged("CashBalance"); return true;
base.OnPropertyChanged("NonTradeableCash"); }
base.OnPropertyChanged("ModelExpectation"); catch(Exception exception)
base.OnPropertyChanged("ExpectationColor"); {
base.OnPropertyChanged("ExpectationDescription"); System.Windows.MessageBox.Show(String.Format("Exception {0}",exception.ToString()),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation);
return false;
}
});
workerTask.ContinueWith(continuation =>
{
BusyIndicator=false;
base.OnPropertyChanged("Parameters");
base.OnPropertyChanged("SelectedParameter");
base.OnPropertyChanged("ParameterValue");
base.OnPropertyChanged("Title");
base.OnPropertyChanged("DisplayName");
base.OnPropertyChanged("AllPositions");
base.OnPropertyChanged("CanMonitor");
base.OnPropertyChanged("CashBalance");
base.OnPropertyChanged("NonTradeableCash");
base.OnPropertyChanged("ModelExpectation");
base.OnPropertyChanged("ExpectationColor");
base.OnPropertyChanged("ExpectationDescription");
});
return true; return true;
} }
private void RunPerformance() private void RunPerformance()
{ {
if(null==sessionParams)return; if(null==sessionParams)return;

View File

@@ -1236,42 +1236,63 @@ namespace TradeBlotter.ViewModels
return; return;
} }
} }
public bool LoadSessionFile() public bool LoadSessionFile()
{ {
if(!CMTSessionManager.IsValidSessionFile(pathFileName)) return false; BusyIndicator = true;
initialPath=Path.GetDirectoryName(pathFileName); BusyContent = $"Loading {Utility.GetFileNameNoExtension(pathFileName)}...";
sessionParams=CMTSessionManager.RestoreSession(pathFileName);
if(null==sessionParams) { MessageBox.Show(String.Format("Unable to open {0}",pathFileName)); pathFileName=null; return false; } Task workerTask = Task.Factory.StartNew( () =>
modelStatistics=CMTTrendModel.GetModelStatistics(sessionParams); {
configuration=sessionParams.CMTParams; try
NVPCollection nvpCollection=sessionParams.CMTParams.ToNVPCollection(); {
nvpDictionary=nvpCollection.ToDictionary(); if(!CMTSessionManager.IsValidSessionFile(pathFileName)) return false;
nvpDictionaryKeys=new ObservableCollection<String>(nvpDictionary.Keys); initialPath=Path.GetDirectoryName(pathFileName);
selectedParameter=nvpDictionaryKeys[0]; sessionParams=CMTSessionManager.RestoreSession(pathFileName);
positions=new CMTPositionModelCollection(); if(null==sessionParams) { MessageBox.Show(String.Format("Unable to open {0}",pathFileName)); pathFileName=null; return false; }
positions.Add(sessionParams.ActivePositions); modelStatistics=CMTTrendModel.GetModelStatistics(sessionParams);
positions.Add(sessionParams.AllPositions); configuration=sessionParams.CMTParams;
trendCandidates=new ObservableCollection<CMTCandidate>(); NVPCollection nvpCollection=sessionParams.CMTParams.ToNVPCollection();
foreach(CMTCandidate candidate in sessionParams.Candidates)trendCandidates.Add(candidate); nvpDictionary=nvpCollection.ToDictionary();
UpdatePositionPrices(true); nvpDictionaryKeys=new ObservableCollection<String>(nvpDictionary.Keys);
RunPerformance(); selectedParameter=nvpDictionaryKeys[0];
base.OnPropertyChanged("Parameters"); positions=new CMTPositionModelCollection();
base.OnPropertyChanged("SelectedParameter"); positions.Add(sessionParams.ActivePositions);
base.OnPropertyChanged("ParameterValue"); positions.Add(sessionParams.AllPositions);
base.OnPropertyChanged("Title"); trendCandidates=new ObservableCollection<CMTCandidate>();
base.OnPropertyChanged("DisplayName"); foreach(CMTCandidate candidate in sessionParams.Candidates)trendCandidates.Add(candidate);
base.OnPropertyChanged("AllPositions"); UpdatePositionPrices(true);
base.OnPropertyChanged("CanMonitor"); RunPerformance();
base.OnPropertyChanged("AllItems"); return true;
base.OnPropertyChanged("CashBalance"); }
base.OnPropertyChanged("NonTradeableCash"); catch(Exception exception)
base.OnPropertyChanged("ModelExpectation"); {
base.OnPropertyChanged("ExpectationColor"); System.Windows.MessageBox.Show(String.Format("Exception {0}",exception.ToString()),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation);
base.OnPropertyChanged("ExpectationDescription"); return false;
base.OnPropertyChanged("TradeableCashDescription"); }
base.OnPropertyChanged("NonTradeableCashDescription"); });
workerTask.ContinueWith(continuation =>
{
BusyIndicator = false;
base.OnPropertyChanged("Parameters");
base.OnPropertyChanged("SelectedParameter");
base.OnPropertyChanged("ParameterValue");
base.OnPropertyChanged("Title");
base.OnPropertyChanged("DisplayName");
base.OnPropertyChanged("AllPositions");
base.OnPropertyChanged("CanMonitor");
base.OnPropertyChanged("AllItems");
base.OnPropertyChanged("CashBalance");
base.OnPropertyChanged("NonTradeableCash");
base.OnPropertyChanged("ModelExpectation");
base.OnPropertyChanged("ExpectationColor");
base.OnPropertyChanged("ExpectationDescription");
base.OnPropertyChanged("TradeableCashDescription");
base.OnPropertyChanged("NonTradeableCashDescription");
});
return true; return true;
} }
private void RunPerformance() private void RunPerformance()
{ {
if(null==sessionParams)return; if(null==sessionParams)return;

View File

@@ -1103,37 +1103,54 @@ namespace TradeBlotter.ViewModels
} }
else LoadSessionFile(); else LoadSessionFile();
} }
public bool LoadSessionFile() public bool LoadSessionFile()
{ {
try BusyIndicator = true;
BusyContent = $"Loading {Utility.GetFileNameNoExtension(pathFileName)}...";
Task workerTask = Task.Factory.StartNew(() =>
{ {
if(!MGSessionManager.IsValidSessionFile(pathFileName)) try
{ {
MessageBox.Show(String.Format("'{0}' is not a valid model. IsValidSessionFile returned false.",pathFileName)); if(!MGSessionManager.IsValidSessionFile(pathFileName))
pathFileName = null; {
MessageBox.Show(String.Format("'{0}' is not a valid model. IsValidSessionFile returned false.",pathFileName));
pathFileName = null;
return false;
}
initialPath=Path.GetDirectoryName(pathFileName);
sessionParams=MGSessionManager.RestoreSession(pathFileName);
if(null==sessionParams)
{
MessageBox.Show(String.Format("Unable to open '{0}'. Restore session failed.",pathFileName));
pathFileName=null;
return false;
}
modelStatistics=MomentumBacktest.GetModelStatistics(sessionParams);
modelPerformanceSeries=MomentumBacktest.GetModelPerformance(sessionParams);
configuration=sessionParams.Configuration;
NVPCollection nvpCollection=sessionParams.Configuration.ToNVPCollection();
nvpDictionary=nvpCollection.ToDictionary();
nvpDictionaryKeys=new ObservableCollection<String>(nvpDictionary.Keys);
selectedParameter=nvpDictionaryKeys[0];
positions=new MGPositionModelCollection();
positions.Add(sessionParams.ActivePositions);
positions.Add(sessionParams.AllPositions);
UpdatePositionPrices(false);
UpdatePositionRSI3(true);
RunPerformance();
return true;
}
catch(Exception exception)
{
System.Windows.MessageBox.Show(String.Format("Exception {0}",exception.ToString()),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation);
return false; return false;
} }
initialPath=Path.GetDirectoryName(pathFileName); });
sessionParams=MGSessionManager.RestoreSession(pathFileName); workerTask.ContinueWith(continuation =>
if(null==sessionParams) {
{ BusyIndicator=false;
MessageBox.Show(String.Format("Unable to open '{0}'. Restore session failed.",pathFileName));
pathFileName=null;
return false;
}
modelStatistics=MomentumBacktest.GetModelStatistics(sessionParams);
modelPerformanceSeries=MomentumBacktest.GetModelPerformance(sessionParams);
configuration=sessionParams.Configuration;
NVPCollection nvpCollection=sessionParams.Configuration.ToNVPCollection();
nvpDictionary=nvpCollection.ToDictionary();
nvpDictionaryKeys=new ObservableCollection<String>(nvpDictionary.Keys);
selectedParameter=nvpDictionaryKeys[0];
positions=new MGPositionModelCollection();
positions.Add(sessionParams.ActivePositions);
positions.Add(sessionParams.AllPositions);
UpdatePositionPrices(false);
UpdatePositionRSI3(true);
RunPerformance();
base.OnPropertyChanged("Parameters"); base.OnPropertyChanged("Parameters");
base.OnPropertyChanged("SelectedParameter"); base.OnPropertyChanged("SelectedParameter");
base.OnPropertyChanged("ParameterValue"); base.OnPropertyChanged("ParameterValue");
@@ -1146,14 +1163,10 @@ namespace TradeBlotter.ViewModels
base.OnPropertyChanged("ModelExpectation"); base.OnPropertyChanged("ModelExpectation");
base.OnPropertyChanged("ExpectationColor"); base.OnPropertyChanged("ExpectationColor");
base.OnPropertyChanged("ExpectationDescription"); base.OnPropertyChanged("ExpectationDescription");
return true; });
} return true;
catch(Exception exception)
{
System.Windows.MessageBox.Show(String.Format("Exception {0}",exception.ToString()),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation);
return false;
}
} }
private void RunPerformance() private void RunPerformance()
{ {
if(null==sessionParams)return; if(null==sessionParams)return;