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
Draft
dayfine
wants to merge
51
commits into
switch/system-keyboard
Choose a base branch
from
autostory/r3-shared-stats
base: switch/system-keyboard
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
b76d4cb
AutoStory: build the start/end select databases with one shared helper
dayfine 198b207
AutoStory: compute start/end story indices with one shared function, …
dayfine 17d4034
AutoStory: move AutoStoryStats to Pokemon/AutoStory
dayfine 56e6da6
Merge origin/main into autostory/r1-select-db
dayfine 935335a
Merge origin/autostory/r1-select-db into autostory/r2-story-index
dayfine df60654
Merge origin/autostory/r2-story-index into autostory/r3-shared-stats
dayfine 4834685
Merge origin/main into autostory/r1-select-db
dayfine b3c3a90
Merge origin/autostory/r1-select-db into autostory/r2-story-index
dayfine 676a03d
Merge origin/autostory/r2-story-index into autostory/r3-shared-stats
dayfine e3377aa
Merge origin/main into autostory/r1-select-db
dayfine 86b2e84
Merge origin/autostory/r1-select-db into autostory/r2-story-index
dayfine 5718316
Merge origin/autostory/r2-story-index into autostory/r3-shared-stats
dayfine 5d23a56
AutoStory: test the shared select database with the helper that build…
dayfine 883c048
Merge autostory/r1-select-db (5d23a5601: the select-database test) in…
dayfine 7cc66e3
Merge autostory/r2-story-index (r1's select-database test moved) into…
dayfine 1ea884b
AutoStory: shared start/end select database and story index
dayfine 8698f8c
Merge origin/main into autostory/r1-select-db
dayfine 0206e94
Merge origin/autostory/r1-select-db into autostory/r2-story-index
dayfine 37d77f2
Merge origin/autostory/r2-story-index into autostory/r3-shared-stats
dayfine 2b03556
AutoStory: segment descriptions use the shared index getters
dayfine 057306f
AutoStory: note story_index's two-section assumption
dayfine 101f574
AutoStory: describe sections as break points in story_index's NOTE
dayfine 9ca64aa
Merge origin/autostory/story-select into autostory/r2-story-index
dayfine cee0b13
Merge autostory/r2-story-index into autostory/r3-shared-stats
dayfine 6c447d7
Merge remote-tracking branch 'origin/main' into sync/story-export-r2
dayfine edc8e51
Merge branch 'sync/story-export-r2' into sync/story-export-r3
dayfine cc65994
Document shared stats alias and namespace endings
dayfine 8b30e00
AutoStory: shared run report: log lines and story counts
dayfine 08d50fc
AutoStory: one test entry point, output parameter last, std::format
dayfine 1dba587
AutoStory: one test header per suite
dayfine a7457ef
Merge origin/main into autostory/r3-shared-stats
dayfine 5a0b9d4
Merge origin/main into autostory/r3-shared-stats
dayfine fbb21f9
Merge origin/main into autostory/r3-shared-stats
dayfine 3bfe35e
Merge remote-tracking branch 'origin/switch/system-keyboard' into aut…
dayfine 1e49c4f
SV AutoStory: write the shared checkpoint log lines
dayfine 1faac37
Merge remote-tracking branch 'origin/switch/system-keyboard' into aut…
dayfine 1b5aaf0
SV AutoStory: keep the legacy file line counts (code health)
dayfine 7cdde2d
AutoStory: review fixes for the shared log lines
dayfine 7b7ef1d
AutoStory: nest the stats test case's Input and Expectation
dayfine 9ad520e
AutoStory: [Checkpoint] lines take an optional display text
dayfine 687023e
AutoStory: checkpoint_head -> checkpoint_prefix
dayfine 2a33aa5
SV AutoStory: checkpoint attempt, reset and pass lines use StoryLog
dayfine 8310a2a
AutoStory: move StoryRunCounts to the segment report, its first user
dayfine ea12373
AutoStory: story_short_line, the overlay form of a log line
dayfine 752ad35
StoryLog: checkpoint lines only; reset line takes the attempt limit
dayfine 2eca3ab
StoryLog tests: the case name sits outside its input
dayfine ec6e5e2
StoryLog: add_checkpoint_prefix replaces display_text
dayfine 7ab7d55
Merge switch/system-keyboard into autostory/r3-shared-stats
dayfine 6612f39
Merge switch/system-keyboard into autostory/r3-shared-stats
dayfine e81d3bb
AutoStory: StoryRunStats for the story engines (Runs, Checkpoints Pas…
dayfine 740530b
AutoStory: SV's AutoStoryStats stays in SV; the shared header keeps S…
dayfine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
32 changes: 32 additions & 0 deletions
32
SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
85 changes: 85 additions & 0 deletions
85
SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
85 changes: 85 additions & 0 deletions
85
SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryLog.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( | ||
| 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( | ||
| 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( | ||
| 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( | ||
| 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); | ||
|
|
||
|
|
||
|
|
||
| } // namespace Pokemon | ||
| } // namespace PokemonAutomation | ||
| #endif | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.