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
191
Issues
191
List
Boards
Labels
Service Desk
Milestones
Merge Requests
32
Merge Requests
32
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
1808489730f9e15f448d8f0897a8dc47fcf6c11f...3b80c207b9f96e24b20beaa9cde0907a5ff8a904
Source
3b80c207b9f96e24b20beaa9cde0907a5ff8a904
Select Git revision
...
Target
1808489730f9e15f448d8f0897a8dc47fcf6c11f
Select Git revision
Compare
Commits (3)
(fix) Fix expected value in Rewards Manager Spec test
· 00beca90
Guy Thouret
authored
1 day ago
00beca90
(chore) Add missing command help and dry run option to contributions cli -
#587
· 9c166d03
Guy Thouret
authored
1 hour ago
9c166d03
(feat) Add decimal score value to contributions table -
#587
· 3b80c207
Guy Thouret
authored
1 hour ago
3b80c207
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
33 deletions
+41
-33
Contributions.php
Controllers/Cli/Contributions.php
+24
-11
cassandra-provision.cql
Core/Provisioner/Provisioners/cassandra-provision.cql
+3
-2
Contribution.php
Core/Rewards/Contributions/Contribution.php
+0
-1
Manager.php
Core/Rewards/Contributions/Manager.php
+4
-11
Repository.php
Core/Rewards/Contributions/Repository.php
+6
-3
Sums.php
Core/Rewards/Contributions/Sums.php
+3
-4
ManagerSpec.php
Spec/Core/Rewards/ManagerSpec.php
+1
-1
No files found.
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
)
{
...
...
This diff is collapsed.
Click to expand it.
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
...
...
This diff is collapsed.
Click to expand it.
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
;
...
...
This diff is collapsed.
Click to expand it.
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
;
...
...
This diff is collapsed.
Click to expand it.
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
;
}
...
...
This diff is collapsed.
Click to expand it.
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'
];
}
}
This diff is collapsed.
Click to expand it.
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
));
}
...
...
This diff is collapsed.
Click to expand it.