33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
namespace Application.Endpoints.SicknessPrediction;
|
|
|
|
public class SicknessPredictionHandler
|
|
{
|
|
public async Task<BaseResponse> GetPrediction(SicknessPredictionDto dto)
|
|
{
|
|
var validation = new SicknessPredictionValidator();
|
|
var validationResult = await validation.ValidateAsync(dto);
|
|
|
|
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 scriptRunner.RunPythonScript(scriptPath, dto.Text);
|
|
|
|
return result;
|
|
}
|
|
} |