-
Notifications
You must be signed in to change notification settings - Fork 4
Add auto-naming for main saving functions #362
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds automatic default filename generation for CSV export functions in the dynamics simulation system. The changes allow users to call save functions without providing a filename, which will automatically generate a timestamped filename based on the simulation name and current datetime.
- Adds simulation name tracking and safe filename generation utilities to the base
Dynamicsclass - Updates three save functions (
saveStreetDensities,saveTravelData,saveMacroscopicObservables) to support optional filename parameters with automatic generation - Adds comprehensive test coverage for the new default filename behavior
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/dsf/base/Dynamics.hpp | Adds m_name member, setName/name accessors, and helper methods m_safeDateTime/m_safeName for generating safe filenames |
| src/dsf/mobility/RoadDynamics.hpp | Updates three save functions to accept optional filenames with automatic generation when empty, and changes saveTravelData default reset parameter |
| test/mobility/Test_dynamics.cpp | Adds comprehensive test cases verifying the new default filename functionality |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
|
||
| for (const auto& entry : std::filesystem::directory_iterator(".")) { | ||
| if (entry.path().filename().string().find("street_densities.csv") != | ||
| std::string::npos) { |
Check warning
Code scanning / Cppcheck (reported by Codacy)
Consider using std::find_if algorithm instead of a raw loop. Warning test
| SUBCASE("Save functions with default filenames") { | ||
| GIVEN("A dynamics object with some streets and agents") { | ||
| Street s1{0, std::make_pair(0, 1), 30., 15.}; | ||
| Street s2{1, std::make_pair(1, 2), 30., 15.}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
| } | ||
| SUBCASE("Save functions with default filenames") { | ||
| GIVEN("A dynamics object with some streets and agents") { | ||
| Street s1{0, std::make_pair(0, 1), 30., 15.}; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.3 rule Note test
| void RoadDynamics<delay_t>::saveMacroscopicObservables(std::string filename, | ||
| char const separator) { | ||
| if (filename.empty()) { | ||
| filename = this->m_safeDateTime() + '_' + this->m_safeName() + |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 18.4 rule Note
| void RoadDynamics<delay_t>::saveMacroscopicObservables(const std::string& filename, | ||
| void RoadDynamics<delay_t>::saveMacroscopicObservables(std::string filename, | ||
| char const separator) { | ||
| if (filename.empty()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
| /// @param filename The name of the file (default is "{datetime}_{simulation_name}_street_densities.csv") | ||
| /// @param normalized If true, the densities are normalized in [0, 1] | ||
| void saveStreetDensities(const std::string& filename, | ||
| void saveStreetDensities(std::string filename = std::string(), |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 17.8 rule Note
| /// @brief Get the current simulation time as epoch time | ||
| /// @return std::time_t, The current simulation time as epoch time | ||
| inline std::time_t time() const { return m_timeInit + m_timeStep; } | ||
| inline auto time() const { return m_timeInit + m_timeStep; } |
Check notice
Code scanning / Cppcheck (reported by Codacy)
time is Y2038-unsafe Note
| Dynamics(network_t& graph, std::optional<unsigned int> seed = std::nullopt); | ||
|
|
||
| /// @brief Set the name of the simulation | ||
| /// @param name The name of the simulation |
Check notice
Code scanning / Cppcheck (reported by Codacy)
time is Y2038-unsafe Note
| #ifdef __APPLE__ | ||
| std::time_t const t = time(); | ||
| std::ostringstream oss; | ||
| oss << std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S"); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
localtime is Y2038-unsafe Note
| /// @return std::string, The safe date-time string | ||
| inline auto m_safeDateTime() const { | ||
| #ifdef __APPLE__ | ||
| std::time_t const t = time(); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
time is Y2038-unsafe Note
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #362 +/- ##
==========================================
+ Coverage 82.90% 82.97% +0.06%
==========================================
Files 50 50
Lines 4879 5057 +178
Branches 556 573 +17
==========================================
+ Hits 4045 4196 +151
- Misses 828 853 +25
- Partials 6 8 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Close #314