SummaryService::getResultCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Entities\Problem;
6
use App\Status;
7
8
class SummaryService
9
{
10
    public static $statusTypes = [
11
        Status::ACCEPT,
12
        Status::PRESENTATION_ERROR,
13
        Status::WRONG_ANSWER,
14
        Status::TIME_LIMIT,
15
        Status::MEMORY_LIMIT,
16
        Status::OUTPUT_LIMIT,
17
        Status::RUNTIME_ERROR,
18
        Status::COMPILE_ERROR,
19
    ];
20
    public $acceptedUser = 0;
21
    public $submitUser = 0;
22
    public $total = 0;
23
    public $statistics;
24
    private $problem;
25
26
    public function __construct(Problem $problem)
27
    {
28
        $this->problem = $problem;
29
30
        $this->process();
31
    }
32
33
    private function process()
34
    {
35
        $service = new ProblemService();
36
37
        $this->statistics = [];
38
        $resultCount = $service->getResultCount($this->problem->id);
39
        foreach ($resultCount as $result) {
40
            $this->statistics[$result->result] = $result->user_count;
41
            $this->total += $result->user_count;
42
        }
43
    }
44
45
    public function getProblem()
46
    {
47
        return $this->problem;
48
    }
49
50
    public function accepted()
51
    {
52
        $service = new ProblemService();
53
54
        return $service->numberOfAcceptedUser($this->problem->id);
55
    }
56
57
    public function submit()
58
    {
59
        $service = new ProblemService();
60
61
        return $service->numberOfSubmitUser($this->problem->id);
62
    }
63
64
    public function getResultCount()
65
    {
66
        return (new ProblemService())->getResultCount($this->problem->id);
67
    }
68
69
    public function bestSolutions()
70
    {
71
        return (new ProblemService())->bestSolutions($this->problem->id);
72
    }
73
}
74