Skip to content

Commit

Permalink
Adds migration for old users
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Feb 13, 2019
1 parent c83662f commit 20ff2b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
12 changes: 6 additions & 6 deletions vendor/bat-native-ledger/src/bat_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ static bool ignore_ = false;
allow_videos_ = state.allow_videos_;
monthly_balances_ = state.monthly_balances_;
recurring_donation_ = state.recurring_donation_;
migrate_score = state.migrate_score;
migrate_score_2 = state.migrate_score_2;
}

PUBLISHER_STATE_ST::~PUBLISHER_STATE_ST() {}
Expand Down Expand Up @@ -670,10 +670,10 @@ static bool ignore_ = false;
}
}

if (d.HasMember("migrate_score") && d["migrate_score"].IsBool()) {
migrate_score = d["migrate_score"].GetBool();
if (d.HasMember("migrate_score_2") && d["migrate_score_2"].IsBool()) {
migrate_score_2 = d["migrate_score_2"].GetBool();
} else {
migrate_score = true;
migrate_score_2 = true;
}
}

Expand Down Expand Up @@ -722,8 +722,8 @@ static bool ignore_ = false;

writer.EndArray();

writer.String("migrate_score");
writer.Bool(data.migrate_score);
writer.String("migrate_score_2");
writer.Bool(data.migrate_score_2);

writer.EndObject();
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/bat-native-ledger/src/bat_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace braveledger_bat_helper {
bool allow_videos_ = true;
std::map<std::string, REPORT_BALANCE_ST> monthly_balances_;
std::map<std::string, double> recurring_donation_;
bool migrate_score = false;
bool migrate_score_2 = false;
};

struct PUBLISHER_ST {
Expand Down
15 changes: 9 additions & 6 deletions vendor/bat-native-ledger/src/bat_publishers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ BatPublishers::BatPublishers(bat_ledger::LedgerImpl* ledger):
BatPublishers::~BatPublishers() {
}

void BatPublishers::calcScoreConsts(const uint64_t& min_duration) {
uint64_t min_duration_big = min_duration * 100;
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;
Expand All @@ -51,8 +54,8 @@ void BatPublishers::calcScoreConsts(const uint64_t& min_duration) {
}

// courtesy of @dimitry-xyz: https://github.com/brave/ledger/issues/2#issuecomment-221752002
double BatPublishers::concaveScore(const uint64_t& duration) {
uint64_t duration_big = duration * 100;
double BatPublishers::concaveScore(const uint64_t& duration_seconds) {
uint64_t duration_big = duration_seconds * 100;
return (-b_ + std::sqrt(b2_ + (a4_ * duration_big))) / a2_;
}

Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions vendor/bat-native-ledger/src/bat_publishers.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class BatPublishers : public ledger::LedgerCallbackHandler {

void OnRestorePublishersInternal(bool success);

void calcScoreConsts(const uint64_t& duration);
void calcScoreConsts(const uint64_t& min_duration_seconds);

double concaveScore(const uint64_t& duration);
double concaveScore(const uint64_t& duration_seconds);

void saveState();

Expand Down

0 comments on commit 20ff2b5

Please sign in to comment.