Show percentages for original and corrected points
This commit is contained in:
@@ -82,7 +82,9 @@ class SetModel extends BaseDatabaseModel
|
||||
}
|
||||
|
||||
$pointsBefore = 0;
|
||||
$pointsTotal = 0;
|
||||
foreach (($result['items'] ?? []) as $item) {
|
||||
$pointsTotal += (int) ($item['points'] ?? 0);
|
||||
if (!empty($item['correct'])) {
|
||||
$pointsBefore += (int) ($item['points'] ?? 0);
|
||||
}
|
||||
@@ -97,6 +99,7 @@ class SetModel extends BaseDatabaseModel
|
||||
'correct_count' => (int) ($result['correct'] ?? 0),
|
||||
'total_count' => (int) ($result['total'] ?? 0),
|
||||
'percentage' => (float) ($result['percentage'] ?? 0),
|
||||
'points_total' => $pointsTotal,
|
||||
'points_before' => $pointsBefore,
|
||||
'points_after' => $pointsBefore,
|
||||
'answers' => json_encode($result['items'] ?? [], JSON_UNESCAPED_UNICODE),
|
||||
|
||||
@@ -85,6 +85,9 @@ class HtmlView extends BaseHtmlView
|
||||
'items' => $results,
|
||||
'correct' => $correct,
|
||||
'total' => count($items),
|
||||
'points_total' => array_sum(array_map(static function ($item) {
|
||||
return (int) ($item->points ?? 0);
|
||||
}, $items)),
|
||||
'percentage' => count($items) ? round(($correct / count($items)) * 100, 2) : 0,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user