Skip to content

Commit

Permalink
Add ability to hide specific stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Sep 28, 2023
1 parent d9a6eb2 commit 3dbe9f5
Show file tree
Hide file tree
Showing 61 changed files with 152 additions and 116 deletions.
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace PokemonAutomation{
const bool IS_BETA_VERSION = true;
const int PROGRAM_VERSION_MAJOR = 0;
const int PROGRAM_VERSION_MINOR = 41;
const int PROGRAM_VERSION_PATCH = 4;
const int PROGRAM_VERSION_PATCH = 6;

const std::string PROGRAM_VERSION_BASE =
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ std::pair<std::string, std::string> make_session_field(
}
if (current_stats){
text += "\n";
text += current_stats->to_str();
text += current_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN);
if (!current_stats_addendum.empty()){
text += "\n";
text += current_stats_addendum;
Expand Down Expand Up @@ -274,7 +274,10 @@ void send_program_notification_with_file(
#endif
const StatsTracker* historical_stats = env.historical_stats();
if (GlobalSettings::instance().ALL_STATS && historical_stats){
messages.emplace_back("Historical Stats:", env.historical_stats()->to_str());
messages.emplace_back(
"Historical Stats:",
env.historical_stats()->to_str(StatsTracker::DISPLAY_ON_SCREEN)
);
}
send_raw_notification(
env.logger(),
Expand Down Expand Up @@ -318,7 +321,10 @@ void send_program_notification(
#endif
const StatsTracker* historical_stats = env.historical_stats();
if (GlobalSettings::instance().ALL_STATS && historical_stats){
messages.emplace_back("Historical Stats:", env.historical_stats()->to_str());
messages.emplace_back(
"Historical Stats:",
env.historical_stats()->to_str(StatsTracker::DISPLAY_ON_SCREEN)
);
}
send_raw_notification(
env.logger(),
Expand Down
4 changes: 2 additions & 2 deletions SerialPrograms/Source/CommonFramework/ProgramSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ const std::string& ProgramSession::identifier() const{
std::string ProgramSession::current_stats() const{
std::lock_guard<std::mutex> lg(m_lock);
if (m_current_stats){
return m_current_stats->to_str();
return m_current_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN);
}
return "";
}
std::string ProgramSession::historical_stats() const{
std::lock_guard<std::mutex> lg(m_lock);
if (m_historical_stats){
return m_historical_stats->to_str();
return m_historical_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN);
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void ProgramEnvironment::update_stats(){


std::string ProgramEnvironment::historical_stats_str() const{
return m_historical_stats ? m_historical_stats->to_str() : "";
return m_historical_stats ? m_historical_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN) : "";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const std::map<std::string, std::string> STATS_DATABASE_ALIASES{

StatLine::StatLine(StatsTracker& tracker)
: m_time(current_time_to_str())
, m_stats(tracker.to_str())
, m_stats(tracker.to_str(StatsTracker::SAVE_TO_STATS_FILE))
{}
StatLine::StatLine(const std::string& line){
size_t pos = line.find(" - ");
Expand Down
34 changes: 27 additions & 7 deletions SerialPrograms/Source/CommonFramework/Tools/StatsTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace PokemonAutomation{



StatsTracker::Stat::Stat(std::string&& p_label, bool p_omit_if_zero)
StatsTracker::Stat::Stat(std::string&& p_label, DisplayMode p_display_node)
: label(p_label)
, omit_if_zero(p_omit_if_zero)
, display_mode(p_display_node)
{}
std::string StatsTracker::to_str() const{
std::string StatsTracker::to_str(PrintMode mode) const{
std::map<std::string, uint64_t> stats;
for (const auto& item : m_stats){
auto alias = m_aliases.find(item.first);
Expand All @@ -41,9 +41,29 @@ std::string StatsTracker::to_str() const{
if (iter != stats.end()){
count += iter->second;
}
if (stat.omit_if_zero && count == 0){
continue;

switch (stat.display_mode){
case ALWAYS_VISIBLE:
break;
case HIDDEN_IF_ZERO:
if (count == 0){
continue;
}else{
break;
}
case ALWAYS_HIDDEN:
switch (mode){
case DISPLAY_ON_SCREEN:
continue;
case SAVE_TO_STATS_FILE:
if (count == 0){
continue;
}else{
break;
}
}
}

if (!str.empty()){
str += " - ";
}
Expand Down Expand Up @@ -115,12 +135,12 @@ std::string stats_to_bar(
if (!override_current.empty()){
current_str = override_current;
}else if (current){
current_str = current->to_str();
current_str = current->to_str(StatsTracker::DISPLAY_ON_SCREEN);
}

std::string historical_str;
if (historical){
historical_str = historical->to_str();
historical_str = historical->to_str(StatsTracker::DISPLAY_ON_SCREEN);
}

if (current_str.empty() && historical_str.empty()){
Expand Down
20 changes: 15 additions & 5 deletions SerialPrograms/Source/CommonFramework/Tools/StatsTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,28 @@ class StatsTracker{
StatsTracker() = default;
virtual ~StatsTracker() = default;

virtual std::string to_str() const;
enum PrintMode{
DISPLAY_ON_SCREEN,
SAVE_TO_STATS_FILE,
};
virtual std::string to_str(PrintMode mode) const;

void parse_and_append_line(const std::string& line);


protected:
static constexpr bool HIDDEN_IF_ZERO = true;
static constexpr bool ALWAYS_VISIBLE = false;
// static constexpr bool HIDDEN_IF_ZERO = true;
// static constexpr bool ALWAYS_VISIBLE = false;
enum DisplayMode{
ALWAYS_VISIBLE,
HIDDEN_IF_ZERO,
ALWAYS_HIDDEN,
};

struct Stat{
std::string label;
bool omit_if_zero;
Stat(std::string&& p_label, bool p_omit_if_zero = ALWAYS_VISIBLE);
DisplayMode display_mode;
Stat(std::string&& p_label, DisplayMode p_display_node = ALWAYS_VISIBLE);
};

std::vector<Stat> m_display_order;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void ComputerProgramWidget::state_change(ProgramState state){
void ComputerProgramWidget::stats_update(const StatsTracker* current_stats, const StatsTracker* historical_stats){
QMetaObject::invokeMethod(this, [this, current_stats, historical_stats]{
m_stats_bar->set_stats(
current_stats == nullptr ? "" : current_stats->to_str(),
historical_stats == nullptr ? "" : historical_stats->to_str()
current_stats == nullptr ? "" : current_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN),
historical_stats == nullptr ? "" : historical_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN)
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ void MultiSwitchProgramWidget2::state_change(ProgramState state){
void MultiSwitchProgramWidget2::stats_update(const StatsTracker* current_stats, const StatsTracker* historical_stats){
QMetaObject::invokeMethod(this, [this, current_stats, historical_stats]{
m_stats_bar->set_stats(
current_stats == nullptr ? "" : current_stats->to_str(),
historical_stats == nullptr ? "" : historical_stats->to_str()
current_stats == nullptr ? "" : current_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN),
historical_stats == nullptr ? "" : historical_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN)
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ void SingleSwitchProgramWidget2::state_change(ProgramState state){
void SingleSwitchProgramWidget2::stats_update(const StatsTracker* current_stats, const StatsTracker* historical_stats){
QMetaObject::invokeMethod(this, [this, current_stats, historical_stats]{
m_stats_bar->set_stats(
current_stats == nullptr ? "" : current_stats->to_str(),
historical_stats == nullptr ? "" : historical_stats->to_str()
current_stats == nullptr ? "" : current_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN),
historical_stats == nullptr ? "" : historical_stats->to_str(StatsTracker::DISPLAY_ON_SCREEN)
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ EggAutonomousStats::EggAutonomousStats()
, m_shinies(m_stats["Shinies"])
{
m_display_order.emplace_back("Eggs Hatched");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Fetch Attempts");
m_display_order.emplace_back("Fetch Success");
m_display_order.emplace_back("Shinies");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct MoneyFarmerRoute210_Descriptor::Stats : public StatsTracker{
, m_react(m_stats["React"])
{
m_display_order.emplace_back("Searches");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("No React");
m_display_order.emplace_back("React");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct MoneyFarmerRoute212_Descriptor::Stats : public StatsTracker{
, m_both(m_stats["Both"])
{
m_display_order.emplace_back("Searches");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("No React");
m_display_order.emplace_back("Man Only");
m_display_order.emplace_back("Woman Only");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct CloneItemsBoxCopy2_Descriptor::Stats : public StatsTracker{
// , m_resets(m_stats["Resets"])
{
m_display_order.emplace_back("Boxes Cloned");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
// m_display_order.emplace_back("Resets");
}
std::atomic<uint64_t>& m_boxes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct StarterReset_Descriptor::Stats : public PokemonSwSh::ShinyHuntTracker{
: ShinyHuntTracker(false)
, m_shiny_starly(m_stats["Shiny Starly"])
{
m_display_order.emplace_back("Shiny Starly", true);
m_display_order.emplace_back("Shiny Starly", HIDDEN_IF_ZERO);
}
std::atomic<uint64_t>& m_shiny_starly;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TradeStats::TradeStats()
, m_errors(m_stats["Errors"])
{
m_display_order.emplace_back("Trades");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class IngoBattleGrinder_Descriptor::Stats : public StatsTracker{
m_display_order.emplace_back("Battles");
m_display_order.emplace_back("Turns");
m_display_order.emplace_back("Lead Move Attempts");
m_display_order.emplace_back("Faint Switches", true);
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Faint Switches", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
}

std::atomic<uint64_t>& battles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class IngoMoveGrinder_Descriptor::Stats : public StatsTracker{
m_display_order.emplace_back("Battles");
m_display_order.emplace_back("Turns");
m_display_order.emplace_back("Move Attempts");
m_display_order.emplace_back("Faint Switches", true);
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Faint Switches", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
}

std::atomic<uint64_t>& battles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LeapGrinder_Descriptor::Stats : public StatsTracker{
, leap_shinies(m_stats["Leap Shinies"])
{
m_display_order.emplace_back("Attempts");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Leaps");
m_display_order.emplace_back("Found");
m_display_order.emplace_back("Enroute Shinies");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MagikarpMoveGrinder_Descriptor::Stats : public StatsTracker{
{
m_display_order.emplace_back("Magikarp");
m_display_order.emplace_back("Move Attempts");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
}

std::atomic<uint64_t>& magikarp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class NuggetFarmerHighlands_Descriptor::Stats : public StatsTracker, public Shin
, shinies(m_stats["Shinies"])
{
m_display_order.emplace_back("Attempts");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Charm", true);
m_display_order.emplace_back("Coin", true);
m_display_order.emplace_back("Shinies", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Charm", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Coin", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Shinies", HIDDEN_IF_ZERO);
}
virtual void add_shiny() override{
shinies++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class TenacityCandyFarmer_Descriptor::Stats : public StatsTracker{
, errors(m_stats["Errors"])
{
m_display_order.emplace_back("Battles");
m_display_order.emplace_back("Faint Switches", true);
m_display_order.emplace_back("Fourth Moves", true);
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Faint Switches", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Fourth Moves", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
}

std::atomic<uint64_t>& battles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class DistortionWaiter_Descriptor::Stats : public StatsTracker{
{
m_display_order.emplace_back("Minutes Waited");
m_display_order.emplace_back("Distortions");
m_display_order.emplace_back("Other Notifications", true);
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Other Notifications", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
}

std::atomic<uint64_t>& minutes_waited;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ class OutbreakFinder_Descriptor::Stats : public StatsTracker{
, matches(m_stats["Matches"])
{
m_display_order.emplace_back("Checks");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Outbreaks");
m_display_order.emplace_back("MMOs");
m_display_order.emplace_back("MMO Pokemon");
m_display_order.emplace_back("Stars");
m_display_order.emplace_back("Matches", true);
m_display_order.emplace_back("Matches", HIDDEN_IF_ZERO);
}

std::atomic<uint64_t>& checks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class RamanasCombeeFinder_Descriptor::Stats : public StatsTracker{
{
m_display_order.emplace_back("Attempts");
m_display_order.emplace_back("Trees");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Blackouts", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Blackouts", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Found");
m_display_order.emplace_back("Enroute Shinies");
m_aliases["Shinies"] = "Enroute Shinies";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class BurmyFinder_Descriptor::Stats : public StatsTracker{
{
m_display_order.emplace_back("Attempts");
m_display_order.emplace_back("Trees");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Blackouts", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Blackouts", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Found");
m_display_order.emplace_back("Enroute Shinies");
m_display_order.emplace_back("Tree Alphas");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class CrobatFinder_Descriptor::Stats : public StatsTracker, public ShinyStatIncr
, shinies(m_stats["Shinies"])
{
m_display_order.emplace_back("Attempts");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Shinies", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Shinies", HIDDEN_IF_ZERO);
}
virtual void add_shiny() override{
shinies++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class FroslassFinder_Descriptor::Stats : public StatsTracker, public ShinyStatIn
, shinies(m_stats["Shinies"])
{
m_display_order.emplace_back("Attempts");
m_display_order.emplace_back("Errors", true);
m_display_order.emplace_back("Shinies", true);
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
m_display_order.emplace_back("Shinies", HIDDEN_IF_ZERO);
}
virtual void add_shiny() override{
shinies++;
Expand Down
Loading

0 comments on commit 3dbe9f5

Please sign in to comment.