Skip to content

Conversation

@Grufoony
Copy link
Collaborator

@Grufoony Grufoony commented Nov 5, 2025

Close #314

@Grufoony Grufoony requested a review from Copilot November 5, 2025 09:24
Copy link
Contributor

Copilot AI left a 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 Dynamics class
  • 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

Consider using std::find_if algorithm instead of a raw loop.
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

MISRA 12.3 rule
}
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

MISRA 12.3 rule
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

MISRA 18.4 rule
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

MISRA 14.4 rule
/// @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

MISRA 17.8 rule
/// @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

time is Y2038-unsafe
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

time is Y2038-unsafe
#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

localtime is Y2038-unsafe
/// @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

time is Y2038-unsafe
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 94.80519% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.97%. Comparing base (30e1446) to head (704ccb6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/dsf/mobility/RoadDynamics.hpp 81.81% 2 Missing ⚠️
test/mobility/Test_dynamics.cpp 96.22% 0 Missing and 2 partials ⚠️
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     
Flag Coverage Δ
unittests 82.97% <94.80%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Grufoony Grufoony merged commit 1bd2a0f into main Nov 5, 2025
41 of 42 checks passed
@Grufoony Grufoony deleted the autoNameFiles branch November 5, 2025 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add auto-naming behavior for export functions

2 participants