...
 
......@@ -44,17 +44,7 @@ class UpdateUserStateEstimate
private function sendStateChangeNotification(): void
{
$data = [
$this->user->getGUID(),
$this->user->getUserState(),
$this->user->getUserStateToday(),
$this->userState->getStateChange(),
$this->estimateStateChange
];
error_log(implode('|', $data));
if ($this->estimateStateChange < 0 && $this->userState->getStateChange() < 0) {
if ($this->estimateStateChange < 0) {
$notificationView = 'rewards_state_decrease_today';
Dispatcher::trigger('notification', 'reward', [
'to' => [
......
......@@ -98,6 +98,7 @@ class ActiveUsersIterator implements \Iterator
$userActivityBuckets->setActiveDaysBuckets($days);
$this->data[] = $userActivityBuckets;
}
if ($this->cursor >= count($this->data)) {
$this->get();
}
......
<?php
namespace Spec\Minds\Core\Analytics\UserStates;
use Minds\Core\Analytics\UserStates\ActiveUsersQueryBuilder;
use PhpSpec\ObjectBehavior;
class ActiveUsersQueryBuilderSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(ActiveUsersQueryBuilder::class);
}
public function it_should_produce_a_valid_query()
{
$from = strtotime('midnight -2 days');
$to = strtotime('midnight');
$this->setPartitions(10)->setPage(2)->setFrom($from)->setTo($to)->query()->shouldBe($this->exampleQuery());
}
private function exampleQuery(): array
{
$query = '{
"index": "minds-metrics-*",
"size": "0",
"body": {
"query": {
"bool": {
"must": [
{
"match_phrase": {
"action.keyword": {
"query": "active"
}
}
},
{
"range": {
"@timestamp": {
"from": 1568073600000,
"to": 1568246400000,
"format": "epoch_millis"
}
}
}
]
}
},
"aggs": {
"users": {
"terms": {
"field": "user_guid.keyword",
"size": 5000,
"include": {
"partition": 2,
"num_partitions": 10
}
},
"aggs": {
"1568160000": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1568160000000,
"to": 1568246400000
}
]
}
},
"count-1568160000": {
"sum_bucket": {
"buckets_path": "1568160000>_count"
}
},
"1568246400": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1568246400000,
"to": 1568332800000
}
]
}
},
"count-1568246400": {
"sum_bucket": {
"buckets_path": "1568246400>_count"
}
}
}
}
}
}
}';
return json_decode($query, true);
}
}
......@@ -16,7 +16,7 @@
"range": {
"@timestamp": {
"from": 1548892800000,
"to": 1549584000000,
"to": 1549497600000,
"format": "epoch_millis"
}
}
......@@ -35,55 +35,55 @@
}
},
"aggs": {
"day-0-bucket": {
"1548979200": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1549497600000,
"to": 1549584000000
"from": 1548979200000,
"to": 1549065600000
}
]
}
},
"day-0": {
"count-1548979200": {
"sum_bucket": {
"buckets_path": "day-0-bucket>_count"
"buckets_path": "1548979200>_count"
}
},
"day-1-bucket": {
"1549065600": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1549411200000,
"to": 1549497600000
"from": 1549065600000,
"to": 1549152000000
}
]
}
},
"day-1": {
"count-1549065600": {
"sum_bucket": {
"buckets_path": "day-1-bucket>_count"
"buckets_path": "1549065600>_count"
}
},
"day-2-bucket": {
"1549152000": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1549324800000,
"to": 1549411200000
"from": 1549152000000,
"to": 1549238400000
}
]
}
},
"day-2": {
"count-1549152000": {
"sum_bucket": {
"buckets_path": "day-2-bucket>_count"
"buckets_path": "1549152000>_count"
}
},
"day-3-bucket": {
"1549238400": {
"date_range": {
"field": "@timestamp",
"ranges": [
......@@ -94,77 +94,61 @@
]
}
},
"day-3": {
"count-1549238400": {
"sum_bucket": {
"buckets_path": "day-3-bucket>_count"
"buckets_path": "1549238400>_count"
}
},
"day-4-bucket": {
"1549324800": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1549152000000,
"to": 1549238400000
}
]
}
},
"day-4": {
"sum_bucket": {
"buckets_path": "day-4-bucket>_count"
}
},
"day-5-bucket": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1549065600000,
"to": 1549152000000
"from": 1549324800000,
"to": 1549411200000
}
]
}
},
"day-5": {
"count-1549324800": {
"sum_bucket": {
"buckets_path": "day-5-bucket>_count"
"buckets_path": "1549324800>_count"
}
},
"day-6-bucket": {
"1549411200": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1548979200000,
"to": 1549065600000
"from": 1549411200000,
"to": 1549497600000
}
]
}
},
"day-6": {
"count-1549411200": {
"sum_bucket": {
"buckets_path": "day-6-bucket>_count"
"buckets_path": "1549411200>_count"
}
},
"day-7-bucket": {
"1549497600": {
"date_range": {
"field": "@timestamp",
"ranges": [
{
"from": 1548892800000,
"to": 1548979200000
"from": 1549497600000,
"to": 1549584000000
}
]
}
},
"day-7": {
"count-1549497600": {
"sum_bucket": {
"buckets_path": "day-7-bucket>_count"
"buckets_path": "1549497600>_count"
}
}
}
}
}
}
}
\ No newline at end of file
}
......@@ -20,31 +20,19 @@
{
"key": "934155581860614163",
"doc_count": 1,
"day-2-bucket": {
"1548979200": {
"buckets": [
{
"key": "2019-02-05T00:00:00.000Z-2019-02-06T00:00:00.000Z",
"from": 1549324800000,
"from_as_string": "2019-02-05T00:00:00.000Z",
"to": 1549411200000,
"to_as_string": "2019-02-06T00:00:00.000Z",
"key": "2019-02-01T00:00:00.000Z-2019-02-02T00:00:00.000Z",
"from": 1548979200000,
"from_as_string": "2019-02-01T00:00:00.000Z",
"to": 1549065600000,
"to_as_string": "2019-02-02T00:00:00.000Z",
"doc_count": 0
}
]
},
"day-1-bucket": {
"buckets": [
{
"key": "2019-02-06T00:00:00.000Z-2019-02-07T00:00:00.000Z",
"from": 1549411200000,
"from_as_string": "2019-02-06T00:00:00.000Z",
"to": 1549497600000,
"to_as_string": "2019-02-07T00:00:00.000Z",
"doc_count": 1
}
]
},
"day-5-bucket": {
"1549065600": {
"buckets": [
{
"key": "2019-02-02T00:00:00.000Z-2019-02-03T00:00:00.000Z",
......@@ -56,19 +44,19 @@
}
]
},
"day-7-bucket": {
"1549152000": {
"buckets": [
{
"key": "2019-01-31T00:00:00.000Z-2019-02-01T00:00:00.000Z",
"from": 1548892800000,
"from_as_string": "2019-01-31T00:00:00.000Z",
"to": 1548979200000,
"to_as_string": "2019-02-01T00:00:00.000Z",
"key": "2019-02-03T00:00:00.000Z-2019-02-04T00:00:00.000Z",
"from": 1549152000000,
"from_as_string": "2019-02-03T00:00:00.000Z",
"to": 1549238400000,
"to_as_string": "2019-02-04T00:00:00.000Z",
"doc_count": 0
}
]
},
"day-3-bucket": {
"1549238400": {
"buckets": [
{
"key": "2019-02-04T00:00:00.000Z-2019-02-05T00:00:00.000Z",
......@@ -80,68 +68,65 @@
}
]
},
"day-0-bucket": {
"1549324800": {
"buckets": [
{
"key": "2019-02-07T00:00:00.000Z-2019-02-08T00:00:00.000Z",
"from": 1549497600000,
"from_as_string": "2019-02-07T00:00:00.000Z",
"to": 1549584000000,
"to_as_string": "2019-02-08T00:00:00.000Z",
"key": "2019-02-05T00:00:00.000Z-2019-02-06T00:00:00.000Z",
"from": 1549324800000,
"from_as_string": "2019-02-05T00:00:00.000Z",
"to": 1549411200000,
"to_as_string": "2019-02-06T00:00:00.000Z",
"doc_count": 0
}
]
},
"day-6-bucket": {
"1549411200": {
"buckets": [
{
"key": "2019-02-01T00:00:00.000Z-2019-02-02T00:00:00.000Z",
"from": 1548979200000,
"from_as_string": "2019-02-01T00:00:00.000Z",
"to": 1549065600000,
"to_as_string": "2019-02-02T00:00:00.000Z",
"doc_count": 0
"key": "2019-02-06T00:00:00.000Z-2019-02-07T00:00:00.000Z",
"from": 1549411200000,
"from_as_string": "2019-02-06T00:00:00.000Z",
"to": 1549497600000,
"to_as_string": "2019-02-07T00:00:00.000Z",
"doc_count": 1
}
]
},
"day-4-bucket": {
"1549497600": {
"buckets": [
{
"key": "2019-02-03T00:00:00.000Z-2019-02-04T00:00:00.000Z",
"from": 1549152000000,
"from_as_string": "2019-02-03T00:00:00.000Z",
"to": 1549238400000,
"to_as_string": "2019-02-04T00:00:00.000Z",
"key": "2019-02-07T00:00:00.000Z-2019-02-08T00:00:00.000Z",
"from": 1549497600000,
"from_as_string": "2019-02-07T00:00:00.000Z",
"to": 1549584000000,
"to_as_string": "2019-02-08T00:00:00.000Z",
"doc_count": 0
}
]
},
"day-0": {
"value": 0
},
"day-1": {
"count-1548979200": {
"value": 1
},
"day-2": {
"count-1549065600": {
"value": 0
},
"day-3": {
"count-1549152000": {
"value": 0
},
"day-4": {
"count-1549238400": {
"value": 0
},
"day-5": {
"count-1549324800": {
"value": 0
},
"day-6": {
"count-1549411200": {
"value": 0
},
"day-7": {
"count-1549497600": {
"value": 0
}
}
]
}
}
}
\ No newline at end of file
}