Skip to content

Commit

Permalink
Merge pull request #58 from Tom94/general-improvements
Browse files Browse the repository at this point in the history
General improvements
  • Loading branch information
Tom94 committed May 31, 2018
2 parents fcc4ac5 + 0a5c801 commit 92b3eaf
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 56 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ After compilation, an executable named `osu-performance` is placed in the _Bin_

where command controls which scores are the target of the computation.
The following commands are valid:
* `new`: Continually poll for new scores and compute pp of these
* `all`: Compute pp of all users
* `new`: Continually poll for new scores and compute pp of these
* `scores`: Compute pp of specific scores
* `users`: Compute pp of specific users

The gamemode to compute pp for can be selected via the `-m` option, which may take the value `osu`, `taiko`, `catch`, or `mania`.
Expand Down
8 changes: 8 additions & 0 deletions include/pp/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Exception

// std::string operations
std::vector<std::string> Split(std::string text, const std::string& delim);
std::string Join(const std::vector<std::string>& words, const std::string& delim);
std::string ToLower(std::string str);
std::string ToUpper(std::string str);

Expand Down Expand Up @@ -94,6 +95,13 @@ enum EMods : u32
ScoreIncreaseMods = Hidden | HardRock | DoubleTime | Flashlight | FadeIn
};

inline EMods MaskRelevantDifficultyMods(EMods mods)
{
return static_cast<EMods>(mods & (DoubleTime | HalfTime | HardRock | Easy | keyMod));
}

std::string ToString(EMods mods);

enum class EGamemode
{
Osu,
Expand Down
9 changes: 0 additions & 9 deletions include/pp/performance/Beatmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ class Beatmap
}

private:
static const EMods s_relevantDifficultyMods = static_cast<EMods>(
DoubleTime | HalfTime | HardRock | Easy | keyMod
);

static EMods maskRelevantDifficultyMods(EMods mods)
{
return static_cast<EMods>(mods & s_relevantDifficultyMods);
}

static const std::unordered_map<std::string, EDifficultyAttributeType> s_difficultyAttributes;

// General information
Expand Down
4 changes: 4 additions & 0 deletions include/pp/performance/Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Processor
void ProcessAllUsers(bool reProcess, u32 numThreads);
void ProcessUsers(const std::vector<std::string>& userNames);
void ProcessUsers(const std::vector<s64>& userIds);
void ProcessScores(const std::vector<s64>& scoreIds);

private:
static const Beatmap::ERankedStatus s_minRankedStatus;
Expand Down Expand Up @@ -133,6 +134,9 @@ class Processor
void storeCount(DatabaseConnection& db, std::string key, s64 value);
s64 retrieveCount(DatabaseConnection& db, std::string key);

std::string retrieveUserName(s64 userId, DatabaseConnection& db) const;
std::string retrieveBeatmapName(s32 beatmapId, DatabaseConnection& db) const;

EGamemode _gamemode;

RWMutex _beatmapMutex;
Expand Down
2 changes: 2 additions & 0 deletions include/pp/performance/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class User

size_t NumScores() const { return _scores.size(); }

const std::vector<Score::PPRecord>& Scores() const { return _scores; }

void ComputePPRecord();

const PPRecord& GetPPRecord() const { return _rating; }
Expand Down
79 changes: 76 additions & 3 deletions src/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

PP_NAMESPACE_BEGIN

std::vector<std::string> Split(std::string text, const std::string& delim) {
std::vector<std::string> Split(std::string text, const std::string& delim)
{
std::vector<std::string> result;
while (true) {
size_t begin = text.find_last_of(delim);
Expand All @@ -21,16 +22,88 @@ std::vector<std::string> Split(std::string text, const std::string& delim) {
return result;
}

std::string ToLower(std::string str) {
std::string Join(const std::vector<std::string>& words, const std::string& delim)
{
std::string result;
for (size_t i = 0; i < words.size(); ++i)
{
result += words[i];
if (i < words.size() - 1)
result += delim;
}
return result;
}

std::string ToLower(std::string str)
{
transform(begin(str), end(str), begin(str), [](unsigned char c) { return (char)tolower(c); });
return str;
}

std::string ToUpper(std::string str) {
std::string ToUpper(std::string str)
{
transform(begin(str), end(str), begin(str), [](unsigned char c) { return (char)toupper(c); });
return str;
}

std::string ToString(EMods mods)
{
std::string result = "";

std::vector<std::string> modStrings;

// Keymods
if (mods & Key1)
modStrings.emplace_back("K1");
if (mods & Key2)
modStrings.emplace_back("K2");
if (mods & Key3)
modStrings.emplace_back("K3");
if (mods & Key4)
modStrings.emplace_back("K4");
if (mods & Key5)
modStrings.emplace_back("K5");
if (mods & Key6)
modStrings.emplace_back("K6");
if (mods & Key7)
modStrings.emplace_back("K7");
if (mods & Key8)
modStrings.emplace_back("K8");
if (mods & Key9)
modStrings.emplace_back("K9");
if (mods & Key10)
modStrings.emplace_back("K10");

// Cheap out
if (mods & NoFail)
modStrings.emplace_back("NF");
if (mods & SpunOut)
modStrings.emplace_back("SO");

// Visiblity
if (mods & Hidden)
modStrings.emplace_back("HD");
if (mods & Flashlight)
modStrings.emplace_back("FL");

// Speed
if (mods & DoubleTime)
modStrings.emplace_back("DT");
if (mods & HalfTime)
modStrings.emplace_back("HT");

// Difficulty
if (mods & HardRock)
modStrings.emplace_back("HR");
if (mods & Easy)
modStrings.emplace_back("EZ");

if (modStrings.empty())
return "None";

return Join(modStrings, ",");
}

std::string GamemodeSuffix(EGamemode gamemode)
{
switch (gamemode)
Expand Down
4 changes: 2 additions & 2 deletions src/performance/Beatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Beatmap::Beatmap(s32 id)

f32 Beatmap::DifficultyAttribute(EMods mods, EDifficultyAttributeType type) const
{
auto difficultyIt = _difficulty.find(maskRelevantDifficultyMods(mods));
auto difficultyIt = _difficulty.find(MaskRelevantDifficultyMods(mods));
return difficultyIt == std::end(_difficulty) ? 0.0f : difficultyIt->second[type];
}

void Beatmap::SetDifficultyAttribute(EMods mods, EDifficultyAttributeType type, f32 value)
{
_difficulty[maskRelevantDifficultyMods(mods)][type] = value;
_difficulty[MaskRelevantDifficultyMods(mods)][type] = value;
}

PP_NAMESPACE_END
Loading

0 comments on commit 92b3eaf

Please sign in to comment.