Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separar responsabilidades R e PHP #118

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions app/Http/Controllers/ExercicioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,8 @@ private function corretoR(Exercicio $exercicio, string $file)
}

try {
$rcode = ''
// import files
. 'file.copy(list.files("/arquivos/",recursive=TRUE,full.names=TRUE),".");'
// Limits memory usage
. 'rlimit_as(1e9);'
. 'rlimit_cpu(15);'
// run corretoR
. 'res <- notaR(' . $exercicio->id . ',"' . $file . '");'
. 'unlink("*",recursive=TRUE);'
// Returns the "res" object to caller
. 'res;'
;
// run corretoR
$rcode = 'notaR(' . $exercicio->id . ',"' . $file . '");';
$r = $cnx->evalString($rcode);
} catch (Exception $e) {
return [
Expand Down
16 changes: 11 additions & 5 deletions docker/R/corretor.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ corretoR <- function (precondi, testes, texto) {
# Executa as precondicoes
if(!no.results(precondi)) eval(parse(text=precondi), envir=corrEnv);

# Limits memory usage
rlimit_as(1e10);
rlimit_cpu(15);

# Executa o texto da resposta
getError <- try(eval(
c(parse(text=texto),"TRUE"), # Evita que o codigo retorne matrizes
Expand All @@ -53,7 +57,11 @@ corretoR <- function (precondi, testes, texto) {

# Recebe o exercicio, transforma o texto em string, corrige, e retorna o vetor de true/false para os testes passados
notaR <- function (id.exerc, arquivo) {
# import files
file.copy(list.files("/arquivos/", recursive=TRUE, full.names=TRUE), ".");
# Read file
texto <- readLines(arquivo, encoding="utf8");
# Get exercicio
testes <- dbGetQuery(con,
paste("SELECT condicao FROM testes
WHERE exercicio_id=", id.exerc,
Expand All @@ -62,12 +70,10 @@ notaR <- function (id.exerc, arquivo) {
paste("SELECT precondicoes FROM exercicios
WHERE id=", id.exerc, sep=""));

# Run corretor
nota <- corretoR (precondi, testes, texto);
# Tenta de novo com charset latin1:
if (is.null(nota)) {
texto <- readLines(arquivo, encoding="latin1");
nota <- corretoR (precondi, testes, texto);
}
# Delete files
unlink("*", recursive=TRUE);
return (nota);
}

Expand Down