From 3544924034177d346edd57a3a910583709001a38 Mon Sep 17 00:00:00 2001 From: Mali Oz Date: Tue, 28 May 2024 16:46:54 -0300 Subject: [PATCH 1/4] move R code to R --- app/Http/Controllers/ExercicioController.php | 14 ++------------ docker/R/corretor.R | 10 ++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ExercicioController.php b/app/Http/Controllers/ExercicioController.php index 2e728ae..9b49e48 100644 --- a/app/Http/Controllers/ExercicioController.php +++ b/app/Http/Controllers/ExercicioController.php @@ -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 [ diff --git a/docker/R/corretor.R b/docker/R/corretor.R index 569c5f4..0b3ffd6 100644 --- a/docker/R/corretor.R +++ b/docker/R/corretor.R @@ -53,7 +53,14 @@ 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), "."); + # Limits memory usage + rlimit_as(1e9); + rlimit_cpu(15); + # Read file texto <- readLines(arquivo, encoding="utf8"); + # Get exercicio testes <- dbGetQuery(con, paste("SELECT condicao FROM testes WHERE exercicio_id=", id.exerc, @@ -62,12 +69,15 @@ 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); } From 3680a378457098a9586946c933a2a7316bf57075 Mon Sep 17 00:00:00 2001 From: Mali Oz Date: Tue, 28 May 2024 17:13:41 -0300 Subject: [PATCH 2/4] Remove fossil enconding check --- docker/R/corretor.R | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docker/R/corretor.R b/docker/R/corretor.R index 0b3ffd6..f1adbf5 100644 --- a/docker/R/corretor.R +++ b/docker/R/corretor.R @@ -71,11 +71,6 @@ notaR <- function (id.exerc, arquivo) { # 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); From 1b9440641be83a7339bca104dadbf9c26403f748 Mon Sep 17 00:00:00 2001 From: Mali Oz Date: Tue, 28 May 2024 18:40:24 -0300 Subject: [PATCH 3/4] =?UTF-8?q?aumenta=20limite=20de=20mem=C3=B3ria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/R/corretor.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/R/corretor.R b/docker/R/corretor.R index f1adbf5..a82eb8d 100644 --- a/docker/R/corretor.R +++ b/docker/R/corretor.R @@ -56,7 +56,7 @@ notaR <- function (id.exerc, arquivo) { # import files file.copy(list.files("/arquivos/", recursive=TRUE, full.names=TRUE), "."); # Limits memory usage - rlimit_as(1e9); + rlimit_as(1e10); rlimit_cpu(15); # Read file texto <- readLines(arquivo, encoding="utf8"); From 070a34cd9a75c97406634d148f21755052edf077 Mon Sep 17 00:00:00 2001 From: Mali Oz Date: Wed, 29 May 2024 13:54:55 -0300 Subject: [PATCH 4/4] move memory limit to after preconds --- docker/R/corretor.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docker/R/corretor.R b/docker/R/corretor.R index a82eb8d..c7a8a72 100644 --- a/docker/R/corretor.R +++ b/docker/R/corretor.R @@ -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 @@ -55,9 +59,6 @@ corretoR <- function (precondi, testes, texto) { notaR <- function (id.exerc, arquivo) { # import files file.copy(list.files("/arquivos/", recursive=TRUE, full.names=TRUE), "."); - # Limits memory usage - rlimit_as(1e10); - rlimit_cpu(15); # Read file texto <- readLines(arquivo, encoding="utf8"); # Get exercicio