Make all the AI tasks run on background threads
This commit is contained in:
@@ -36,8 +36,9 @@
|
||||
<!-- AI Frame -->
|
||||
<div class="gridFrame">
|
||||
<div>
|
||||
<button @onclick="pullandtrain">@button1Text</button>
|
||||
<button @onclick="predict">@button2Text</button>
|
||||
<button @onclick="pull">@pullButtonText</button>
|
||||
<button @onclick="train">@trainButtonText</button>
|
||||
<button @onclick="predict">@predictButtonText</button>
|
||||
</div>
|
||||
<div>
|
||||
@foreach (stockPredictionPair cur in predictions){
|
||||
@@ -102,18 +103,50 @@
|
||||
|
||||
// AI Stuff
|
||||
|
||||
string button1Text = "Train AI";
|
||||
string button2Text = "Predict AI";
|
||||
string pullButtonText = "Pull Data";
|
||||
string trainButtonText = "Train AI";
|
||||
string predictButtonText = "Predict AI";
|
||||
|
||||
async Task pullandtrain(){
|
||||
button1Text = "Do not refresh the page. The data is refreshing.";
|
||||
await Task.Delay(1);
|
||||
aiModule.TrainAI();
|
||||
button1Text = "Refresh Completed";
|
||||
bool pullDebounce = true;
|
||||
async Task pull(){
|
||||
if (pullDebounce){
|
||||
pullDebounce = false;
|
||||
pullButtonText = "Do not refresh the page. The data is pulling.";
|
||||
await Task.Delay(1);
|
||||
Task thread = new Task(async () => {
|
||||
aiModule.PullAI();
|
||||
pullButtonText = "Data pulled";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
await Task.Delay(2000);
|
||||
pullButtonText = "Pull Data";
|
||||
await InvokeAsync(StateHasChanged);
|
||||
pullDebounce = true;
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
bool trainDebounce = true;
|
||||
async Task train(){
|
||||
if (trainDebounce){
|
||||
trainDebounce = false;
|
||||
trainButtonText = "Do not refresh the page. The AI is training.";
|
||||
await Task.Delay(1);
|
||||
Task thread = new Task(async () => {
|
||||
aiModule.TrainAI();
|
||||
trainButtonText = "AI Trained";
|
||||
StateHasChanged();
|
||||
await Task.Delay(2000);
|
||||
trainButtonText = "Train AI";
|
||||
StateHasChanged();
|
||||
trainDebounce = true;
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
async Task predict(){
|
||||
button2Text = "Do not refresh the page. The data is refreshing.";
|
||||
predictButtonText = "Do not refresh the page. The AI is predicting";
|
||||
await Task.Delay(1);
|
||||
List<Task> threadpool = new List<Task>();
|
||||
foreach(stockPredictionPair cur in predictions){
|
||||
@@ -125,9 +158,9 @@
|
||||
threadpool.Add(thread);
|
||||
}
|
||||
await Task.WhenAll(threadpool);
|
||||
button2Text = "Refresh Completed";
|
||||
StateHasChanged();
|
||||
await Task.Delay(1);
|
||||
predictButtonText = "Predictions loaded";
|
||||
await Task.Delay(2000);
|
||||
predictButtonText = "Predict AI";
|
||||
}
|
||||
|
||||
// Data Types
|
||||
|
||||
Reference in New Issue
Block a user