|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Redislabs\Module\RedisGraph; |
|
6
|
|
|
|
|
7
|
|
|
class Statistics |
|
8
|
|
|
{ |
|
9
|
|
|
private array $statistics = [ |
|
10
|
|
|
'LABELS_ADDED' => 0, |
|
11
|
|
|
'NODES_CREATED' => 0, |
|
12
|
|
|
'NODES_DELETED' => 0, |
|
13
|
|
|
'RELATIONSHIPS_CREATED' => 0, |
|
14
|
|
|
'RELATIONSHIPS_DELETED' => 0, |
|
15
|
|
|
'PROPERTIES_SET' => 0, |
|
16
|
|
|
'CACHED_EXECUTION' => 0, |
|
17
|
|
|
'INTERNAL_EXECUTION_TIME' => '0.0' |
|
18
|
|
|
]; |
|
19
|
|
|
private static array $availableStatistics = [ |
|
20
|
|
|
'Labels added' => 'LABELS_ADDED', |
|
21
|
|
|
'Nodes created' => 'NODES_CREATED', |
|
22
|
|
|
'Nodes deleted' => 'NODES_DELETED', |
|
23
|
|
|
'Cached execution' => 'CACHED_EXECUTION', |
|
24
|
|
|
'Relationships deleted' => 'RELATIONSHIPS_DELETED', |
|
25
|
|
|
'Properties set' => 'PROPERTIES_SET', |
|
26
|
|
|
'Relationships created' => 'RELATIONSHIPS_CREATED', |
|
27
|
|
|
'Query internal execution time' => 'INTERNAL_EXECUTION_TIME', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(array $statistics) |
|
31
|
|
|
{ |
|
32
|
|
|
foreach ($statistics as $stat) { |
|
33
|
|
|
$statDetails = $this->getStat($stat); |
|
34
|
|
|
if ($statDetails !== null) { |
|
35
|
|
|
$this->statistics[$statDetails['key']] = $statDetails['value']; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function getStat($stat): array |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
$statDetails = explode(':', $stat); |
|
44
|
|
|
$statName = self::$availableStatistics[$statDetails[0]]; |
|
45
|
|
|
if ($statName === 'INTERNAL_EXECUTION_TIME') { |
|
46
|
|
|
return ['key' => $statName, 'value' => (float) $statDetails[1]]; |
|
47
|
|
|
} |
|
48
|
|
|
return ['key' => $statName, 'value' => (int) $statDetails[1]]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getResultStatistics(): array |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->statistics; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|