Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (3)
(fix) Fix expected value in Rewards Manager Spec test
· 00beca90
Guy Thouret
authored
Jul 30, 2019
00beca90
(chore) Add missing command help and dry run option to contributions cli -
#587
· 9c166d03
Guy Thouret
authored
Jul 31, 2019
9c166d03
(feat) Add decimal score value to contributions table -
#587
· 3b80c207
Guy Thouret
authored
Jul 31, 2019
3b80c207
Hide whitespace changes
Inline
Side-by-side
Controllers/Cli/Contributions.php
View file @
3b80c207
...
...
@@ -2,29 +2,41 @@
namespace
Minds\Controllers\Cli
;
use
DateTime
;
use
Elasticsearch\ClientBuilder
;
use
Minds\Cli
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities
;
use
Minds\Helpers\Flags
;
use
Minds\Interfaces
;
use
Minds\Core\Rewards\Contributions\UsersIterator
;
class
Contributions
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 contributions for all users'
);
$this
->
out
(
'--from={timestamp} the day to start from. Default is yesterday at midnight'
);
$this
->
out
(
'--incremental={true|false} Provide estimates during current day'
);
$this
->
out
(
'--action={active|subscribe|jury-duty} Type of action'
);
$this
->
out
(
'--dry-run={true|false} true prevents saving the data'
);
break
;
case
'syncCheckins'
:
$this
->
out
(
'--from={timestamp} the day to start from. Default is yesterday at midnight'
);
$this
->
out
(
'--incremental={true|false} Provide estimates during current day'
);
break
;
case
'test'
:
$this
->
out
(
'Test contributions for a user'
);
$this
->
out
(
'--from={timestamp} the day to start from. Default is 7 days ago'
);
$this
->
out
(
'--guid={guid} the guid of the user to get contributions for'
);
default
:
$this
->
out
(
'Syntax usage: cli contributions <command>'
);
$this
->
displayCommandHelp
();
}
}
public
function
exec
()
{
return
$this
->
help
();
}
public
function
sync
()
...
...
@@ -33,6 +45,7 @@ class Contributions extends Cli\Controller implements Interfaces\CliControllerIn
ini_set
(
'display_errors'
,
1
);
$from
=
$this
->
getOpt
(
'from'
);
$dryRun
=
$this
->
getOpt
(
'dry-run'
)
===
'true'
;
if
(
!
$from
&&
$this
->
getOpt
(
'incremental'
))
{
$from
=
strtotime
(
'midnight'
)
*
1000
;
//run throughout the day, provides estimates
...
...
@@ -65,8 +78,8 @@ class Contributions extends Cli\Controller implements Interfaces\CliControllerIn
$manager
=
new
Core\Rewards\Contributions\Manager
();
$manager
->
setFrom
(
$from
)
->
setUser
(
$user
)
;
//$manager
->setDryRun(
true
);
->
setUser
(
$user
)
->
setDryRun
(
$dryRun
);
$results
=
$manager
->
sync
();
foreach
(
$results
as
$result
)
{
...
...
Core/Provisioner/Provisioners/cassandra-provision.cql
View file @
3b80c207
...
...
@@ -260,6 +260,7 @@ CREATE TABLE minds.contributions (
metric text,
amount varint,
score varint,
score_decimal decimal,
PRIMARY KEY (user_guid, timestamp, metric)
) WITH CLUSTERING ORDER BY (timestamp DESC, metric ASC)
AND bloom_filter_fp_chance = 0.01
...
...
@@ -278,9 +279,9 @@ CREATE TABLE minds.contributions (
AND speculative_retry = '99PERCENTILE';
CREATE MATERIALIZED VIEW minds.contributions_by_timestamp AS
SELECT timestamp, user_guid, metric, amount, score
SELECT timestamp, user_guid, metric, amount, score
, score_decimal
FROM minds.contributions
WHERE user_guid IS NOT NULL AND timestamp IS NOT NULL AND metric IS NOT NULL AND amount IS NOT NULL
AND score IS NOT NULL
WHERE user_guid IS NOT NULL AND timestamp IS NOT NULL AND metric IS NOT NULL AND amount IS NOT NULL
PRIMARY KEY (timestamp, user_guid, metric)
WITH CLUSTERING ORDER BY (user_guid ASC, metric ASC)
AND bloom_filter_fp_chance = 0.01
...
...
Core/Rewards/Contributions/Contribution.php
View file @
3b80c207
...
...
@@ -3,7 +3,6 @@ namespace Minds\Core\Rewards\Contributions;
class
Contribution
{
protected
$metric
;
protected
$timestamp
;
protected
$amount
=
0
;
...
...
Core/Rewards/Contributions/Manager.php
View file @
3b80c207
...
...
@@ -102,7 +102,7 @@ class Manager
$this
->
repository
->
add
(
$contributions
);
return
$contributions
;
return
$contributions
;
}
/**
...
...
@@ -131,7 +131,7 @@ class Manager
/**
* Gather the entire site contribution score
*/
public
function
getSiteContributionScore
()
public
function
getSiteContributionScore
()
:
float
{
if
(
isset
(
$this
->
site_contribution_score_cache
[
$this
->
from
]))
{
return
$this
->
site_contribution_score_cache
[
$this
->
from
];
...
...
@@ -144,9 +144,9 @@ class Manager
/**
* Gather the contribution score for the user
* @return
in
t
* @return
floa
t
*/
public
function
getUserContributionScore
():
in
t
public
function
getUserContributionScore
():
floa
t
{
return
$this
->
sums
->
setTimestamp
(
$this
->
from
)
...
...
@@ -160,13 +160,6 @@ class Manager
*/
public
function
getRewardsAmount
():
string
{
//$share = BigNumber::_($this->getUserContributionScore(), 18)->div($this->getSiteContribtionScore());
//$pool = BigNumber::toPlain('100000000', 18)->div(15)->div(365);
//$velocity = 10;
//$pool = $pool->div($velocity);
$tokensPerScore
=
BigNumber
::
_
(
pi
())
->
mul
(
10
**
18
)
->
div
(
200
);
$tokens
=
BigNumber
::
_
(
$this
->
getUserContributionScore
())
->
mul
(
$tokensPerScore
);
return
(
string
)
$tokens
;
...
...
Core/Rewards/Contributions/Repository.php
View file @
3b80c207
...
...
@@ -4,6 +4,7 @@ namespace Minds\Core\Rewards\Contributions;
use
Cassandra
;
use
Cassandra\Varint
;
use
Cassandra\Timestamp
;
use
Cassandra\Decimal
;
use
Minds\Core\Data\Cassandra\Client
;
use
Minds\Core\Data\Cassandra\Prepared\Custom
;
use
Minds\Core\Di\Di
;
...
...
@@ -31,7 +32,8 @@ class Repository
user_guid,
metric,
amount,
score
score,
score_decimal
)
VALUES (?,?,?,?,?)"
;
foreach
(
$contributions
as
$contribution
)
{
...
...
@@ -42,7 +44,8 @@ class Repository
new
Varint
(
$contribution
->
getUser
()
->
guid
),
$contribution
->
getMetric
(),
new
Varint
(
$contribution
->
getAmount
()),
new
Varint
(
$contribution
->
getScore
())
null
,
new
Decimal
(
$contribution
->
getScore
())
]
];
}
...
...
@@ -114,7 +117,7 @@ class Repository
->
setMetric
((
string
)
$row
[
'metric'
])
->
setTimestamp
(
$row
[
'timestamp'
]
->
time
()
*
1000
)
->
setAmount
((
string
)
BigNumber
::
_
(
$row
[
'amount'
]))
->
setScore
((
int
)
$row
[
'score'
]);
->
setScore
((
float
)
$row
[
'score_decimal'
]
??
$row
[
'score'
]);
$contributions
[]
=
$contribution
;
}
...
...
Core/Rewards/Contributions/Sums.php
View file @
3b80c207
...
...
@@ -76,14 +76,14 @@ class Sums
$query
=
new
Custom
();
if
(
$this
->
user
)
{
$query
->
query
(
"SELECT SUM(score) as score from contributions WHERE user_guid = ?
$query
->
query
(
"SELECT SUM(score
_decimal
) as score from contributions WHERE user_guid = ?
AND timestamp = ?"
,
[
new
Varint
((
int
)
$this
->
user
->
guid
),
new
Timestamp
(
$this
->
timestamp
/
1000
)
]);
}
else
{
$query
->
query
(
"SELECT SUM(score) as score from contributions_by_timestamp WHERE timestamp = ?"
,
$query
->
query
(
"SELECT SUM(score
_decimal
) as score from contributions_by_timestamp WHERE timestamp = ?"
,
[
new
Timestamp
(
$this
->
timestamp
/
1000
)
]);
...
...
@@ -95,7 +95,6 @@ class Sums
error_log
(
$e
->
getMessage
());
}
return
(
in
t
)
$rows
[
0
][
'score'
];
return
(
floa
t
)
$rows
[
0
][
'score'
];
}
}
Spec/Core/Rewards/ManagerSpec.php
View file @
3b80c207
...
...
@@ -73,7 +73,7 @@ class ManagerSpec extends ObjectBehavior
->
setFrom
(
$from
)
->
setTo
(
$to
);
$this
->
sync
()
->
getAmount
()
->
shouldBe
(
20
);
$this
->
sync
()
->
getAmount
()
->
shouldBe
(
"
20
"
);
$this
->
sync
()
->
getContract
()
->
shouldBe
(
'offchain:reward'
);
$this
->
sync
()
->
getTimestamp
()
->
shouldBe
(
strtotime
(
'-1 second'
,
$to
/
1000
));
}
...
...