Skip to content

Commit

Permalink
Merge pull request #102 from lageIBUSP/relatorios
Browse files Browse the repository at this point in the history
Relatorios
  • Loading branch information
andrechalom authored Apr 11, 2024
2 parents 70c5688 + d03ebe2 commit 0bf41f3
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 90 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ docker exec -t notar_app_1 php artisan migrate
docker exec -t notar_app_1 php artisan migrate:admin novasenha
```

## Atualizando o CSS e javascript

O CSS do notaR é gerado a partir dos arquivos `.scss` na pasta `resources/sass`. Os scripts javascript estão na pasta `resources/js`. Após modificar esses arquivos, é preciso compilar o código usando o `npm`. Em ambiente de desenvolvimento, use o script `npm run dev`, e antes de submeter qualquer commit, compile a versão de produção com `npm run prod`.

## Rodando os testes de integração

**ATENÇÃO: ESSES TESTES DESTROEM SEU BANCO DE DADOS LOCAL. NÃO RODE EM PRODUÇÃO**
Expand Down
88 changes: 37 additions & 51 deletions app/Http/Controllers/RelatorioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,82 +18,68 @@ class RelatorioController extends Controller
public function index(Request $request)
{
$this->authorize('view', Relatorio::class);
// Prepare return
$turmas = Turma::orderBy('created_at', 'DESC')->has('users')->get();
// Validate
$rules = array(
'turma' => 'sometimes|int|exists:turmas,id',
'tipo' => 'sometimes|in:realizacao,notas',
'export' => 'sometimes|bool'
);
$data = $request->validate($rules);
if(array_key_exists('turma',$data) && array_key_exists('tipo',$data)) {
return $this->relatorio($data['turma'], $data['tipo'], $data['export']);
} else {
return redirect()->action(
[self::class, 'index'],
['turma' => $turmas->first()->id, 'tipo' => 'notas', 'export' => 0]
);
}
}

/**
* Separa os relatórios
*
* @param int $turma
* @param string $tipo
* @param bool $export
* @return \Illuminate\View\View
*/
public function relatorio(int $turma, string $tipo, bool $export)
{
$this->authorize('view', Relatorio::class);
$turma = Turma::with(['users', 'prazos', 'prazos.exercicio', 'users.notas'])
->find($turma);
$turma = Turma::with(['users', 'prazos', 'prazos.exercicio', 'users.notas'])->find($data['turma']);
$tipo = $data['tipo'];
$export = $data['export'];

if ($tipo == 'notas') {
$table = $this->relatorioNotas($turma);
} else {
$table = $this->relatorioRealizacao($turma);
}

if ($tipo == 'notas') {
$table = $this->relatorioNotas($turma);
} else {
$table = $this->relatorioRealizacao($turma);
}
if ($export) {
$filename = TmpFile::generateTmpFileName('relatorio-'.$tipo.'-'.$turma->name, '.csv');
$file = fopen($filename,'w');
// write csv
foreach($table as $row) {
fputcsv($file,$row);
}
fclose($file);

if ($export) {
$filename = TmpFile::generateTmpFileName('relatorio-'.$tipo.'-'.$turma->name, '.csv');
$file = fopen($filename,'w');
// write csv
foreach($table as $row) {
fputcsv($file,$row);
return response()->download($filename)->deleteFileAfterSend(true);
}
fclose($file);

return response()->download($filename)->deleteFileAfterSend(true);
}
return View('relatorio.'.$tipo)
->with('tabela', $table)
->with('turma', $turma)
->with('tipo', $tipo)
->with('export', $export)
->with('turmas', $turmas);

// Prepare return
$turmas = Turma::orderBy('created_at', 'DESC')->has('users')->get();

return View('relatorio.'.$tipo)
->with('tabela', $table)
->with('turma', $turma)
->with('tipo', $tipo)
->with('export', $export)
} else {
return View('relatorio.notas')
->with('turmas', $turmas);

}
}
}

/** Relatório de notas
*
* @param Turma $turma
*/
public function relatorioNotas (Turma $turma) {
$prazos = $turma->prazos->sortBy('exercicio.name');
$colnames = $prazos->pluck('exercicio.name')->prepend('');
$colnames = $prazos->pluck('exercicio.name')
->prepend('Email')
->prepend('Nome');
$mytable = collect();
$mytable->push($colnames->all());
foreach ($turma->users->sortBy(['name','email']) as $user) {
$rowname = $user->name ? $user->name : $user->email;
$notas = $prazos->map( function ($prazo) use ($user) {
return $user->notaFinal($prazo);
});
$myrow = $notas->prepend($rowname);
$myrow = $notas->prepend($user->email)
->prepend($user->name);

$mytable->push($myrow->all());
}
Expand Down Expand Up @@ -133,14 +119,14 @@ public function relatorioRealizacao (Turma $turma) {
$prazo->resumo = [
'name' => $prazo->exercicio->name,
'tentaram' => number_format(100*$tentaram/$nusers, 1)."%",
'notamaxima' => $tentaram ? number_format(100*$arr->where('nota','100')->count()/$tentaram, 1) : '' ,
'notamaxima' => $tentaram ? number_format(100*$arr->where('nota','100')->count()/$tentaram, 1)."%" : '' ,
'tentativas' => number_format($arr->average('tentativas'), 1),
'media' => $tentaram ? number_format($arr->average('nota'), 1) : "",
// 'primeiroerro' => $tentaram ? $arr->mode('primeiroerro')[0] : ''
];
}

$colnames = ['','Tentaram','Nota Máxima', 'Média de Tentativas', 'Média de Notas'];
$colnames = ['Exercício','Tentaram','Tiveram nota máxima', 'Média de Tentativas', 'Média de Notas'];
$mytable = $turma->prazos->pluck('resumo');
$mytable->prepend($colnames);
return $mytable;
Expand Down
10 changes: 1 addition & 9 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$admin = User::factory()->create([
'name' => 'Admin Adminsson',
'email'=> '[email protected]',
'is_admin'=>true
]);
$admin->password = "123";
$admin->save();

$ind_user = User::factory()->create();
$alunos = User::factory()->count(3)->create();
$turma = Turma::factory()
Expand Down Expand Up @@ -65,6 +57,6 @@ public function run()
->for($alunos[2])
->for($exercicios[2])
->create();

}
}
12 changes: 6 additions & 6 deletions public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/app.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

35 changes: 15 additions & 20 deletions public/js/app.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
/*!
* Bootstrap v4.6.0 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Bootstrap v4.6.2 (https://getbootstrap.com/)
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/

/*!
* Sizzle CSS Selector Engine v2.3.5
* https://sizzlejs.com/
* The buffer module from node.js, for the browser.
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2020-03-14
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/

/*!
* jQuery JavaScript Library v3.5.1
* jQuery JavaScript Library v3.7.1
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2020-05-04T22:49Z
* Date: 2023-08-28T13:37Z
*/

/*!
* jQuery UI :data 1.12.1
* jQuery UI :data 1.13.2
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
Expand All @@ -39,7 +32,7 @@
*/

/*!
* jQuery UI Mouse 1.12.1
* jQuery UI Mouse 1.13.2
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
Expand All @@ -48,7 +41,7 @@
*/

/*!
* jQuery UI Scroll Parent 1.12.1
* jQuery UI Scroll Parent 1.13.2
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
Expand All @@ -57,7 +50,7 @@
*/

/*!
* jQuery UI Sortable 1.12.1
* jQuery UI Sortable 1.13.2
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
Expand All @@ -66,14 +59,16 @@
*/

/*!
* jQuery UI Widget 1.12.1
* jQuery UI Widget 1.13.2
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*!@preserve
* Tempus Dominus Bootstrap4 v5.39.0 (https://tempusdominus.github.io/bootstrap-4/)
* Copyright 2016-2020 Jonathan Peterson and contributors
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions resources/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ footer {
position: relative;
}

.gridline {
display: grid;
grid-auto-flow: column;
grid-column-gap: 10px;
}

input.small {
max-width: 55px;
}
Expand Down
4 changes: 3 additions & 1 deletion resources/views/relatorio/select.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<form action="{{URL::to('/relatorio')}}" method='GET' class="relatorio-select">
<form action="{{URL::to('/relatorio')}}" method='GET' class="relatorio-select row gridline">
<label for="turma">Turma:</label>
<select id="turma" name="turma">
@foreach ($turmas as $key => $value)
Expand All @@ -18,4 +18,6 @@
<option value="0" {{($export ?? '') == '0' ? "selected" : ""}}>Ver apenas</option>
<option value="1" {{($export ?? '') == '1' ? "selected" : ""}}>Exportar</option>
</select>

<input type="submit" class="btn btn-small inline btn-edit" value="Gerar relatório">
</form>

0 comments on commit 0bf41f3

Please sign in to comment.