Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
185
Issues
185
List
Boards
Labels
Service Desk
Milestones
Merge Requests
33
Merge Requests
33
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
cd8300ae65decaa639f20d015f2bab0e319f5819...42e5591b26545d5422248c21ab58c43a2bcee4d4
Source
42e5591b26545d5422248c21ab58c43a2bcee4d4
Select Git revision
...
Target
cd8300ae65decaa639f20d015f2bab0e319f5819
Select Git revision
Compare
Commits (2)
(fix) Update UserStates Manager test with reward factor fields -
#589
· 8d2051bc
Guy Thouret
authored
1 hour ago
8d2051bc
(feat) Add state change value to UserState object -
#588
· 42e5591b
Guy Thouret
authored
11 minutes ago
42e5591b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
2 deletions
+39
-2
UserState.php
Core/Analytics/UserStates/UserState.php
+32
-1
ManagerSpec.php
Spec/Core/Analytics/UserStates/ManagerSpec.php
+4
-0
UserStateSpec.php
Spec/Core/Analytics/UserStates/UserStateSpec.php
+3
-1
No files found.
Core/Analytics/UserStates/UserState.php
View file @
42e5591b
...
...
@@ -22,6 +22,8 @@ use Minds\Traits\MagicAttributes;
* @method string getPreviousState()
* @method UserState setActivityPercentage(float $activityPercentage)
* @method float getActivityPercentage()
* @method UserState setStateChange(int $stateChange)
* @method int getUserState()
*/
class
UserState
{
...
...
@@ -33,6 +35,16 @@ class UserState
const
STATE_RESURRECTED
=
'resurrected'
;
const
STATE_UNKNOWN
=
'unknown'
;
const
STATE_INDEXES
=
[
self
::
STATE_UNKNOWN
=>
0
,
self
::
STATE_NEW
=>
1
,
self
::
STATE_COLD
=>
2
,
self
::
STATE_RESURRECTED
=>
3
,
self
::
STATE_CURIOUS
=>
4
,
self
::
STATE_CASUAL
=>
5
,
self
::
STATE_CORE
=>
6
,
];
use
MagicAttributes
;
/** @var int $userGuid */
...
...
@@ -50,8 +62,12 @@ class UserState
/** @var float $activityPercentage */
private
$activityPercentage
;
/** @var int $stateChange */
private
$stateChange
;
public
function
export
()
:
array
{
$this
->
deriveStateChange
();
return
[
'user_guid'
=>
$this
->
userGuid
,
'reference_date'
=>
$this
->
referenceDateMs
,
...
...
@@ -60,15 +76,30 @@ class UserState
'activity_percentage'
=>
$this
->
activityPercentage
,
'reward_factor'
=>
RewardFactor
::
getForUserState
(
$this
->
state
),
'previous_reward_factor'
=>
RewardFactor
::
getForUserState
(
$this
->
previousState
),
'state_change'
=>
$this
->
stateChange
];
}
private
function
deriveStateChange
()
:
void
{
$this
->
stateChange
=
self
::
stateChange
(
$this
->
previousState
,
$this
->
state
);
}
public
static
function
stateChange
(
?
string
$oldState
,
?
string
$newState
)
:
int
{
$oldStateIndex
=
self
::
STATE_INDEXES
[
$oldState
]
??
0
;
$newStateIndex
=
self
::
STATE_INDEXES
[
$newState
]
??
0
;
return
$newStateIndex
-
$oldStateIndex
;
}
public
static
function
fromArray
(
array
$data
)
:
UserState
{
return
(
new
UserState
())
->
setUserGuid
(
$data
[
'user_guid'
])
->
setReferenceDateMs
(
$data
[
'reference_date'
])
->
setState
(
$data
[
'state'
])
->
setPreviousState
(
$data
[
'previous_state'
])
->
setActivityPercentage
(
$data
[
'activity_percentage'
]);
->
setActivityPercentage
(
$data
[
'activity_percentage'
])
->
setStateChange
(
self
::
stateChange
(
$data
[
'previous_state'
],
$data
[
'state'
]));
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/UserStates/ManagerSpec.php
View file @
42e5591b
...
...
@@ -3,6 +3,7 @@
namespace
Spec\Minds\Core\Analytics\UserStates
;
use
Minds\Core\Analytics\UserStates\Manager
;
use
Minds\Core\Analytics\UserStates\UserState
;
use
Minds\Core\Data\ElasticSearch\Client
;
use
Minds\Core\Analytics\UserStates\ActiveUsersIterator
;
use
Minds\Core\Analytics\UserStates\UserStateIterator
;
...
...
@@ -77,6 +78,9 @@ class ManagerSpec extends ObjectBehavior
'state'
=>
'curious'
,
'previous_state'
=>
'resurrected'
,
'activity_percentage'
=>
'0.14'
,
'reward_factor'
=>
1
,
'previous_reward_factor'
=>
1.5
,
'state_change'
=>
UserState
::
stateChange
(
'resurrected'
,
'curious'
)
],
];
}
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Analytics/UserStates/UserStateSpec.php
View file @
42e5591b
...
...
@@ -18,7 +18,8 @@ class UserStateSpec extends ObjectBehavior
->
setReferenceDateMs
(
1549497600
)
->
setState
(
'cold'
)
->
setPreviousState
(
'curious'
)
->
setActivityPercentage
(
0.14
);
->
setActivityPercentage
(
0.14
)
->
setStateChange
(
UserState
::
stateChange
(
'curious'
,
'cold'
));
$export
=
$this
->
export
();
$export
->
shouldBeArray
();
$export
[
'user_guid'
]
->
shouldEqual
(
$this
->
getUserGuid
());
...
...
@@ -26,5 +27,6 @@ class UserStateSpec extends ObjectBehavior
$export
[
'state'
]
->
shouldEqual
(
$this
->
getState
());
$export
[
'previous_state'
]
->
shouldEqual
(
$this
->
getPreviousState
());
$export
[
'activity_percentage'
]
->
shouldEqual
(
$this
->
getActivityPercentage
());
$export
[
'state_change'
]
->
shouldEqual
(
$this
->
getStateChange
());
}
}
This diff is collapsed.
Click to expand it.