Skip to content

Commit f08202d

Browse files
committed
Terminando gráfico
1 parent 58db40d commit f08202d

File tree

10 files changed

+318
-78
lines changed

10 files changed

+318
-78
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace SON\Http\Controllers\Api\Student;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Http\Request;
7+
use SON\Http\Controllers\Controller;
8+
9+
class ClassTestResultsController extends Controller
10+
{
11+
12+
public function perSubject(Request $request) //?class_teaching=120
13+
{
14+
$sumClassTestPoints = "(select sum(`point`) from questions where questions.class_test_id = class_tests.id)";
15+
$selects = [
16+
'student_class_tests.created_at',
17+
"(student_class_tests.`point`/$sumClassTestPoints)*100 as percentage"
18+
];
19+
$results = \DB::table('student_class_tests')
20+
->selectRaw(implode(',', $selects))
21+
->join('class_tests', 'class_tests.id', '=', 'student_class_tests.class_test_id')
22+
//->join('class_teachings','class_teachings.id','=','class_tests.class_teaching_id')
23+
//->join('subjects','subjects.id','=','class_teachings.subject_id')
24+
->where('student_id',25)
25+
->where('class_tests.class_teaching_id',166)
26+
->orderBy('student_class_tests.created_at', 'asc')
27+
->get();
28+
$results->map(function ($item) { //\stdClass
29+
$item->created_at = (new Carbon($item->created_at))->format(Carbon::ISO8601);
30+
return $item;
31+
});
32+
return $results;
33+
}
34+
}

Diff for: database/seeds/DatabaseSeeder.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public function run()
1515
$this->call(SubjectsTableSeeder::class);
1616
$this->call(ClassInformationsTableSeeder::class);
1717
$this->call(ClassTestsTableSeeder::class);
18+
$this->call(StudentClassTestTableSeeder::class);
1819
}
1920
}

Diff for: database/seeds/StudentClassTestTableSeeder.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use Illuminate\Database\Seeder;
4+
5+
class StudentClassTestTableSeeder extends Seeder
6+
{
7+
/**
8+
* Run the database seeds.
9+
*
10+
* @return void
11+
*/
12+
public function run()
13+
{
14+
$classTests = \SON\Models\ClassTest::byTeacher(1)->get();
15+
16+
foreach ($classTests as $classTest){
17+
$classTeaching = $classTest->classTeaching;
18+
$classInformation = $classTeaching->classInformation;
19+
$students = $classInformation->students;
20+
$totalStudents = (int)($students->count() * 0.7);
21+
$studentsRandom = $students->random($totalStudents);
22+
$halfStudents = $studentsRandom->count()/2;
23+
$studentsRandom100 = $studentsRandom->slice(0,$halfStudents);
24+
$self = $this;
25+
$studentsRandom100->each(function($student) use($self,$classTest){
26+
$self->makeResults($student,$classTest,1);
27+
});
28+
$studentsRandom60 = $studentsRandom->slice($halfStudents,$studentsRandom->count());
29+
$studentsRandom60->each(function($student) use($self,$classTest){
30+
$self->makeResults($student,$classTest,0.6);
31+
});
32+
}
33+
}
34+
35+
public function makeResults($student,$classTest, $perc){
36+
$questions = $classTest->questions;
37+
$numQuestionsCorrect = (int)($questions->count() * $perc);
38+
$questionsCorrect = $questions->slice(0,$numQuestionsCorrect);
39+
$questionsIncorrect = $questions->slice($numQuestionsCorrect,$questions->count());
40+
$choices = [];
41+
foreach ($questionsCorrect as $question){
42+
$choices[] = [
43+
'question_id' => $question->id,
44+
'question_choice_id' => $question->choices->first()->id
45+
];
46+
}
47+
48+
foreach ($questionsIncorrect as $question){
49+
$choices[] = [
50+
'question_id' => $question->id,
51+
'question_choice_id' => $question->choices->last()->id
52+
];
53+
}
54+
55+
\Illuminate\Database\Eloquent\Model::reguard();
56+
\SON\Models\StudentClassTest::createFully([
57+
'class_test_id' => $classTest->id,
58+
'student_id' => $student->id,
59+
'choices' => $choices
60+
]);
61+
\Illuminate\Database\Eloquent\Model::unguard();
62+
}
63+
}

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lodash": "^4.17.4",
2222
"moment": "^2.18.1",
2323
"pnotify": "^3.2.0",
24+
"scriptjs": "^2.5.8",
2425
"select2": "^4.0.3",
2526
"vue": "^2.1.10",
2627
"vue-deepset": "^0.5.1",

Diff for: public/js/spa.js

