Use threading for python. and make singals from python
This commit is contained in:
@@ -22,8 +22,17 @@
|
||||
<button @onclick="pullandtrain">@button1Text</button>
|
||||
<button @onclick="predict">@button2Text</button>
|
||||
|
||||
@foreach(double cur in predictions){
|
||||
<p>@cur</p><br/>
|
||||
@foreach (stockPredictionPair cur in predictions){
|
||||
<div>
|
||||
<h1>Symbol: @cur.Symbol</h1><br />
|
||||
@if (cur.Movement == -1){
|
||||
<p>Sell</p>
|
||||
} else if (cur.Movement == 1){
|
||||
<p>Buy</p>
|
||||
} else{
|
||||
<p>Hold</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
@@ -34,7 +43,13 @@
|
||||
string button1Text = "Train AI";
|
||||
string button2Text = "Predict AI";
|
||||
|
||||
double[] predictions = {};
|
||||
|
||||
List<stockPredictionPair> predictions = new List<stockPredictionPair>(){
|
||||
new stockPredictionPair(){ Symbol = "AAPL" },
|
||||
new stockPredictionPair(){ Symbol = "AAPL" },
|
||||
new stockPredictionPair(){ Symbol = "TTD" },
|
||||
new stockPredictionPair(){ Symbol = "FUN" }
|
||||
};
|
||||
|
||||
async Task pullandtrain(){
|
||||
button1Text = "Do not refresh the page. The data is refreshing.";
|
||||
@@ -46,8 +61,24 @@
|
||||
async Task predict(){
|
||||
button2Text = "Do not refresh the page. The data is refreshing.";
|
||||
await Task.Delay(1);
|
||||
predictions = aiModule.PredictAI();
|
||||
List<Task> threadpool = new List<Task>();
|
||||
foreach(stockPredictionPair cur in predictions){
|
||||
Task thread = new Task(() => {
|
||||
cur.Movement = aiModule.PredictAI(cur.Symbol);
|
||||
Console.WriteLine("Received Signal [" + cur.Symbol + "] : " + cur.Movement);
|
||||
});
|
||||
thread.Start();
|
||||
threadpool.Add(thread);
|
||||
}
|
||||
await Task.WhenAll(threadpool);
|
||||
button2Text = "Refresh Completed";
|
||||
StateHasChanged();
|
||||
await Task.Delay(1);
|
||||
}
|
||||
|
||||
class stockPredictionPair{
|
||||
public string Symbol = "";
|
||||
public int Movement = 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user