Completed
Pull Request — master (#32)
by Manuel
04:07
created

Statistics::totalPokes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace PiFinder\Services;
4
5
use DB;
6
use PiFinder\Poke;
7
use PiFinder\DeviceArchive;
8
9
class Statistics
10
{
11
    /**
12
     * Returns the count of all pokes.
13
     *
14
     * @return mixed
15
     */
16
    public function totalPokes()
17
    {
18
        $base = 189771;
19
20
        return DB::table('network_distribution')->sum('pokes') + $base;
21
    }
22
23
    /**
24
     * Returns the the count of all devices.
25
     *
26
     * @return mixed
27
     */
28
    public function totalDevices()
29
    {
30
        return DeviceArchive::count();
31
    }
32
33
    /**
34
     * Returns all pokes.
35
     *
36
     * @return mixed
37
     */
38
    public function allPokes()
39
    {
40
        return Poke::all();
41
    }
42
43
    /**
44
     * Returns a collection of all networks and it's count.
45
     *
46
     * @return mixed
47
     */
48
    public function networkDistribution()
49
    {
50
        $data = DB::table('network_distribution')
51
            ->select('network as label', 'pokes as value')
52
            ->get();
53
54
        return $this->addColors($data);
55
    }
56
57
    private function addColors($data)
58
    {
59
        $colors = ['rgb(23,103,153)', 'rgb(47,135,176)', 'rgb(66,164,187)', 'rgb(91,192,196)'];
60
        $highlight_colors = ['#8BB3CC', '#97C3D7', '#ADDFE1', '#BBEAE3'];
61
62
        return $data->each(function ($network, $i) use ($colors, $highlight_colors) {
63
            $network->color = $colors[$i];
64
            $network->highlight = $highlight_colors[$i];
65
        });
66
    }
67
}
68