Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Common/Qt/QtThreadPool_Tests.h"
#include "Kernels/Kernels_Tests.h"
#include "Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h"
#include "Pokemon/AutoStory/Pokemon_AutoStoryStats_Tests.h"
#include "CommonFramework/AudioPipeline/AudioInfo_Tests.h"
#include "CommonFramework/AudioPipeline/Tools/ChannelMixer.h"
#include "CommonFramework/AudioPipeline/SinkPipeline_Tests.h"
Expand Down Expand Up @@ -54,7 +55,7 @@



UnitTestDatabase make_UNIT_TESTS_ALL(){

Check warning on line 58 in SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::ComputerPrograms::make_UNIT_TESTS_ALL(): function_lines=39 (advisory above 25, limit 50)
UnitTestDatabase ret;

add_tests_QtEventThreadPool(ret, GlobalThreadPools::computation_normal());
Expand All @@ -76,6 +77,7 @@
OCR::add_tests(ret);
Kernels::add_tests(ret);
Pokemon::add_tests_AutoStorySelect(ret);
Pokemon::add_tests_AutoStoryStats(ret);
NintendoSwitch::add_tests_CheckOnlineDetector(ret);
NintendoSwitch::add_tests_FailedToConnectDetector(ret);
NintendoSwitch::add_tests_UpdatePopupDetector(ret);
Expand Down
46 changes: 46 additions & 0 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* AutoStory Stats
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_AutoStoryStats_H
#define PokemonAutomation_Pokemon_AutoStoryStats_H

#include <atomic>
#include <cstdint>
#include "CommonFramework/ProgramStats/StatsTracking.h"

namespace PokemonAutomation{
namespace Pokemon{


// Stats shared by the AutoStory programs of every game.
struct AutoStoryStats : public StatsTracker{
AutoStoryStats()
: m_runs(m_stats["Runs"])
, m_segments_started(m_stats["Segments Started"])
, m_checkpoints_started(m_stats["Checkpoints Started"])
, m_resets(m_stats["Resets"])
{
m_display_order.emplace_back("Runs");
m_display_order.emplace_back("Segments Started");
m_display_order.emplace_back("Checkpoints Started");
m_display_order.emplace_back("Resets");

// Labels used before the rename: saved totals carry over.
m_aliases["Segment"] = "Segments Started";
m_aliases["Checkpoint"] = "Checkpoints Started";
m_aliases["Reset"] = "Resets";
}
std::atomic<uint64_t>& m_runs;
std::atomic<uint64_t>& m_segments_started;
std::atomic<uint64_t>& m_checkpoints_started;
std::atomic<uint64_t>& m_resets;
};



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* AutoStory Stats Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <string>
#include <utility>
#include <vector>
#include "Pokemon_AutoStoryStats.h"
#include "Pokemon_AutoStoryStats_Tests.h"

namespace PokemonAutomation{
namespace Pokemon{

namespace{

// A stats file line, as loaded from disk.
struct AutoStoryStatsInput{
std::string saved_line;
};

// The stats line written back after loading it.
struct AutoStoryStatsExpectation{
std::string line;
};

struct AutoStoryStatsScenario{
std::string name;
AutoStoryStatsInput input;
AutoStoryStatsExpectation expectation;
};

class Test_AutoStoryStatsLoad : public UnitTest{
public:
Test_AutoStoryStatsLoad(AutoStoryStatsScenario scenario)
: UnitTest(std::format("Pokemon::AutoStoryStats - {}", scenario.name))
, m_scenario(std::move(scenario))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
AutoStoryStats stats;
stats.parse_and_append_line(m_scenario.input.saved_line);
const std::string got = stats.to_str(StatsTracker::SAVE_TO_STATS_FILE);
if (got != m_scenario.expectation.line){
return std::format("Expected \"{}\", got \"{}\"", m_scenario.expectation.line, got);
}
return true;
}

private:
const AutoStoryStatsScenario m_scenario;
};

} // namespace



void add_tests_AutoStoryStats(UnitTestDatabase& database){
const std::vector<AutoStoryStatsScenario> load_cases{
{
.name = "old labels fill the new ones",
.input = {.saved_line = "Checkpoint: 12 - Segment: 3 - Reset: 1"},
.expectation = {.line = "Runs: 0 - Segments Started: 3 - Checkpoints Started: 12 - Resets: 1"},
},
{
.name = "new labels load as they are",
.input = {.saved_line = "Runs: 4 - Segments Started: 3 - Checkpoints Started: 1,234 - Resets: 2"},
.expectation = {.line = "Runs: 4 - Segments Started: 3 - Checkpoints Started: 1,234 - Resets: 2"},
},
{
.name = "old and new labels add up",
.input = {.saved_line = "Checkpoint: 10 - Checkpoints Started: 5 - Runs: 1"},
.expectation = {.line = "Runs: 1 - Segments Started: 0 - Checkpoints Started: 15 - Resets: 0"},
},
};
for (const AutoStoryStatsScenario& scenario : load_cases){
database.add<Test_AutoStoryStatsLoad>(scenario);
}
}



} // namespace Pokemon
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* AutoStory Stats Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_AutoStoryStats_Tests_H
#define PokemonAutomation_Pokemon_AutoStoryStats_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace Pokemon{


// Registers the tests that load saved AutoStory stats lines.
void add_tests_AutoStoryStats(UnitTestDatabase& database);



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,6 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex
StartProgramChecks::check_performance_class_wired_or_wireless(context);
assert_16_9_720p_min(env.logger(), env.console);


// test code
if (TEST_FLYPOINT_LOCATIONS || TEST_MOVE_CURSOR_OFFSET_FROM_FLYPOINT || ENABLE_TEST_CHECKPOINTS || ENABLE_MISC_TEST || TEST_PBF_LEFT_JOYSTICK || TEST_PBF_JOYSTICK2 || TEST_CHANGE_DIRECTION || TEST_CURRENT_DIRECTION){
test_code(env, context);
Expand All @@ -1226,6 +1225,9 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex
}
}

env.current_stats<AutoStoryStats>().m_runs++;
env.update_stats();

// Connect the controller.
require_player(env.console, context, BUTTON_L);

Expand Down Expand Up @@ -1278,11 +1280,9 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex
env.console.log("Ensure the minimap is unlocked.");
confirm_minimap_unlocked(env, context);
}

}

