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

Correto r minimo #115

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 25 additions & 1 deletion app/Http/Controllers/ExercicioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,41 @@ private function corretoR(Exercicio $exercicio, string $file)
// resposta do R
try {
$cnx = new Connection('r');
} catch (Exception $e) {
Log::error('Erro ao conectar ao serviço R');
return [
'status' => 'danger',
'mensagem' => 'Ocorreu um erro ao conectar com o serviço R. Por favor contate um administrador.',
'resultado' => null,
'nota' => 0
];
}

try {
$rcode = ''
// database auth
. 'dbusr <- "' . env('DB_USERNAME') . '";'
. 'dbpass <- "' . env('DB_PASSWORD') . '";'
. 'dbname <- "' . env('DB_DATABASE') . '";'
. 'con <- connect(dbusr, dbpass, dbname);'
;
$r = $cnx->evalString($rcode);
} catch (Exception $e) {
Log::error('Erro ao na conexão RMySql');
return [
'status' => 'danger',
'mensagem' => 'Ocorreu um erro ao acessar os testes do exercício. Por favor contate um administrador.',
'resultado' => null,
'nota' => 0
];
}

try {
$rcode = ''
// import files
. 'file.copy(list.files("/arquivos/",recursive=TRUE,full.names=TRUE),".");'
// Limits memory usage
. 'rlimit_as(1e10);'
. 'rlimit_as(1e9);'
. 'rlimit_cpu(15);'
// run corretoR
. 'res <- notaR(' . $exercicio->id . ',"' . $file . '");'
Expand Down
22 changes: 11 additions & 11 deletions docker/R/corretor.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ no.results <- function(object) {
# texto
# E devolve um um vector logico com o resultado dos testes
# Caso o codigo tenha erros de sintaxe, retorna NULL
corretoR <- function (id.exerc, texto) {
corretoR <- function (precondi, testes, texto) {
# Definicoes iniciais
corrEnv <- new.env()
# Funcoes disponiveis dentro do ambiente de correcao
eval(parse(file=paste0("/usr/local/src/notar/acessorias.R")), envir=corrEnv)

testes <- dbGetQuery(con,
paste("SELECT condicao FROM testes
WHERE exercicio_id=", id.exerc,
" ORDER BY id ASC", sep=""));
precondi <- dbGetQuery(con,
paste("SELECT precondicoes FROM exercicios
WHERE id=", id.exerc, sep=""));

# Executa as precondicoes
if(!no.results(precondi)) eval(parse(text=precondi), envir=corrEnv);

Expand Down Expand Up @@ -62,11 +54,19 @@ corretoR <- function (id.exerc, 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) {
texto <- readLines(arquivo, encoding="utf8");
nota <- corretoR (id.exerc, texto);
testes <- dbGetQuery(con,
paste("SELECT condicao FROM testes
WHERE exercicio_id=", id.exerc,
" ORDER BY id ASC", sep=""));
precondi <- dbGetQuery(con,
paste("SELECT precondicoes FROM exercicios
WHERE id=", id.exerc, sep=""));

nota <- corretoR (precondi, testes, texto);
# Tenta de novo com charset latin1:
if (is.null(nota)) {
texto <- readLines(arquivo, encoding="latin1");
nota <- corretoR (id.exerc, texto);
nota <- corretoR (precondi, testes, texto);
}
return (nota);
}
Expand Down