Add error handling for the predictor

This commit is contained in:
2026-03-05 20:14:51 -08:00
parent 308076bfa6
commit 405872da39
2 changed files with 22 additions and 7 deletions
+11 -1
View File
@@ -46,6 +46,7 @@
<button @onclick="pull">@pullButtonText</button>
<button @onclick="train">@trainButtonText</button>
<button @onclick="predict">@predictButtonText</button>
<span>@PredictError</span>
</div>
</div>
}
@@ -124,9 +125,11 @@
string pullButtonText = "Pull Data";
string trainButtonText = "Train AI";
string predictButtonText = "Predict AI";
string PredictError = "";
bool pullDebounce = true;
async Task pull(){
PredictError = "";
if (pullDebounce){
pullDebounce = false;
pullButtonText = "Do not refresh the page. The data is pulling.";
@@ -146,6 +149,7 @@
bool trainDebounce = true;
async Task train(){
PredictError = "";
if (trainDebounce){
trainDebounce = false;
trainButtonText = "Do not refresh the page. The AI is training.";
@@ -164,12 +168,18 @@
}
async Task predict(){
PredictError = "";
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){
Task thread = new Task(() => {
cur.Movement = aiModule.PredictAI(cur.Symbol);
(string, int)Result = aiModule.PredictAI(cur.Symbol);
if (string.IsNullOrEmpty(Result.Item1)){
cur.Movement = Result.Item2;
}else{
PredictError = Result.Item1;
}
Console.WriteLine("Received Signal [" + cur.Symbol + "] : " + cur.Movement);
});
thread.Start();
+7 -2
View File
@@ -35,14 +35,19 @@ namespace PythonInterop {
}
}
public int PredictAI(string StockSymbol) {
// Return ( Error, Signal )
public (string, int) PredictAI(string StockSymbol) {
try {
using (Py.GIL()) {
dynamic predictor = Py.Import("ai-predictor");
using (dynamic x = predictor.Predict(StockSymbol)) {
int result = (int)x;
return result;
return ("", result);
}
}
} catch (Exception ex) {
return (ex.ToString(), 0);
}
}
}