Add debounce and stylize

This commit is contained in:
2026-03-06 17:19:45 -08:00
parent 405872da39
commit 54ea7c3027
2 changed files with 84 additions and 45 deletions
+58 -44
View File
@@ -29,6 +29,7 @@
<!-- User Frame --> <!-- User Frame -->
}else{ }else{
<div class="gridFrame"> <div class="gridFrame">
<div><h2>Account</h2></div>
<span>UserName: @Session.UserName</span><br /> <span>UserName: @Session.UserName</span><br />
<div> <div>
@foreach(PurchasedStock cur in Session.TrackedStocks){ @foreach(PurchasedStock cur in Session.TrackedStocks){
@@ -42,10 +43,16 @@
<!-- Tool Frame --> <!-- Tool Frame -->
<div class="gridFrame"> <div class="gridFrame">
<div> <div>
<span>Actions</span> <div><h2>Actions</h2></div>
<button @onclick="pull">@pullButtonText</button> @if (Debounce){
<button @onclick="train">@trainButtonText</button> <button @onclick="pull">@pullButtonText</button>
<button @onclick="predict">@predictButtonText</button> <button @onclick="train">@trainButtonText</button>
<button @onclick="predict">@predictButtonText</button>
}else{
<button disabled>@pullButtonText</button>
<button disabled>@trainButtonText</button>
<button disabled>@predictButtonText</button>
}
<span>@PredictError</span> <span>@PredictError</span>
</div> </div>
</div> </div>
@@ -54,22 +61,26 @@
<!-- AI Frame --> <!-- AI Frame -->
<div class="gridFrame"> <div class="gridFrame">
<div> <div>
<h2>Current Signal</h2>
</div> </div>
<div> @foreach (stockPredictionPair cur in predictions){
@foreach (stockPredictionPair cur in predictions){ <div class="signalBlock">
<div> <div>
<h1>Symbol: @cur.Symbol</h1><br /> <p>@cur.Symbol</p>
@if (cur.Movement == -1){
<p>Sell</p>
} else if (cur.Movement == 1){
<p>Buy</p>
} else{
<p>Hold</p>
}
</div> </div>
} <div>
</div> <span>-></span>
</div>
@if (cur.Movement == -1){
<div style="background-color: red;"><p style=>Sell</p></div>
} else if (cur.Movement == 1){
<div style="background-color: green;"><p>Buy</p></div>
} else{
<div style="background-color: #444;"><p>Hold</p></div>
}
</div>
}
</div> </div>
</div> </div>
@@ -127,11 +138,11 @@
string predictButtonText = "Predict AI"; string predictButtonText = "Predict AI";
string PredictError = ""; string PredictError = "";
bool pullDebounce = true; bool Debounce = true;
async Task pull(){ async Task pull(){
PredictError = ""; PredictError = "";
if (pullDebounce){ if (Debounce){
pullDebounce = false; Debounce = false;
pullButtonText = "Do not refresh the page. The data is pulling."; pullButtonText = "Do not refresh the page. The data is pulling.";
await Task.Delay(1); await Task.Delay(1);
Task thread = new Task(async () => { Task thread = new Task(async () => {
@@ -141,17 +152,16 @@
await Task.Delay(2000); await Task.Delay(2000);
pullButtonText = "Pull Data"; pullButtonText = "Pull Data";
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
pullDebounce = true; Debounce = true;
}); });
thread.Start(); thread.Start();
} }
} }
bool trainDebounce = true;
async Task train(){ async Task train(){
PredictError = ""; PredictError = "";
if (trainDebounce){ if (Debounce){
trainDebounce = false; Debounce = false;
trainButtonText = "Do not refresh the page. The AI is training."; trainButtonText = "Do not refresh the page. The AI is training.";
await Task.Delay(1); await Task.Delay(1);
Task thread = new Task(async () => { Task thread = new Task(async () => {
@@ -161,7 +171,7 @@
await Task.Delay(2000); await Task.Delay(2000);
trainButtonText = "Train AI"; trainButtonText = "Train AI";
StateHasChanged(); StateHasChanged();
trainDebounce = true; Debounce = true;
}); });
thread.Start(); thread.Start();
} }
@@ -169,26 +179,30 @@
async Task predict(){ async Task predict(){
PredictError = ""; PredictError = "";
predictButtonText = "Do not refresh the page. The AI is predicting"; if (Debounce){
await Task.Delay(1); Debounce = false;
List<Task> threadpool = new List<Task>(); predictButtonText = "Do not refresh the page. The AI is predicting";
foreach(stockPredictionPair cur in predictions){ await Task.Delay(1);
Task thread = new Task(() => { List<Task> threadpool = new List<Task>();
(string, int)Result = aiModule.PredictAI(cur.Symbol); foreach(stockPredictionPair cur in predictions){
if (string.IsNullOrEmpty(Result.Item1)){ Task thread = new Task(() => {
cur.Movement = Result.Item2; (string, int)Result = aiModule.PredictAI(cur.Symbol);
}else{ if (string.IsNullOrEmpty(Result.Item1)){
PredictError = Result.Item1; cur.Movement = Result.Item2;
} }else{
Console.WriteLine("Received Signal [" + cur.Symbol + "] : " + cur.Movement); PredictError = Result.Item1;
}); }
thread.Start(); Console.WriteLine("Received Signal [" + cur.Symbol + "] : " + cur.Movement);
threadpool.Add(thread); });
thread.Start();
threadpool.Add(thread);
}
await Task.WhenAll(threadpool);
predictButtonText = "Predictions loaded";
await Task.Delay(2000);
predictButtonText = "Predict AI";
Debounce = true;
} }
await Task.WhenAll(threadpool);
predictButtonText = "Predictions loaded";
await Task.Delay(2000);
predictButtonText = "Predict AI";
} }
// Data Types // Data Types
+26 -1
View File
@@ -5,7 +5,6 @@
grid-auto-columns: auto; grid-auto-columns: auto;
grid-auto-flow: column; grid-auto-flow: column;
grid-template-columns: max-content; grid-template-columns: max-content;
overflow: scroll;
} }
.gridFrame { .gridFrame {
@@ -60,3 +59,29 @@
.loginRow button:last-of-type{ .loginRow button:last-of-type{
float: right; float: right;
} }
.signalBlock {
display: flex;
}
.signalBlock > :nth-child(1) {
border: solid #040 1px;
border-radius: 15px;
width: 40px;
padding: 0px 20px;
background-color: greenyellow;
}
.signalBlock > :nth-child(2) {
padding: 0 30px;
font-size: 30px;
align-content: center;
}
.signalBlock > :nth-child(3) {
color: white;
padding: 0 30px;
width: 40px;
border: solid #000 1px;
border-radius: 15px;
}