Repository navigation
AutoStory: shared run report (stats + log lines) #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b76d4cb
198b207
17d4034
56e6da6
935335a
df60654
4834685
b3c3a90
676a03d
e3377aa
86b2e84
5718316
5d23a56
883c048
7cc66e3
1ea884b
8698f8c
0206e94
37d77f2
2b03556
057306f
101f574
9ca64aa
cee0b13
6c447d7
edc8e51
cc65994
8b30e00
08d50fc
1dba587
a7457ef
5a0b9d4
fbb21f9
3bfe35e
1e49c4f
1faac37
1b5aaf0
7cdde2d
7b7ef1d
9ad520e
687023e
2a33aa5
8310a2a
ea12373
752ad35
2eca3ab
ec6e5e2
7ab7d55
6612f39
e81d3bb
740530b
ddad1c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* 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{ | ||
|
|
||
|
|
||
| // The stats of a story engine's AutoStory: program runs, checkpoints passed | ||
| // and game resets to a checkpoint's save. | ||
| struct StoryRunStats : public StatsTracker{ | ||
| StoryRunStats() | ||
| : m_runs(m_stats["Runs"]) | ||
| , m_checkpoints_passed(m_stats["Checkpoints Passed"]) | ||
| , m_resets(m_stats["Resets"]) | ||
| { | ||
| m_display_order.emplace_back("Runs"); | ||
| m_display_order.emplace_back("Checkpoints Passed"); | ||
| m_display_order.emplace_back("Resets"); | ||
| } | ||
| std::atomic<uint64_t>& m_runs; | ||
| std::atomic<uint64_t>& m_checkpoints_passed; | ||
| std::atomic<uint64_t>& m_resets; | ||
| }; | ||
|
|
||
|
|
||
| } // namespace Pokemon | ||
| } // namespace PokemonAutomation | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* AutoStory Tests | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| * The unit tests of the pieces every AutoStory program shares, story | ||
| * engine or not. add_tests_AutoStory() is the one entry point the unit | ||
| * test runner calls; a new shared AutoStory suite registers there. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_Pokemon_AutoStory_Tests_H | ||
| #define PokemonAutomation_Pokemon_AutoStory_Tests_H | ||
|
|
||
| #include "Common/Cpp/TestRunners/UnitTestDatabase.h" | ||
| #include "Pokemon_AutoStorySelect_Tests.h" | ||
| #include "Pokemon_StoryLog_Tests.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace Pokemon{ | ||
|
|
||
|
|
||
| // Registers every shared AutoStory suite, for the unit test runner. | ||
| inline void add_tests_AutoStory(UnitTestDatabase& database){ | ||
| add_tests_AutoStorySelect(database); | ||
| add_tests_StoryLog(database); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } // namespace Pokemon | ||
| } // namespace PokemonAutomation | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* Story Log | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include <format> | ||
| #include "Pokemon_StoryLog.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace Pokemon{ | ||
|
|
||
|
|
||
| namespace{ | ||
|
|
||
| std::string resets_text(size_t attempt){ | ||
| if (attempt <= 1){ | ||
| return "one-shot"; | ||
| } | ||
| return std::format("{} reset{}", attempt - 1, attempt == 2 ? "" : "s"); | ||
| } | ||
|
|
||
| // "[Checkpoint] 00.04", or the game's own checkpoint text unchanged. | ||
| std::string checkpoint_prefix(std::string_view checkpoint, bool add_checkpoint_prefix){ | ||
| if (!add_checkpoint_prefix){ | ||
| return std::string(checkpoint); | ||
| } | ||
| return std::format("[Checkpoint] {}", checkpoint); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
|
|
||
| std::string checkpoint_start_line( | ||
| std::string_view checkpoint, std::optional<size_t> events, bool add_checkpoint_prefix | ||
| ){ | ||
| const std::string prefix = checkpoint_prefix(checkpoint, add_checkpoint_prefix); | ||
| if (!events){ | ||
| return std::format("{}: start", prefix); | ||
| } | ||
| return std::format("{}: start, {} events", prefix, *events); | ||
| } | ||
|
|
||
| std::string checkpoint_attempt_line( | ||
| std::string_view checkpoint, size_t attempt, std::optional<size_t> attempts, bool add_checkpoint_prefix | ||
| ){ | ||
| const std::string prefix = checkpoint_prefix(checkpoint, add_checkpoint_prefix); | ||
| if (!attempts){ | ||
| return std::format("{}: attempt {}", prefix, attempt); | ||
| } | ||
| return std::format("{}: attempt {}/{}", prefix, attempt, *attempts); | ||
| } | ||
|
|
||
| std::string checkpoint_pass_line(std::string_view checkpoint, size_t attempt, bool add_checkpoint_prefix){ | ||
| return std::format( | ||
| "{}: passed on attempt {} ({})", | ||
| checkpoint_prefix(checkpoint, add_checkpoint_prefix), attempt, resets_text(attempt) | ||
| ); | ||
| } | ||
|
|
||
| std::string checkpoint_reset_line( | ||
| std::string_view checkpoint, size_t next_attempt, std::optional<size_t> attempts, bool add_checkpoint_prefix | ||
| ){ | ||
| const std::string prefix = checkpoint_prefix(checkpoint, add_checkpoint_prefix); | ||
| if (!attempts){ | ||
| return std::format("{}: failed, resetting for attempt {}", prefix, next_attempt); | ||
| } | ||
| return std::format("{}: failed, resetting for attempt {}/{}", prefix, next_attempt, *attempts); | ||
| } | ||
|
|
||
| std::string story_short_line(std::string_view line){ | ||
| if (!line.starts_with('[')){ | ||
| return std::string(line); | ||
| } | ||
| const size_t end = line.find("] "); | ||
| if (end == std::string_view::npos){ | ||
| return std::string(line); | ||
| } | ||
| return std::string(line.substr(end + 2)); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } // namespace Pokemon | ||
| } // namespace PokemonAutomation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* Story Log | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| * A story is split at three levels: a segment is a chapter of | ||
| * checkpoints, a checkpoint is the stretch between two saves and the unit | ||
| * a run retries, and an event is one step inside a checkpoint. This file | ||
| * writes the checkpoint lines: start, attempt, reset and pass, in one | ||
| * format for every game, so the program developer and user find each | ||
| * checkpoint's attempts the same way in any game's log. Nothing here runs | ||
| * a story. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_Pokemon_StoryLog_H | ||
| #define PokemonAutomation_Pokemon_StoryLog_H | ||
|
|
||
| #include <cstddef> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace Pokemon{ | ||
|
|
||
|
|
||
| // The lines below start with "[Checkpoint] " and then `checkpoint`. A game | ||
| // whose checkpoint text already says it is a checkpoint (SV's | ||
| // "Checkpoint:: 004 - 02 ...") passes that text as `checkpoint` and | ||
| // `add_checkpoint_prefix` false, and the line starts with the text alone: | ||
| // Checkpoint:: 004 - 02 ...: start | ||
|
|
||
| // A checkpoint starts; the story engine also says it has `events` events: | ||
| // [Checkpoint] 00.04: start | ||
| // [Checkpoint] 00.04: start, 3 events | ||
| std::string checkpoint_start_line( | ||
|
Check warning on line 36 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h
|
||
| std::string_view checkpoint, | ||
| std::optional<size_t> events = std::nullopt, | ||
| bool add_checkpoint_prefix = true | ||
| ); | ||
|
|
||
| // An attempt at a checkpoint starts, counting from 1, out of the | ||
| // program's limit of `attempts` if it has one: | ||
| // [Checkpoint] 00.04: attempt 2 | ||
| // [Checkpoint] 00.04: attempt 2/3 | ||
| std::string checkpoint_attempt_line( | ||
|
Check warning on line 46 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h
|
||
| std::string_view checkpoint, | ||
| size_t attempt, | ||
| std::optional<size_t> attempts = std::nullopt, | ||
| bool add_checkpoint_prefix = true | ||
| ); | ||
|
|
||
| // A checkpoint passed on attempt `attempt`, counting from 1; every attempt | ||
| // before it ended in a reset: | ||
| // [Checkpoint] 00.03: passed on attempt 1 (one-shot) | ||
| // [Checkpoint] 00.04: passed on attempt 3 (2 resets) | ||
| std::string checkpoint_pass_line( | ||
|
Check warning on line 57 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h
|
||
| std::string_view checkpoint, | ||
| size_t attempt, | ||
| bool add_checkpoint_prefix = true | ||
| ); | ||
|
|
||
| // An attempt failed and the game resets to the checkpoint's save for | ||
| // attempt `next_attempt`, out of the limit of `attempts` if it has one: | ||
| // [Checkpoint] 00.04: failed, resetting for attempt 2 | ||
| // [Checkpoint] 00.04: failed, resetting for attempt 2/3 | ||
| std::string checkpoint_reset_line( | ||
|
Check warning on line 67 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h
|
||
| std::string_view checkpoint, | ||
| size_t next_attempt, | ||
| std::optional<size_t> attempts = std::nullopt, | ||
| bool add_checkpoint_prefix = true | ||
| ); | ||
|
|
||
| // The full lines above go to the log. The video overlay, which wraps its | ||
| // lines, shows each one short, without its leading "[Tag] ": | ||
| // [Checkpoint] 12.03: start, 18 events -> 12.03: start, 18 events | ||
| // Any line with a leading "[Tag] " is shortened the same way. A line | ||
| // without a tag, like SV's checkpoint text, is returned unchanged. | ||
| std::string story_short_line(std::string_view line); | ||
|
Check warning on line 79 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h
|
||
|
|
||
|
|
||
|
|
||
| } // namespace Pokemon | ||
| } // namespace PokemonAutomation | ||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.