-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes AC for 1min setting #1507
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,20 +41,22 @@ BatPublishers::BatPublishers(bat_ledger::LedgerImpl* ledger): | |
BatPublishers::~BatPublishers() { | ||
} | ||
|
||
void BatPublishers::calcScoreConsts(const uint64_t& min_duration) { | ||
uint64_t min_duration_ms = min_duration * | ||
braveledger_ledger::_milliseconds_second; | ||
a_ = (1.0 / (braveledger_ledger::_d * 2.0)) - min_duration_ms; | ||
void BatPublishers::calcScoreConsts(const uint64_t& min_duration_seconds) { | ||
// we increase duration for 100 to keep it as close to muon implementation | ||
// as possible (we used 1000 in muon) | ||
// keeping it with only seconds visits are not spaced out equally | ||
uint64_t min_duration_big = min_duration_seconds * 100; | ||
a_ = (1.0 / (braveledger_ledger::_d * 2.0)) - min_duration_big; | ||
a2_ = a_ * 2.0; | ||
a4_ = a2_ * 2.0; | ||
b_ = min_duration_ms - a_; | ||
b_ = min_duration_big - a_; | ||
b2_ = b_ * b_; | ||
} | ||
|
||
// courtesy of @dimitry-xyz: https://github.com/brave/ledger/issues/2#issuecomment-221752002 | ||
double BatPublishers::concaveScore(const uint64_t& duration) { | ||
uint64_t duration_ms = duration * braveledger_ledger::_milliseconds_second; | ||
return (-b_ + std::sqrt(b2_ + (a4_ * duration_ms))) / a2_; | ||
double BatPublishers::concaveScore(const uint64_t& duration_seconds) { | ||
uint64_t duration_big = duration_seconds * 100; | ||
return (-b_ + std::sqrt(b2_ + (a4_ * duration_big))) / a2_; | ||
} | ||
|
||
std::string getProviderName(const std::string& publisher_id) { | ||
|
@@ -431,6 +433,7 @@ void BatPublishers::OnRestorePublishersInternal(bool success) { | |
|
||
void BatPublishers::setPublisherMinVisitTime(const uint64_t& duration) { // In seconds | ||
state_->min_publisher_duration_ = duration; | ||
calcScoreConsts(duration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to update variables on the fly and not only when we restart the browser There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should really move these things to an observer for PublisherMinVisitTime change in a follow-up somewhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so ledger would save data and call rewards that save was successful and we would trigger observer that would then call back ledger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, an observer internal to ledger |
||
SynopsisNormalizer(); | ||
saveState(); | ||
} | ||
|
@@ -488,11 +491,11 @@ bool BatPublishers::getPublisherAllowVideos() const { | |
} | ||
|
||
bool BatPublishers::GetMigrateScore() const { | ||
return state_->migrate_score; | ||
return state_->migrate_score_2; | ||
} | ||
|
||
void BatPublishers::SetMigrateScore(bool value) { | ||
state_->migrate_score = value; | ||
state_->migrate_score_2 = value; | ||
saveState(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "bat/ledger/ledger.h" | ||
#include "bat_publishers.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
// npm run test -- brave_unit_tests --filter=BatPublishersTest.* | ||
|
||
namespace braveledger_bat_publishers { | ||
|
||
class BatPublishersTest : public testing::Test { | ||
}; | ||
|
||
TEST_F(BatPublishersTest, calcScoreConsts) { | ||
braveledger_bat_publishers::BatPublishers* publishers = | ||
new braveledger_bat_publishers::BatPublishers(nullptr); | ||
|
||
/* | ||
* Test 5 seconds | ||
*/ | ||
publishers->calcScoreConsts(5); | ||
|
||
EXPECT_EQ(publishers->a_, 14500); | ||
EXPECT_EQ(publishers->a2_, 29000); | ||
EXPECT_EQ(publishers->a4_, 58000); | ||
EXPECT_EQ(publishers->b_, -14000); | ||
EXPECT_EQ(publishers->b2_, 196000000); | ||
|
||
/* | ||
* Test 8 seconds | ||
*/ | ||
publishers->calcScoreConsts(8); | ||
|
||
EXPECT_EQ(publishers->a_, 14200); | ||
EXPECT_EQ(publishers->a2_, 28400); | ||
EXPECT_EQ(publishers->a4_, 56800); | ||
EXPECT_EQ(publishers->b_, -13400); | ||
EXPECT_EQ(publishers->b2_, 179560000); | ||
|
||
/* | ||
* Test 1min (60 seconds) | ||
*/ | ||
publishers->calcScoreConsts(60); | ||
|
||
EXPECT_EQ(publishers->a_, 9000); | ||
EXPECT_EQ(publishers->a2_, 18000); | ||
EXPECT_EQ(publishers->a4_, 36000); | ||
EXPECT_EQ(publishers->b_, -3000); | ||
EXPECT_EQ(publishers->b2_, 9000000); | ||
} | ||
|
||
TEST_F(BatPublishersTest, concaveScore) { | ||
braveledger_bat_publishers::BatPublishers* publishers = | ||
new braveledger_bat_publishers::BatPublishers(nullptr); | ||
|
||
/* | ||
* min duration: 5 seconds | ||
* duration: 5, 15, 60, 1000, 10000, 150000, 500000 | ||
*/ | ||
publishers->calcScoreConsts(5); | ||
EXPECT_NEAR(publishers->concaveScore(5), 1, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(15), 1.06285, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(60), 1.28703, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(1000), 3.15289, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(10000), 8.80133, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(150000), 32.6498, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(500000), 59.2068, 0.001f); | ||
|
||
/* | ||
* min duration: 8 seconds | ||
* duration: 5, 15, 60, 1000, 10000, 150000, 500000 | ||
*/ | ||
publishers->calcScoreConsts(8); | ||
EXPECT_NEAR(publishers->concaveScore(5), 0.979606, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(15), 1.04477, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(60), 1.27505, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(1000), 3.16717, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(10000), 8.8769, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(150000), 32.9766, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(500000), 59.8128, 0.001f); | ||
|
||
/* | ||
* min duration: 60 seconds | ||
* duration: 5, 15, 60, 1000, 10000, 150000, 500000 | ||
*/ | ||
publishers->calcScoreConsts(60); | ||
EXPECT_NEAR(publishers->concaveScore(5), 0.455342, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(15), 0.607625, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(60), 1, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(1000), 3.50416, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(10000), 10.7089, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(150000), 40.9918, 0.001f); | ||
EXPECT_NEAR(publishers->concaveScore(500000), 74.7025, 0.001f); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
score_2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we migrated once already and we just need to migrate it again, so that's why I rename it to 2 as 1 is not needed anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why does it need to be score_2 in the data structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so that we migrate only once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the name has changed now, but I think what we need here is a
version
attribute for the data