Skip to content

Commit

Permalink
Add config option to disable writing user totals
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Dec 18, 2023
1 parent 3d40335 commit 332bb49
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 53 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ MYSQL_USER_PP_TABLE_NAME
MYSQL_USER_METADATA_TABLE_NAME
WRITE_ALL_PP
WRITE_USER_TOTALS
POLL_INTERVAL_DIFFICULTIES
POLL_INTERVAL_SCORES
Expand Down
1 change: 1 addition & 0 deletions include/pp/performance/Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Processor
std::string UserMetadataTableName;

bool WriteAllPPChanges;
bool WriteUserTotals;

std::string SlackHookHost;
std::string SlackHookKey;
Expand Down
4 changes: 4 additions & 0 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ if [ ! -f config.json ]; then
TEMPLATE+='
"data-dog.port": (env.DATADOG_PORT // 8125) | tonumber,'
fi
if [[ -v WRITE_USER_TOTALS ]]; then
TEMPLATE+='
"write-user-totals": ((env.WRITE_USER_TOTALS | ascii_downcase) == "true" or env.WRITE_USER_TOTALS == "1"),'
fi

TEMPLATE+="}"
jq -n "$TEMPLATE" > config.json
Expand Down
110 changes: 57 additions & 53 deletions src/performance/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ void Processor::readConfig(const std::string& filename)
_config.UserMetadataTableName = j.value("mysql.user-metadata-table-name", "sample_users");

_config.WriteAllPPChanges = j.value("write-all-pp", true);
_config.WriteUserTotals = j.value("write-user-totals", true);

_config.DifficultyUpdateInterval = j.value("poll.interval.difficulties", 10000);
_config.ScoreUpdateInterval = j.value("poll.interval.scores", 50);
Expand Down Expand Up @@ -1001,68 +1002,71 @@ User Processor::processSingleUserGeneric(

_pDataDog->Increment("osu.pp.score.updated", scoresThatNeedDBUpdate.size(), {StrFormat("mode:{0}", GamemodeTag(_gamemode))}, 0.01f);

user.ComputePPRecord();
auto userPPRecord = user.GetPPRecord();

// Check for notable event
if (!scoresThatNeedDBUpdate.empty() && scoresThatNeedDBUpdate.front().Id() == selectedScoreId && // Did the score actually get found (this _should_ never be false, but better make sure)
scoresThatNeedDBUpdate.front().TotalValue() > userPPRecord.Value * s_notableEventRatingThreshold)
if (_config.WriteUserTotals)
{
_pDataDog->Increment("osu.pp.score.notable_events", 1, {StrFormat("mode:{0}", GamemodeTag(_gamemode))});

const auto& score = scoresThatNeedDBUpdate.front();
user.ComputePPRecord();
auto userPPRecord = user.GetPPRecord();

// Obtain user's previous pp rating for determining the difference
auto res = dbSlave.Query(StrFormat(
"SELECT `{0}` FROM `osu_user_stats{1}` WHERE `user_id`={2}",
_config.UserPPColumnName,
GamemodeSuffix(_gamemode),
userId
));

while (res.NextRow())
// Check for notable event
if (!scoresThatNeedDBUpdate.empty() && scoresThatNeedDBUpdate.front().Id() == selectedScoreId && // Did the score actually get found (this _should_ never be false, but better make sure)
scoresThatNeedDBUpdate.front().TotalValue() > userPPRecord.Value * s_notableEventRatingThreshold)
{
if (res.IsNull(0))
continue;

f64 ratingChange = userPPRecord.Value - (f64)res[0];

// We don't want to log scores, that give less than a mere 5 pp
if (ratingChange < s_notableEventRatingDifferenceMinimum)
continue;
_pDataDog->Increment("osu.pp.score.notable_events", 1, {StrFormat("mode:{0}", GamemodeTag(_gamemode))});

tlog::info() << StrFormat("Notable event: s{0} u{1} b{2}", score.Id(), userId, score.BeatmapId());
const auto& score = scoresThatNeedDBUpdate.front();

db.NonQueryBackground(StrFormat(
"INSERT INTO "
"osu_user_performance_change(user_id, mode, beatmap_id, performance_change, `rank`) "
"VALUES({0},{1},{2},{3},null)",
userId,
_gamemode,
score.BeatmapId(),
ratingChange
// Obtain user's previous pp rating for determining the difference
auto res = dbSlave.Query(StrFormat(
"SELECT `{0}` FROM `osu_user_stats{1}` WHERE `user_id`={2}",
_config.UserPPColumnName,
GamemodeSuffix(_gamemode),
userId
));

while (res.NextRow())
{
if (res.IsNull(0))
continue;

f64 ratingChange = userPPRecord.Value - (f64)res[0];

// We don't want to log scores, that give less than a mere 5 pp
if (ratingChange < s_notableEventRatingDifferenceMinimum)
continue;

tlog::info() << StrFormat("Notable event: s{0} u{1} b{2}", score.Id(), userId, score.BeatmapId());

db.NonQueryBackground(StrFormat(
"INSERT INTO "
"osu_user_performance_change(user_id, mode, beatmap_id, performance_change, `rank`) "
"VALUES({0},{1},{2},{3},null)",
userId,
_gamemode,
score.BeatmapId(),
ratingChange
));
}
}
}

newUsers.AppendAndCommit(StrFormat(
"UPDATE `osu_user_stats{0}` "
"SET `{1}`= CASE "
// Set pp to 0 if the user is inactive or restricted.
"WHEN (CURDATE() > DATE_ADD(`last_played`, INTERVAL 3 MONTH) OR (SELECT `user_warnings` FROM `{5}` WHERE `user_id`={4}) > 0) THEN 0 "
"ELSE {2} "
"END,"
"`accuracy_new`={3} "
"WHERE `user_id`={4} AND ABS(`{1}` - {2}) > 0.01;",
GamemodeSuffix(_gamemode),
_config.UserPPColumnName,
userPPRecord.Value,
userPPRecord.Accuracy,
userId,
_config.UserMetadataTableName
));
newUsers.AppendAndCommit(StrFormat(
"UPDATE `osu_user_stats{0}` "
"SET `{1}`= CASE "
// Set pp to 0 if the user is inactive or restricted.
"WHEN (CURDATE() > DATE_ADD(`last_played`, INTERVAL 3 MONTH) OR (SELECT `user_warnings` FROM `{5}` WHERE `user_id`={4}) > 0) THEN 0 "
"ELSE {2} "
"END,"
"`accuracy_new`={3} "
"WHERE `user_id`={4} AND ABS(`{1}` - {2}) > 0.01;",
GamemodeSuffix(_gamemode),
_config.UserPPColumnName,
userPPRecord.Value,
userPPRecord.Accuracy,
userId,
_config.UserMetadataTableName
));

_pDataDog->Increment("osu.pp.user.amount_processed", 1, {StrFormat("mode:{0}", GamemodeTag(_gamemode))}, 0.01f);
_pDataDog->Increment("osu.pp.user.amount_processed", 1, {StrFormat("mode:{0}", GamemodeTag(_gamemode))}, 0.01f);
}

return user;
}
Expand Down

0 comments on commit 332bb49

Please sign in to comment.