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