Skip to content

Commit 957cbaa

Browse files
committed
Implementation of sum of points for students statistics. ShadowAssignmentEvaluation added author column.
1 parent 3b10bd4 commit 957cbaa

File tree

4 files changed

+65
-25
lines changed

4 files changed

+65
-25
lines changed

app/config/config.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ services:
342342
- App\Model\Repository\Pipelines
343343
- App\Model\Repository\SisGroupBindings
344344
- App\Model\Repository\SisValidTerms
345+
- App\Model\Repository\ShadowAssignments
346+
- App\Model\Repository\ShadowAssignmentEvaluations
345347

346348
# views factories
347349
- App\Model\View\ExerciseViewFactory

app/model/entity/ShadowAssignmentEvaluation.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
* @method string getId()
1212
* @method string getNote()
1313
* @method ShadowAssignment getShadowAssignment()
14+
* @method User getAuthor()
1415
* @method int getPoints()
1516
* @method setPoints(int $points)
1617
*/
1718
class ShadowAssignmentEvaluation
1819
{
1920
use MagicAccessors;
2021

21-
public function __construct(string $note, ShadowAssignment $shadowAssignment) {
22-
$this->points = 0;
22+
public function __construct(int $points, string $note, ShadowAssignment $shadowAssignment, User $author) {
23+
$this->points = $points;
2324
$this->shadowAssignment = $shadowAssignment;
2425
$this->note = $note;
26+
$this->author = $author;
2527
}
2628

2729
/**
@@ -31,6 +33,11 @@ public function __construct(string $note, ShadowAssignment $shadowAssignment) {
3133
*/
3234
protected $id;
3335

36+
/**
37+
* @ORM\Column(type="integer")
38+
*/
39+
protected $points;
40+
3441
/**
3542
* @ORM\Column(type="text")
3643
*/
@@ -43,8 +50,8 @@ public function __construct(string $note, ShadowAssignment $shadowAssignment) {
4350
protected $shadowAssignment;
4451

4552
/**
46-
* @ORM\Column(type="integer")
53+
* @ORM\ManyToOne(targetEntity="User")
4754
*/
48-
protected $points;
55+
protected $author;
4956

5057
}

app/model/repository/ShadowAssignmentEvaluations.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@
22

33
namespace App\Model\Repository;
44

5+
use App\Model\Entity\ShadowAssignment;
56
use App\Model\Entity\ShadowAssignmentEvaluation;
7+
use App\Model\Entity\User;
68
use Kdyby\Doctrine\EntityManager;
79

810
/**
911
* @method ShadowAssignmentEvaluation findOrThrow($id)
1012
*/
11-
class ShadowAssignmentEvaluations extends BaseSoftDeleteRepository {
13+
class ShadowAssignmentEvaluations extends BaseRepository {
1214

1315
public function __construct(EntityManager $em) {
1416
parent::__construct($em, ShadowAssignmentEvaluation::class);
1517
}
1618

19+
/**
20+
* Find best solutions of given assignments for user.
21+
* @param ShadowAssignment[] $shadowAssignments
22+
* @param User $user
23+
* @return ShadowAssignmentEvaluation[]
24+
*/
25+
public function findEvaluationsForAssignment(array $shadowAssignments, User $user): array {
26+
return $this->findBy([
27+
"author" => $user,
28+
"assignment" => $shadowAssignments,
29+
]);
30+
}
31+
1732
}

app/model/view/GroupViewFactory.php

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
use App\Model\Entity\AssignmentSolution;
1212
use App\Model\Entity\Group;
1313
use App\Model\Entity\LocalizedGroup;
14+
use App\Model\Entity\ShadowAssignment;
15+
use App\Model\Entity\ShadowAssignmentEvaluation;
1416
use App\Model\Entity\User;
1517
use App\Model\Repository\AssignmentSolutions;
18+
use App\Model\Repository\ShadowAssignmentEvaluations;
1619
use App\Security\ACL\IAssignmentPermissions;
1720
use App\Security\ACL\IGroupPermissions;
1821
use Doctrine\Common\Collections\Collection;
@@ -24,30 +27,29 @@
2427
*/
2528
class GroupViewFactory {
2629

27-
/**
28-
* @var AssignmentSolutions
29-
*/
30+
/** @var AssignmentSolutions */
3031
private $assignmentSolutions;
3132

32-
/**
33-
* @var IGroupPermissions
34-
*/
33+
/** @var IGroupPermissions */
3534
private $groupAcl;
3635

37-
/**
38-
* @var IAssignmentPermissions
39-
*/
36+
/** @var IAssignmentPermissions */
4037
private $assignmentAcl;
4138

4239
/** @var GroupBindingAccessor */
4340
private $bindings;
4441

42+
/** @var ShadowAssignmentEvaluations */
43+
private $shadowAssignmentEvaluations;
44+
4545
public function __construct(AssignmentSolutions $assignmentSolutions, IGroupPermissions $groupAcl,
46-
IAssignmentPermissions $assignmentAcl, GroupBindingAccessor $bindings) {
46+
IAssignmentPermissions $assignmentAcl, GroupBindingAccessor $bindings,
47+
ShadowAssignmentEvaluations $shadowAssignmentEvaluations) {
4748
$this->assignmentSolutions = $assignmentSolutions;
4849
$this->groupAcl = $groupAcl;
4950
$this->assignmentAcl = $assignmentAcl;
5051
$this->bindings = $bindings;
52+
$this->shadowAssignmentEvaluations = $shadowAssignmentEvaluations;
5153
}
5254

5355

@@ -72,12 +74,16 @@ function ($carry, Pair $solutionPair) {
7274
}
7375

7476
/**
75-
* @param Group $group
76-
* @param User $user
77+
* Get total sum of points which given user gained in given shadow assignments.
78+
* @param ShadowAssignmentEvaluation[] $shadowEvaluations
7779
* @return int
7880
*/
79-
private function getPointsForShadowAssignments(Group $group, User $user): int {
80-
// TODO
81+
private function getPointsForShadowAssignments(array $shadowEvaluations): int {
82+
return array_reduce($shadowEvaluations,
83+
function ($carry, ShadowAssignmentEvaluation $evaluation) {
84+
return $carry + $evaluation->getPoints();
85+
},
86+
0);
8187
}
8288

8389
/**
@@ -88,12 +94,13 @@ private function getPointsForShadowAssignments(Group $group, User $user): int {
8894
*/
8995
public function getStudentsStats(Group $group, User $student) {
9096
$maxPoints = $group->getMaxPoints();
91-
$solutions = $this->assignmentSolutions->findBestSolutionsForAssignments($group->getAssignments()->getValues(), $student);
92-
$gainedPoints = $this->getPointsGainedByStudentForSolutions($solutions);
93-
$gainedPoints += $this->getPointsForShadowAssignments($group, $student);
97+
$assignmentSolutions = $this->assignmentSolutions->findBestSolutionsForAssignments($group->getAssignments()->getValues(), $student);
98+
$shadowEvaluations = $this->shadowAssignmentEvaluations->findEvaluationsForAssignment($group->getShadowAssignments()->getValues(), $student);
99+
$gainedPoints = $this->getPointsGainedByStudentForSolutions($assignmentSolutions);
100+
$gainedPoints += $this->getPointsForShadowAssignments($shadowEvaluations);
94101

95102
$assignments = [];
96-
foreach ($solutions as $solutionPair) {
103+
foreach ($assignmentSolutions as $solutionPair) {
97104
/**
98105
* @var Assignment $assignment
99106
* @var AssignmentSolution $best
@@ -113,8 +120,17 @@ public function getStudentsStats(Group $group, User $student) {
113120
];
114121
}
115122

116-
// TODO: points assignments
117-
$shadowAssignments = null;
123+
$shadowAssignments = [];
124+
foreach ($shadowEvaluations as $evaluation) {
125+
$assignment = $evaluation->getShadowAssignment();
126+
$shadowAssignments[] = [
127+
"id" => $assignment->getId(),
128+
"points" => [
129+
"total" => $assignment->getMaxPoints(),
130+
"gained" => $evaluation->getPoints()
131+
]
132+
];
133+
}
118134

119135
return [
120136
"userId" => $student->getId(),

0 commit comments

Comments
 (0)