run_autostory(env, context);

send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
GO_HOME_WHEN_DONE.run_end_of_program(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ void get_on_or_off_ride(const ProgramInfo& info, VideoStream& stream, ProControl

void checkpoint_save(SingleSwitchProgramEnvironment& env, ProControllerContext& context, EventNotificationOption& notif_status_update, AutoStoryStats& stats){
save_game_from_overworld(env.program_info(), env.console, context);
stats.m_checkpoint++;
stats.m_checkpoints_started++;
env.update_stats();
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
}
Expand Down Expand Up @@ -1481,7 +1481,7 @@ void checkpoint_reattempt_loop(
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
stats.m_resets++;
env.update_stats();
}
}
Expand All @@ -1502,7 +1502,7 @@ void checkpoint_reattempt_loop_tutorial(
try{
if(i==0){
save_game_tutorial(env.program_info(), env.console, context);
stats.m_checkpoint++;
stats.m_checkpoints_started++;
env.update_stats();
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
}
Expand Down Expand Up @@ -1540,7 +1540,7 @@ void checkpoint_reattempt_loop_tutorial(
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
stats.m_resets++;
env.update_stats();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutostoryTools

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=505 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -10,10 +10,10 @@
#include <functional>
#include "CommonFramework/Language.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ProgramStats/StatsTracking.h"
#include "ML/Inference/ML_YOLOv5Detector.h"
#include "ML/Inference/ML_YOLONavigation.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h"
#include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h"

namespace PokemonAutomation{
Expand All @@ -24,20 +24,8 @@

static constexpr bool ENABLE_TEST = false;

struct AutoStoryStats : public StatsTracker{
AutoStoryStats()
: m_checkpoint(m_stats["Checkpoint"])
, m_segment(m_stats["Segment"])
, m_reset(m_stats["Reset"])
{
m_display_order.emplace_back("Checkpoint");
m_display_order.emplace_back("Segment");
m_display_order.emplace_back("Reset");
}
std::atomic<uint64_t>& m_checkpoint;
std::atomic<uint64_t>& m_segment;
std::atomic<uint64_t>& m_reset;
};
// Shared with the AutoStory programs of the other games.
using Pokemon::AutoStoryStats;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void AutoStory_Segment_01::run_segment(
AutoStoryStats& stats
) const{

stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void AutoStory_Segment_02::run_segment(
AutoStoryOptions options,
AutoStoryStats& stats
) const{
stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::string AutoStory_Segment_03::end_text() const{

void AutoStory_Segment_03::run_segment(SingleSwitchProgramEnvironment& env, ProControllerContext& context, AutoStoryOptions options, AutoStoryStats& stats) const{

stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void AutoStory_Segment_04::run_segment(
AutoStoryStats& stats
) const{

stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void AutoStory_Segment_05::run_segment(
AutoStoryStats& stats
) const{

stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void AutoStory_Segment_06::run_segment(
AutoStoryStats& stats
) const{

stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void AutoStory_Segment_07::run_segment(
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void AutoStory_Segment_08::run_segment(
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void AutoStory_Segment_09::run_segment(
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void AutoStory_Segment_10::run_segment(
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* AutoStory

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_11.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=640 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -57,7 +57,7 @@
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void AutoStory_Segment_12::run_segment(
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void AutoStory_Segment_13::run_segment(
) const{


stats.m_segment++;
stats.m_segments_started++;
env.update_stats();
context.wait_for_all_requests();
env.console.log("Start Segment " + name(), COLOR_ORANGE);
Expand Down
Loading
Loading