55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using Controllers.Processes;
|
|
|
|
namespace Controllers.PythonInterop {
|
|
|
|
public class AIModule {
|
|
|
|
string _PyPath = "";
|
|
string _ExecPath = "";
|
|
|
|
public AIModule() {
|
|
_PyPath = "/usr/bin/python3.11";
|
|
_ExecPath = $"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AIPython")}";
|
|
}
|
|
|
|
public void PullAI() {
|
|
(bool, string) Success = PyProcess.RunPythonProcess(_PyPath, _ExecPath + "/datapuller.py");
|
|
if (!Success.Item1) {
|
|
Console.WriteLine(Success.Item2);
|
|
}
|
|
}
|
|
|
|
public void TrainAI() {
|
|
(bool, string) Success = PyProcess.RunPythonProcess(_PyPath, _ExecPath + "/aitrainer.py");
|
|
if (!Success.Item1) {
|
|
Console.WriteLine(Success.Item2);
|
|
}
|
|
}
|
|
|
|
// Return ( Error, Signal )
|
|
public (string, int) PredictAI(string StockSymbol) {
|
|
(bool, string) Success = PyProcess.RunPythonProcess(_PyPath, _ExecPath + "/aipredictor.py", returns: true, PyArgs: StockSymbol);
|
|
if (!Success.Item1) {
|
|
return (Success.Item2, 0);
|
|
} else {
|
|
if (int.TryParse(Success.Item2, out int parsed)) {
|
|
return ("", parsed);
|
|
}
|
|
return ("Python returns an unknown value", 0);
|
|
}
|
|
}
|
|
|
|
public float GetCurrentPrice(string StockSymbol) {
|
|
(bool, string) Success = PyProcess.RunPythonProcess(_PyPath, _ExecPath + "/currentprice.py", returns: true, PyArgs: StockSymbol);
|
|
if (!Success.Item1) {
|
|
return 0;
|
|
} else {
|
|
if (float.TryParse(Success.Item2, out float parsed)) {
|
|
return parsed;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |