From e6123e570291974b012f1472e9e72325b23fed58 Mon Sep 17 00:00:00 2001 From: Wessel Tip Date: Wed, 5 Nov 2025 15:50:56 +0100 Subject: [PATCH] fix(Config,Database): Remove references to assignment one --- doc/architecture/managers/ConfigManager.md | 4 +- doc/architecture/managers/DatabaseManager.md | 67 +++++-------------- doc/installation/installation.md | 2 +- doc/tests/ConfigManager.md | 2 +- doc/tests/DatabaseManager.md | 14 ++-- docker-compose.yml | 2 +- src/config.toml | 2 +- .../src/config/ConfigManager.cpp | 2 +- .../test/ConfigManager.test.cpp | 2 +- 9 files changed, 33 insertions(+), 64 deletions(-) diff --git a/doc/architecture/managers/ConfigManager.md b/doc/architecture/managers/ConfigManager.md index 664b54f..47728db 100644 --- a/doc/architecture/managers/ConfigManager.md +++ b/doc/architecture/managers/ConfigManager.md @@ -84,7 +84,7 @@ std::vector default_config_paths_ = { #### Default Values and Fallbacks - **host**: `"localhost"` - Local database server - **port**: `5432` - Standard PostgreSQL port -- **dbname**: `"grades"` - Application-specific database +- **dbname**: `"imu_data"` - Application-specific database - **user**: `"postgres"` - Default PostgreSQL user - **password**: `"postgres"` - Default PostgreSQL password - **timeout**: `30` seconds - connection timeout @@ -121,7 +121,7 @@ Example complete TOML configuration: [database] host = "localhost" port = 5432 -dbname = "grades" +dbname = "imu_data" user = "postgres" password = "postgres" timeout = 30 diff --git a/doc/architecture/managers/DatabaseManager.md b/doc/architecture/managers/DatabaseManager.md index a4bc1d1..e311f75 100644 --- a/doc/architecture/managers/DatabaseManager.md +++ b/doc/architecture/managers/DatabaseManager.md @@ -1,9 +1,9 @@ -# DatabaseManager (`assignments::one::DatabaseManager`) +# DatabaseManager (`assignments::two::DatabaseManager`) ## Overview -The `DatabaseManager` class is a PostgreSQL database interface for the ROS2 grade calculator. -It handles all database operations including connection management, table creation and data insertion. +The `DatabaseManager` class is a PostgreSQL database interface for the ROS2 IMU data collection system. +It handles all database operations including connection management, table creation and data storage. ## Implementation Details @@ -28,7 +28,7 @@ DatabaseManager(rclcpp::Logger logger) > Returns `true` on successful connection, `false` on failure - Establishes connection to PostgreSQL database using connection information from the config TOML -- Connection string format: `"host=localhost port=5432 dbname=grades user=postgres password=postgres"` +- Connection string format: `"host=localhost port=5432 dbname=imu_data user=postgres password=postgres"` **`bool is_connected() const`** > Returns `true` if connection exists and is open @@ -47,56 +47,25 @@ DatabaseManager(rclcpp::Logger logger) **`void create_tables()`** - Creates all required database tables using SQL queries from `SQLQueries.hpp` - Tables created: - - `enrollments`: Student course enrollments - - `exam_results`: Individual exam scores - - `course_results`: Final course grades and statistics + - `imu_data`: IMU sensor readings with linear acceleration and angular velocity data - Uses transactions for atomic table creation -**`void insert_sample_data()`** -- Inserts predefined sample student data - ### Data Operations -#### Student Course Management +#### IMU Data Storage -**`std::vector queue_pending_combinations()`** -> Returns vector of StudentCourse objects for processing queue +**`bool store_imu_data(double linear_accel_x, double linear_accel_y, double linear_accel_z, double angular_vel_x, double angular_vel_y, double angular_vel_z)`** +> Returns `true` on successful storage, `false` on failure -- Gets all student-course combinations that need exam results generated -- Executes complex SQL query to find missing exam results - -**`bool enroll_student_into_course(const StudentCourse& sc)`** -> Returns `true` on successful enrollment, `false` on failure - -- Enrolls a student into a specific course - -#### Exam Result Processing - -**`bool store_exam_result(const std::string& student_name, const std::string& course_name, int grade)`** -- Stores individual exam results in the database +- Stores IMU sensor readings in the database - Parameters: - - `student_name`: Name of the student - - `course_name`: Name of the course - - `grade`: Exam score (10-100) - -**`bool store_final_course_result(const StudentCourse& sc, int exam_count, int final_grade)`** -- Stores calculated final course results -- Parameters: - - `sc`: StudentCourse object containing student and course names - - `exam_count`: Number of exams taken - - `final_grade`: Calculated final grade -- Used by grade calculation nodes for final result storage - -#### Grade Retrieval - -**`int get_final_course_grade(const StudentCourse& sc)`** -> Returns: -> - `> 0`: Valid final grade (rounded average) -> - `-1`: No exams taken or no results found - -- Gets final calculated grade for a student-course combination -- Performs average calculation with proper rounding -- Used by nodes to check if final grading is complete + - `linear_accel_x`: Linear acceleration on X-axis + - `linear_accel_y`: Linear acceleration on Y-axis + - `linear_accel_z`: Linear acceleration on Z-axis + - `angular_vel_x`: Angular velocity around X-axis + - `angular_vel_y`: Angular velocity around Y-axis + - `angular_vel_z`: Angular velocity around Z-axis +- Automatically adds timestamp on insertion ### Logging @@ -117,9 +86,9 @@ DatabaseManager db_manager(node->get_logger()); // Check connection status if (db_manager.is_connected()) { // Database ready for operations - bool success = db_manager.store_exam_result("Wessel", "ROS2", 85); + bool success = db_manager.store_imu_data(1.2, -0.5, 9.8, 0.01, 0.02, 0.03); if (success) { - RCLCPP_INFO(logger, "Exam result stored successfully"); + RCLCPP_INFO(logger, "IMU data stored successfully"); } } ``` diff --git a/doc/installation/installation.md b/doc/installation/installation.md index 16a4208..635d66d 100644 --- a/doc/installation/installation.md +++ b/doc/installation/installation.md @@ -36,7 +36,7 @@ sudo docker-compose up ``` You can configure specific database settings in the `docker-compose.yaml` in the root folder or the `config.toml` file in the `src/` folder -### Start the Grade calculator program +### Start the IMU Reader program ```bash ros2 launch g2_2025_imu_reader_pkg imu_reader.launch.xml ``` diff --git a/doc/tests/ConfigManager.md b/doc/tests/ConfigManager.md index e0c6208..3fff236 100644 --- a/doc/tests/ConfigManager.md +++ b/doc/tests/ConfigManager.md @@ -61,7 +61,7 @@ Unit tests for `ConfigManager` are implemented in `src/g2_2025_imu_reader_pkg/te [database] host = "localhost" port = 5432 - dbname = "grades" + dbname = "imu_data" user = "postgres" password = "postgres" ``` diff --git a/doc/tests/DatabaseManager.md b/doc/tests/DatabaseManager.md index 7747675..b1bb8c2 100644 --- a/doc/tests/DatabaseManager.md +++ b/doc/tests/DatabaseManager.md @@ -18,16 +18,16 @@ Unit tests for `DatabaseManager` are implemented in `src/g2_2025_imu_reader_pkg/ - **Test Action:** Call `is_connected()` method - **Expected Result:** Returns either `true` or `false` (no crashes or invalid states) -### 3. QueuePendingCombinationsTest +### 3. StoreIMUDataWhenNotConnected -**Description:** Verifies retrieval of pending student-course combinations that need exam results. +**Description:** Verifies that storing IMU data without an active database connection fails gracefully. -- Test action: Call `store_imu_data(linear_x, linear_y, linear_z, ang_x, ang_y, ang_z)` without an active DB connection. -- Expected result: Returns `false` and does not throw — method must check connection status before DB operations. +- **Test Action:** Call `store_imu_data(linear_x, linear_y, linear_z, ang_x, ang_y, ang_z)` without an active DB connection +- **Expected Result:** Returns `false` and does not throw — method must check connection status before DB operations ### 4. CreateTablesNoCrash -Description: Verifies calling `create_tables()` without an active connection is safe. +**Description:** Verifies calling `create_tables()` without an active connection is safe. -- Test action: Call `create_tables()` on a manager that is not connected. -- Expected result: No exception thrown; the function should be a no-op when no DB connection exists. +- **Test Action:** Call `create_tables()` on a manager that is not connected +- **Expected Result:** No exception thrown; the function should be a no-op when no DB connection exists diff --git a/docker-compose.yml b/docker-compose.yml index 69d96ce..1fd1383 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: environment: - POSTGRES_PASSWORD=postgres - POSTGRES_USER=postgres - - POSTGRES_DB=grades + - POSTGRES_DB=imu_data ports: - "5432:5432" mosquitto: diff --git a/src/config.toml b/src/config.toml index f20f203..1af459b 100644 --- a/src/config.toml +++ b/src/config.toml @@ -1,7 +1,7 @@ [database] host = "localhost" port = 5432 -dbname = "grades" +dbname = "imu_data" user = "postgres" password = "postgres" timeout = 30 diff --git a/src/g2_2025_imu_reader_pkg/src/config/ConfigManager.cpp b/src/g2_2025_imu_reader_pkg/src/config/ConfigManager.cpp index 501a9f1..cd9d372 100644 --- a/src/g2_2025_imu_reader_pkg/src/config/ConfigManager.cpp +++ b/src/g2_2025_imu_reader_pkg/src/config/ConfigManager.cpp @@ -83,7 +83,7 @@ DatabaseConfig ConfigManager::parse_database_config(const toml::table& config) c db_config.host = database_section["host"].value_or("localhost"); db_config.port = database_section["port"].value_or(5432); - db_config.dbname = database_section["dbname"].value_or("grades"); + db_config.dbname = database_section["dbname"].value_or("imu_data"); db_config.user = database_section["user"].value_or("postgres"); db_config.password = database_section["password"].value_or("postgres"); db_config.timeout = database_section["timeout"].value_or(30); diff --git a/src/g2_2025_imu_reader_pkg/test/ConfigManager.test.cpp b/src/g2_2025_imu_reader_pkg/test/ConfigManager.test.cpp index 6131aa1..5141809 100644 --- a/src/g2_2025_imu_reader_pkg/test/ConfigManager.test.cpp +++ b/src/g2_2025_imu_reader_pkg/test/ConfigManager.test.cpp @@ -26,7 +26,7 @@ static const std::string TEST_CONFIG_NO_POOL_CONTENT = R"( [database] host = "localhost" port = 5432 -dbname = "grades" +dbname = "imu_data" user = "postgres" password = "postgres" )";