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
31
Merge Requests
31
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
59e50c27da213605582a53855c28330ec3e369b2...1808489730f9e15f448d8f0897a8dc47fcf6c11f
Source
1808489730f9e15f448d8f0897a8dc47fcf6c11f
Select Git revision
...
Target
59e50c27da213605582a53855c28330ec3e369b2
Select Git revision
Compare
Commits (6)
(fix) Rewards\Contributions: Fix typo in word contribution -
#587
· 01b11f8d
Guy Thouret
authored
1 day ago
01b11f8d
(fix) Spec bootstrap should load configs (prevents errors connecting to Redis and MQ in dev) -
#587
· c036456b
Guy Thouret
authored
21 hours ago
c036456b
(chore) Add missing help descriptions to rewards cli controller -
#587
· d0425dd2
Guy Thouret
authored
21 hours ago
d0425dd2
(feat) Add missing type hints in Contributions Manager -
#588
· 444c6081
Guy Thouret
authored
21 hours ago
444c6081
(feat) Add action types help text and dry run warning to rewards cli -
#587
· f150613d
Guy Thouret
authored
1 hour ago
f150613d
(feat) Apply the user state reward multiplier to contribution scores -
#587
· 18084897
Guy Thouret
authored
1 hour ago
18084897
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
25 deletions
+55
-25
Rewards.php
Controllers/Cli/Rewards.php
+27
-7
Manager.php
Core/Rewards/Contributions/Manager.php
+26
-17
Overview.php
Core/Rewards/Contributions/Overview.php
+1
-1
bootstrap.php
Spec/bootstrap.php
+1
-0
No files found.
Controllers/Cli/Rewards.php
View file @
18084897
...
...
@@ -16,17 +16,33 @@ use Minds\Core\Events\Dispatcher;
class
Rewards
extends
Cli\Controller
implements
Interfaces\CliControllerInterface
{
private
$start
;
private
$elasticsearch
;
public
function
help
(
$command
=
null
)
{
$this
->
out
(
'Syntax usage: cli trending <type>'
);
switch
(
$command
)
{
case
'sync'
:
$this
->
out
(
'Get rewards for all users'
);
$this
->
out
(
'--timestamp={timestamp} the day to start from. Default is yesterday at midnight'
);
$this
->
out
(
'--action={active|subscribe|jury-duty} Type of action'
);
$this
->
out
(
'--dry-run={true|false} true prevents saving the data'
);
break
;
case
'single'
:
$this
->
out
(
'Get rewards for a single user'
);
$this
->
out
(
'--guid={guid} the guid of the user to get rewards for'
);
$this
->
out
(
'--timestamp={timestamp} the day to start from. Default is yesterday at midnight'
);
break
;
case
'issue'
:
$this
->
out
(
'Issue tokens to a user'
);
$this
->
out
(
'--username={string username} username of the user to issue tokens to'
);
$this
->
out
(
'--amount={number of tokens} Number of tokens to issue'
);
default
:
$this
->
out
(
'Syntax usage: cli rewards <type>'
);
$this
->
displayCommandHelp
();
}
}
public
function
exec
()
{
return
$this
->
help
();
}
public
function
sync
()
...
...
@@ -34,9 +50,13 @@ class Rewards extends Cli\Controller implements Interfaces\CliControllerInterfac
error_reporting
(
E_ALL
);
ini_set
(
'display_errors'
,
1
);
$timestamp
=
$this
->
getOpt
(
'timestamp'
)
?:
(
strtotime
(
'midnight -24 hours'
)
*
1000
);
$to
=
strtotime
(
"+24 hours"
,
$timestamp
/
1000
)
*
1000
;
$dryRun
=
$this
->
getOpt
(
'dry-run'
)
===
'true'
;
if
(
$dryRun
)
{
$this
->
out
(
'DRY RUN'
);
}
$users
=
new
UsersIterator
;
$users
->
setFrom
(
$timestamp
)
...
...
@@ -68,7 +88,7 @@ class Rewards extends Cli\Controller implements Interfaces\CliControllerInterfac
$manager
->
setFrom
(
$timestamp
)
->
setTo
(
$to
);
$manager
->
setUser
(
$user
);
$manager
->
setDryRun
(
$
this
->
getOpt
(
'dry-run'
)
);
$manager
->
setDryRun
(
$
dryRun
);
$reward
=
$manager
->
sync
();
$total
=
$total
->
add
(
$reward
->
getAmount
());
$leaderboard
[
$user
->
guid
]
=
(
$reward
->
getAmount
()
/
(
10
**
18
));
...
...
This diff is collapsed.
Click to expand it.
Core/Rewards/Contributions/Manager.php
View file @
18084897
...
...
@@ -6,17 +6,26 @@ namespace Minds\Core\Rewards\Contributions;
use
Minds\Core\Analytics
;
use
Minds\Core\Util\BigNumber
;
use
Minds\Entities\User
;
class
Manager
{
/** @var Analytics\Manager */
protected
$analytics
;
/** @var Repository */
protected
$repository
;
/** @var User */
protected
$user
;
/** @var int */
protected
$from
;
/** @var int */
protected
$to
;
/** @var bool */
protected
$dryRun
=
false
;
protected
$site_contribtion_score_cache
=
[];
/** @var array */
protected
$site_contribution_score_cache
=
[];
/** @var Sums */
protected
$sums
;
public
function
__construct
(
$analytics
=
null
,
$repository
=
null
,
$sums
=
null
)
{
...
...
@@ -27,7 +36,7 @@ class Manager
$this
->
to
=
time
()
*
1000
;
}
public
function
setUser
(
$user
)
public
function
setUser
(
$user
)
:
self
{
$this
->
user
=
$user
;
return
$this
;
...
...
@@ -39,25 +48,25 @@ class Manager
* @param bool $dryRun
* @return $this
*/
public
function
setDryRun
(
$dryRun
)
public
function
setDryRun
(
$dryRun
)
:
self
{
$this
->
dryRun
=
$dryRun
;
return
$this
;
}
public
function
setFrom
(
$from
)
public
function
setFrom
(
$from
)
:
self
{
$this
->
from
=
$from
;
return
$this
;
}
public
function
setTo
(
$to
)
public
function
setTo
(
$to
)
:
self
{
$this
->
to
=
$to
;
return
$this
;
}
public
function
sync
()
public
function
sync
()
:
array
{
$this
->
analytics
->
setFrom
(
$this
->
from
)
...
...
@@ -73,10 +82,11 @@ class Manager
foreach
(
$this
->
analytics
->
getCounts
()
as
$ts
=>
$data
)
{
foreach
(
$data
as
$metric
=>
$count
)
{
$multiplier
=
ContributionValues
::
$multipliers
[
$metric
];
$userStateMultiplier
=
Analytics\UserStates\RewardFactor
::
getForUserState
(
$this
->
user
->
getUserState
());
$contribution
=
new
Contribution
();
$contribution
->
setMetric
(
$metric
)
->
setTimestamp
(
$ts
)
->
setScore
(
$count
*
$multiplier
)
->
setScore
(
$count
*
$multiplier
*
$userStateMultiplier
)
->
setAmount
(
$count
);
if
(
$this
->
user
)
{
...
...
@@ -86,7 +96,6 @@ class Manager
}
}
if
(
$this
->
dryRun
)
{
return
$contributions
;
}
...
...
@@ -101,12 +110,12 @@ class Manager
* @param Contribution $contribution
* @return bool
*/
public
function
add
(
Contribution
$contribution
)
:
bool
public
function
add
(
Contribution
$contribution
)
:
bool
{
return
(
bool
)
$this
->
repository
->
add
(
$contribution
);
}
public
function
issueCheckins
(
$count
)
public
function
issueCheckins
(
$count
)
:
void
{
$multiplier
=
ContributionValues
::
$multipliers
[
'checkin'
];
$contribution
=
new
Contribution
();
...
...
@@ -122,12 +131,12 @@ class Manager
/**
* Gather the entire site contribution score
*/
public
function
getSiteContribtionScore
()
public
function
getSiteContrib
u
tionScore
()
{
if
(
isset
(
$this
->
site_contribtion_score_cache
[
$this
->
from
]))
{
return
$this
->
site_contribtion_score_cache
[
$this
->
from
];
if
(
isset
(
$this
->
site_contrib
u
tion_score_cache
[
$this
->
from
]))
{
return
$this
->
site_contrib
u
tion_score_cache
[
$this
->
from
];
}
return
$this
->
site_contribtion_score_cache
[
$this
->
from
]
=
$this
->
sums
return
$this
->
site_contrib
u
tion_score_cache
[
$this
->
from
]
=
$this
->
sums
->
setTimestamp
(
$this
->
from
)
->
setUser
(
null
)
->
getScore
();
...
...
@@ -137,7 +146,7 @@ class Manager
* Gather the contribution score for the user
* @return int
*/
public
function
getUserContributionScore
()
public
function
getUserContributionScore
()
:
int
{
return
$this
->
sums
->
setTimestamp
(
$this
->
from
)
...
...
@@ -149,7 +158,7 @@ class Manager
* Return the number of tokens to be rewarded
* @return string
*/
public
function
getRewardsAmount
()
public
function
getRewardsAmount
()
:
string
{
//$share = BigNumber::_($this->getUserContributionScore(), 18)->div($this->getSiteContribtionScore());
//$pool = BigNumber::toPlain('100000000', 18)->div(15)->div(365);
...
...
This diff is collapsed.
Click to expand it.
Core/Rewards/Contributions/Overview.php
View file @
18084897
...
...
@@ -99,7 +99,7 @@ class Overview
$this
->
manager
->
setUser
(
$this
->
user
);
$this
->
manager
->
setFrom
(
$timestamp
);
$this
->
totalNetworkContribution
=
$this
->
manager
->
getSiteContribtionScore
();
$this
->
totalNetworkContribution
=
$this
->
manager
->
getSiteContrib
u
tionScore
();
$this
->
yourContribution
=
$this
->
manager
->
getUserContributionScore
();
$this
->
currentReward
=
$this
->
manager
->
getRewardsAmount
();
...
...
This diff is collapsed.
Click to expand it.
Spec/bootstrap.php
View file @
18084897
...
...
@@ -8,6 +8,7 @@ date_default_timezone_set('UTC');
$minds
=
new
Minds\Core\Minds
();
$minds
->
loadLegacy
();
$minds
->
loadConfigs
();
$CONFIG
=
Minds\Core\Di\Di
::
_
()
->
get
(
'Config'
);
$CONFIG
->
default_access
=
2
;
...
...
This diff is collapsed.
Click to expand it.