-
Notifications
You must be signed in to change notification settings - Fork 4
Move output from CSV files to a SQL db
#403
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
| dynamics.setSpeedFluctuationSTD(0.1); | ||
|
|
||
| // Connect database for saving data | ||
| dynamics.connectDataBase(OUT_FOLDER + "simulation_data.db"); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 18.4 rule Note
| dynamics.setDataUpdatePeriod(30); // Store data every 30 time steps | ||
|
|
||
| // Connect database for saving data | ||
| dynamics.connectDataBase(OUT_FOLDER + "simulation_data.db"); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 18.4 rule Note
| #ifdef __APPLE__ | ||
| std::time_t const t = std::chrono::system_clock::to_time_t(now); | ||
| 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
| std::filesystem::remove(testFile); | ||
| SQLite::Statement cols(db, | ||
| "SELECT street_id, density, avg_speed FROM road_data"); | ||
| while (cols.executeStep()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note test
| std::ifstream file(entry.path()); | ||
| REQUIRE(file.is_open()); | ||
| // Evolve until agent reaches destination (with limit) | ||
| for (int iter = 0; iter < 1000 && dynamics.nAgents() > 0; ++iter) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note test
| break; | ||
| } | ||
| SQLite::Statement cols(db, "SELECT distance_m, travel_time_s FROM travel_data"); | ||
| while (cols.executeStep()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note test
| SQLite::Statement cols(db, "SELECT distance_m, travel_time_s FROM travel_data"); | ||
| while (cols.executeStep()) { | ||
| auto distance = cols.getColumn(0).getDouble(); | ||
| auto time = cols.getColumn(1).getDouble(); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
time is Y2038-unsafe Note test
| auto distance = cols.getColumn(0).getDouble(); | ||
| auto time = cols.getColumn(1).getDouble(); | ||
| CHECK(distance > 0.0); | ||
| CHECK(time > 0.0); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
time is Y2038-unsafe Note test
|
|
||
| file.close(); | ||
| std::filesystem::remove(testFile); | ||
| for (int iter = 0; iter < 1000 && dynamics.nAgents() > 0; ++iter) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 12.1 rule Note test
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #403 +/- ##
==========================================
+ Coverage 85.81% 87.42% +1.61%
==========================================
Files 54 53 -1
Lines 6190 5941 -249
Branches 671 658 -13
==========================================
- Hits 5312 5194 -118
+ Misses 862 728 -134
- Partials 16 19 +3
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:
|
| /// @brief Copy assignment operator for PointsCluster. | ||
| /// @param other The PointsCluster to copy from. | ||
| /// @return Reference to this PointsCluster. | ||
| PointsCluster& operator=(PointsCluster const& other) = default; |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 16.3 rule Note
| cluster_radius_km, | ||
| max_speed_kph, | ||
| min_duration_min](auto& pair) { | ||
| max_speed_kph](auto& pair) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 13.1 rule Note
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.
Cppcheck (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
5157ae1 to
808fcc9
Compare
| } | ||
|
|
||
| /* Database modal styles */ | ||
| .modal { |
Check warning
Code scanning / Csslint (reported by Codacy)
Rule doesn't have all its properties in alphabetical order. Warning
| display: none; | ||
| } | ||
|
|
||
| .modal-content { |
Check warning
Code scanning / Csslint (reported by Codacy)
Rule doesn't have all its properties in alphabetical order. Warning
| text-align: center; | ||
| } | ||
|
|
||
| .modal-content h2 { |
Check warning
Code scanning / Csslint (reported by Codacy)
Rule doesn't have all its properties in alphabetical order. Warning
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| .db-input-group input[type="file"] { |
Check warning
Code scanning / Csslint (reported by Codacy)
Rule doesn't have all its properties in alphabetical order. Warning
| border-color: #4CAF50; | ||
| } | ||
|
|
||
| .db-status { |
Check warning
Code scanning / Csslint (reported by Codacy)
Rule doesn't have all its properties in alphabetical order. Warning
| text-align: center; | ||
| } | ||
|
|
||
| .modal-content h2 { |
Check notice
Code scanning / Csslint (reported by Codacy)
Heading (h2) should not be qualified. Note
| border: 2px dashed #ccc; | ||
| border-radius: 5px; | ||
| width: 100%; | ||
| box-sizing: border-box; |
Check notice
Code scanning / Csslint (reported by Codacy)
The box-sizing property isn't supported in IE6 and IE7. Note
| min-height: 20px; | ||
| } | ||
|
|
||
| .db-status.error { |
Check notice
Code scanning / Csslint (reported by Codacy)
Adjoining classes: .db-status.error Note
| color: #c62828; | ||
| } | ||
|
|
||
| .db-status.success { |
Check notice
Code scanning / Csslint (reported by Codacy)
Adjoining classes: .db-status.success Note
| color: #2e7d32; | ||
| } | ||
|
|
||
| .db-status.loading { |
Check notice
Code scanning / Csslint (reported by Codacy)
Adjoining classes: .db-status.loading Note
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.
Stylelint (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
|
|
||
| // Grufoony - 9/2/2026 | ||
| // TODO: make this dynamic based on data range | ||
| const MAX_DENSITY = 200; |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note
| // Grufoony - 9/2/2026 | ||
| // TODO: make this dynamic based on data range | ||
| const MAX_DENSITY = 200; | ||
| const MAX_DENSITY_INVERTED = 1 / MAX_DENSITY; |
Check notice
Code scanning / Jshint (reported by Codacy)
Prohibits the use of __iterator__ property due to compatibility issues Note
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 migrates simulation output from CSV files to a SQLite database, updates the C++ simulation engine to write structured results into that DB, and rewrites the webapp to load and visualize simulations directly from the SQLite file (including selecting which simulation run to view).
Changes:
- Add SQLite-backed persistence for per-street data, aggregate stats, travel data, simulation metadata, and network topology (edges/nodes).
- Update the webapp UI/JS to load a user-selected SQLite database in-browser (sql.js) and select a simulation to visualize.
- Remove the legacy
AdjacencyMatrixAPI, tests, and Python bindings that depended on it; refresh examples/tests to use DB saving.
Reviewed changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| webapp/index.html | Adds sql.js dependency and a modal to select/load a SQLite DB. |
| webapp/styles.css | Styles for the new DB-load modal. |
| webapp/script.js | Switches data loading from CSV/config to SQLite queries + simulation selection flow. |
| src/dsf/base/Dynamics.hpp | Adds simulation id and SQLite DB connection handling. |
| src/dsf/mobility/RoadDynamics.hpp | Adds DB schema initialization, network dump, and DB-backed saving in evolve(). |
| src/dsf/mobility/FirstOrderDynamics.hpp / .cpp | Implements dumping simulation parameters into a simulations table. |
| src/dsf/mobility/RoadNetwork.hpp / .cpp | Removes AdjacencyMatrix-based construction and related includes/ctors. |
| src/dsf/base/Network.hpp | Removes AdjacencyMatrix-based constructor. |
| src/dsf/bindings.cpp | Drops AdjacencyMatrix bindings and replaces CSV save APIs with saveData() + DB connect exposure. |
| CMakeLists.txt | Fetches/links SQLiteCpp and exposes it via dsf target. |
| examples/slow_charge_tl.cpp / slow_charge_rb.cpp | Switch examples from CSV saving to DB saving via connectDataBase() + saveData(). |
| test/mobility/Test_dynamics.cpp | Replaces CSV-based save tests with DB table/schema assertions using SQLiteCpp. |
| test/mobility/Test_graph.cpp | Removes AdjacencyMatrix constructor subcase usage. |
| test/base/Test_AdjacencyMatrix.cpp | Deletes AdjacencyMatrix test suite. |
| src/dsf/base/AdjacencyMatrix.hpp / .cpp | Deletes AdjacencyMatrix implementation. |
| src/dsf/dsf.hpp | Removes AdjacencyMatrix include. |
| src/dsf/mdt/TrajectoryCollection.cpp | Fixes lambda capture list (removes unused capture). |
| src/dsf/mdt/PointsCluster.hpp | Adds copy assignment operator. |
| .gitignore | Ignores *.ipynb. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
webapp/script.js
Outdated
| for (const ts of timestamps) { | ||
| // Get all road_data for this timestamp and simulation | ||
| const dataResult = db.exec( | ||
| `SELECT street_id, density FROM road_data WHERE simulation_id = ${selectedSimulationId} AND datetime = '${ts}'` |
Copilot
AI
Feb 9, 2026
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.
road_data is created by the simulator with a density_vpk column (see C++ schema), but this query selects density. This will return NULL/throw and the map will show no densities. Update the query (and downstream usage) to read density_vpk (and optionally also pull avg_speed_kph, counts, etc. if needed).
| `SELECT street_id, density FROM road_data WHERE simulation_id = ${selectedSimulationId} AND datetime = '${ts}'` | |
| `SELECT street_id, density_vpk FROM road_data WHERE simulation_id = ${selectedSimulationId} AND datetime = '${ts}'` |
TODO: