34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
namespace Application.Endpoints.SicknessPrediction;
|
|
|
|
public class SicknessPredictionHandler
|
|
{
|
|
public static async Task<BaseResponse> GetPrediction(SicknessPredictionCommand command)
|
|
{
|
|
var validation = new SicknessPredictionValidator();
|
|
var validationResult = await validation.ValidateAsync(command);
|
|
|
|
if (!validationResult.IsValid)
|
|
{
|
|
var firstError = validationResult.Errors.FirstOrDefault();
|
|
var errorCode = int.TryParse(firstError.ErrorCode, out var code) ? code : -1;
|
|
var errorMessage = firstError.ErrorMessage;
|
|
|
|
return new BaseResponse
|
|
{
|
|
StatusCode = errorCode,
|
|
Message = errorMessage,
|
|
Data = null
|
|
};
|
|
}
|
|
|
|
var currentDirectory = Directory.GetCurrentDirectory(); // gets the current working directory
|
|
var applicationDirectory = Path.Combine(Directory.GetParent(currentDirectory)?.FullName, "Application");
|
|
|
|
var scriptPath = Path.Combine(applicationDirectory, "Endpoints", "SicknessPrediction",
|
|
"SicknessPredictionScript.py");
|
|
var scriptRunner = new PythonScriptRunner();
|
|
var result = await PythonScriptRunner.RunPythonScript(scriptPath, command.Text);
|
|
|
|
return result;
|
|
}
|
|
} |