Files
AI-Stock-Trader/WebServer/Components/Pages/Home.razor
T
2026-02-19 15:09:06 -08:00

84 lines
2.1 KiB
Plaintext

@page "/"
@rendermode InteractiveServer
<PageTitle>Home</PageTitle>
<div class="card-holder">
<a class="card">
HOME
</a>
<a class="card">
S&P Chart
</a>
<a class="card">
Connect
</a>
<a class="card">
About
</a>
</div>
<div class="main-area">
<button @onclick="pullandtrain">@button1Text</button>
<button @onclick="predict">@button2Text</button>
@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>
@code {
string button1Text = "Train AI";
string button2Text = "Predict AI";
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.";
await Task.Delay(1);
aiModule.TrainAI();
button1Text = "Refresh Completed";
}
async Task predict(){
button2Text = "Do not refresh the page. The data is refreshing.";
await Task.Delay(1);
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;
}
}