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
|
|
|
|