Completed
Push — master ( 2402a0...52ee14 )
by Manuel
08:57
created

Statistics   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 5
c 5
b 1
f 2
lcom 0
cbo 1
dl 0
loc 59
ccs 19
cts 19
cp 1
rs 10

5 Methods

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