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
|
1 |
|
public function totalPokes() |
17
|
|
|
{ |
18
|
1 |
|
$base = 189771; |
19
|
|
|
|
20
|
1 |
|
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
|
1 |
|
public function totalDevices() |
29
|
|
|
{ |
30
|
1 |
|
return DeviceArchive::count(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns all pokes. |
35
|
|
|
* |
36
|
|
|
* @return mixed |
37
|
|
|
*/ |
38
|
1 |
|
public function allPokes() |
39
|
|
|
{ |
40
|
1 |
|
return Poke::all(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns a collection of all networks and it's count. |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
1 |
|
public function networkDistribution() |
49
|
|
|
{ |
50
|
1 |
|
$data = DB::table('network_distribution') |
51
|
1 |
|
->select('network as label', 'pokes as value') |
52
|
1 |
|
->get(); |
53
|
|
|
|
54
|
1 |
|
return $this->addColors($data); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
private function addColors($data) |
58
|
|
|
{ |
59
|
1 |
|
$colors = ['rgb(23,103,153)', 'rgb(47,135,176)', 'rgb(66,164,187)', 'rgb(91,192,196)']; |
60
|
1 |
|
$highlight_colors = ['#8BB3CC', '#97C3D7', '#ADDFE1', '#BBEAE3']; |
61
|
|
|
|
62
|
1 |
|
return $data->each(function ($network, $i) use ($colors, $highlight_colors) { |
63
|
1 |
|
$network->color = $colors[$i]; |
64
|
1 |
|
$network->highlight = $highlight_colors[$i]; |
65
|
1 |
|
}); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|