+112-73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: resources/assets/spa/js/components/student/StudentClassTeachingList.vue

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
<td>
2121
<router-link :to="{name: 'student.class_tests.list', params: {class_teaching: classTeaching.id} }">
2222
Avaliações
23+
</router-link>|
24+
<router-link :to="{name: 'student.chart.per_subject', params: {class_teaching: classTeaching.id} }">
25+
Aproveitamento
2326
</router-link>
2427
</td>
2528
</tr>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<template>
2+
<div class="container">
3+
<div class="row">
4+
<div class="page-header">
5+
<h1>
6+
Turma
7+
<small>{{classInformationName}}</small>
8+
</h1>
9+
</div>
10+
<div id="chart"></div>
11+
</div>
12+
</div>
13+
</template>
14+
15+
<script type="text/javascript">
16+
import scriptjs from 'scriptjs';
17+
import store from '../../../store/store';
18+
import classInformationMixin from '../../../mixins/class_information.mixin';
19+
import {Student} from '../../../services/resources';
20+
21+
export default {
22+
mixins: [classInformationMixin],
23+
data(){
24+
return {
25+
data: []
26+
}
27+
},
28+
computed: {
29+
storeType() {
30+
return 'student';
31+
},
32+
},
33+
mounted() {
34+
let classInformationId = this.$route.params.class_information;
35+
let classTeachingId = this.$route.params.class_teaching;
36+
store.dispatch('student/classInformation/get', classInformationId);
37+
store.dispatch('student/classTeaching/get', {classInformationId,classTeachingId})
38+
.then(this.getData)
39+
.then(data => {
40+
if(data.length === 1){
41+
return;
42+
}
43+
this.data = data;
44+
this.initGoogleCharts();
45+
})
46+
},
47+
methods:{
48+
initGoogleCharts(){
49+
let self = this;
50+
scriptjs('https://www.gstatic.com/charts/loader.js', function(){
51+
google.charts.load('current',{'packages': ['corechart']});
52+
google.charts.setOnLoadCallback(self.drawChart)
53+
});
54+
},
55+
drawChart(){
56+
let options = {
57+
title: `Aproveitamento da disciplina ${this.classTeaching.subject.name}`,
58+
curveType: 'function'
59+
};
60+
61+
let chart = new google.visualization.LineChart(document.getElementById('chart'));
62+
chart.draw(google.visualization.arrayToDataTable(this.data),options);
63+
},
64+
getData(){
65+
let data = [
66+
["Data Avaliação","Aproveitamento"],
67+
];
68+
return Student.classTestResult.perSubject({class_teaching: this.classTeaching.id})
69+
.then(response => {
70+
for(let object of response.data){
71+
//{created:, percentage:} -> ["",90]
72+
object.created_at = this.$options.filters.dateBr(object.created_at);
73+
data.push(Object.values(object));
74+
}
75+
return data;
76+
})
77+
}
78+
}
79+
}
80+
</script>

Diff for: resources/assets/spa/js/router.map.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,23 @@ export default [
8787
{
8888
name: 'student.class_tests.list',
8989
path: 'classes/:class_information/teachings/:class_teaching/tests',
90-
component: require('./components/Student/class_test/StudentClassTestList.vue'),
90+
component: require('./components/student/class_test/StudentClassTestList.vue'),
9191
meta: {
9292
auth: true
9393
}
9494
},
9595
{
9696
name: 'student.class_tests.do',
9797
path: 'classes/:class_information/teachings/:class_teaching/tests/:class_test/do/:student_class_test?',
98-
component: require('./components/Student/class_test/StudentClassTestDo.vue'),
98+
component: require('./components/student/class_test/StudentClassTestDo.vue'),
99+
meta: {
100+
auth: true
101+
}
102+
},
103+
{
104+
name: 'student.chart.per_subject',
105+
path: 'classes/:class_information/teachings/:class_teaching/charts/per_subject',
106+
component: require('./components/student/chart/StudentChartPerSubject.vue'),
99107
meta: {
100108
auth: true
101109
}

Diff for: resources/assets/spa/js/services/resources.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ const Student = {
4949
classInformation: Vue.resource('student/class_informations/{class_information}'),
5050
classTeaching: Vue.resource('student/class_informations/{class_information}/class_teachings/{class_teaching}'),
5151
classTest: Vue.resource('student/class_teachings/{class_teaching}/class_tests/{class_test}'),
52-
studentClassTest: Vue.resource('student/class_tests/{class_test}/do/{student_class_test}')
52+
studentClassTest: Vue.resource('student/class_tests/{class_test}/do/{student_class_test}'),
53+
classTestResult: Vue.resource('',{},{
54+
perSubject: {
55+
method: 'GET',
56+
url: 'student/class_tests/results/per_subject?class_teaching={class_teaching}'
57+
}
58+
})
5359
};
5460

5561
export {

Diff for: routes/api.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@
5151
Route::group(['prefix' => 'class_teachings/{class_teaching}', 'as' => 'class_teachings.'], function () {
5252
Route::resource('class_tests', 'ClassTestsController', ['only' => ['index', 'show']]);
5353
});
54-
Route::group(['prefix' => 'class_tests/{class_test}', 'as' => 'class_tests.'], function () {
55-
Route::resource('do', 'StudentClassTestsController', ['only' => ['show','store']]);
54+
Route::group(['prefix' => 'class_tests', 'as' => 'class_tests.'], function () {
55+
Route::group(['prefix' => '{class_test}'], function(){
56+
Route::resource('do', 'StudentClassTestsController', ['only' => ['show','store']]);
57+
});
58+
Route::group(['prefix' => 'results'], function(){ //class_tests/results/per_subject
59+
Route::get('per_subject', 'ClassTestResultsController@perSubject');
60+
});
5661
});
5762
Route::resource('class_informations', 'ClassInformationsController', ['only' => ['index', 'show']]);
5863
});

0 commit comments

Comments
 (0)