fix(Config,Database): Remove references to assignment one

This commit is contained in:
2025-11-05 15:50:56 +01:00
parent 523709e349
commit e6123e5702
9 changed files with 33 additions and 64 deletions

View File

@@ -84,7 +84,7 @@ std::vector<std::string> default_config_paths_ = {
#### Default Values and Fallbacks #### Default Values and Fallbacks
- **host**: `"localhost"` - Local database server - **host**: `"localhost"` - Local database server
- **port**: `5432` - Standard PostgreSQL port - **port**: `5432` - Standard PostgreSQL port
- **dbname**: `"grades"` - Application-specific database - **dbname**: `"imu_data"` - Application-specific database
- **user**: `"postgres"` - Default PostgreSQL user - **user**: `"postgres"` - Default PostgreSQL user
- **password**: `"postgres"` - Default PostgreSQL password - **password**: `"postgres"` - Default PostgreSQL password
- **timeout**: `30` seconds - connection timeout - **timeout**: `30` seconds - connection timeout
@@ -121,7 +121,7 @@ Example complete TOML configuration:
[database] [database]
host = "localhost" host = "localhost"
port = 5432 port = 5432
dbname = "grades" dbname = "imu_data"
user = "postgres" user = "postgres"
password = "postgres" password = "postgres"
timeout = 30 timeout = 30

View File

@@ -1,9 +1,9 @@
# DatabaseManager (`assignments::one::DatabaseManager`) # DatabaseManager (`assignments::two::DatabaseManager`)
## Overview ## Overview
The `DatabaseManager` class is a PostgreSQL database interface for the ROS2 grade calculator. 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 insertion. It handles all database operations including connection management, table creation and data storage.
## Implementation Details ## Implementation Details
@@ -28,7 +28,7 @@ DatabaseManager(rclcpp::Logger logger)
> Returns `true` on successful connection, `false` on failure > Returns `true` on successful connection, `false` on failure
- Establishes connection to PostgreSQL database using connection information from the config TOML - 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`** **`bool is_connected() const`**
> Returns `true` if connection exists and is open > Returns `true` if connection exists and is open
@@ -47,56 +47,25 @@ DatabaseManager(rclcpp::Logger logger)
**`void create_tables()`** **`void create_tables()`**
- Creates all required database tables using SQL queries from `SQLQueries.hpp` - Creates all required database tables using SQL queries from `SQLQueries.hpp`
- Tables created: - Tables created:
- `enrollments`: Student course enrollments - `imu_data`: IMU sensor readings with linear acceleration and angular velocity data
- `exam_results`: Individual exam scores
- `course_results`: Final course grades and statistics
- Uses transactions for atomic table creation - Uses transactions for atomic table creation
**`void insert_sample_data()`**
- Inserts predefined sample student data
### Data Operations ### Data Operations
#### Student Course Management #### IMU Data Storage
**`std::vector<StudentCourse> queue_pending_combinations()`** **`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 vector of StudentCourse objects for processing queue > Returns `true` on successful storage, `false` on failure
- Gets all student-course combinations that need exam results generated - Stores IMU sensor readings in the database
- 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
- Parameters: - Parameters:
- `student_name`: Name of the student - `linear_accel_x`: Linear acceleration on X-axis
- `course_name`: Name of the course - `linear_accel_y`: Linear acceleration on Y-axis
- `grade`: Exam score (10-100) - `linear_accel_z`: Linear acceleration on Z-axis
- `angular_vel_x`: Angular velocity around X-axis
**`bool store_final_course_result(const StudentCourse& sc, int exam_count, int final_grade)`** - `angular_vel_y`: Angular velocity around Y-axis
- Stores calculated final course results - `angular_vel_z`: Angular velocity around Z-axis
- Parameters: - Automatically adds timestamp on insertion
- `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
### Logging ### Logging
@@ -117,9 +86,9 @@ DatabaseManager db_manager(node->get_logger());
// Check connection status // Check connection status
if (db_manager.is_connected()) { if (db_manager.is_connected()) {
// Database ready for operations // 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) { if (success) {
RCLCPP_INFO(logger, "Exam result stored successfully"); RCLCPP_INFO(logger, "IMU data stored successfully");
} }
} }
``` ```

View File

@@ -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 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 ```bash
ros2 launch g2_2025_imu_reader_pkg imu_reader.launch.xml ros2 launch g2_2025_imu_reader_pkg imu_reader.launch.xml
``` ```

View File

@@ -61,7 +61,7 @@ Unit tests for `ConfigManager` are implemented in `src/g2_2025_imu_reader_pkg/te
[database] [database]
host = "localhost" host = "localhost"
port = 5432 port = 5432
dbname = "grades" dbname = "imu_data"
user = "postgres" user = "postgres"
password = "postgres" password = "postgres"
``` ```

View File

@@ -18,16 +18,16 @@ Unit tests for `DatabaseManager` are implemented in `src/g2_2025_imu_reader_pkg/
- **Test Action:** Call `is_connected()` method - **Test Action:** Call `is_connected()` method
- **Expected Result:** Returns either `true` or `false` (no crashes or invalid states) - **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. - **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. - **Expected Result:** Returns `false` and does not throw — method must check connection status before DB operations
### 4. CreateTablesNoCrash ### 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. - **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. - **Expected Result:** No exception thrown; the function should be a no-op when no DB connection exists

View File

@@ -7,7 +7,7 @@ services:
environment: environment:
- POSTGRES_PASSWORD=postgres - POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres - POSTGRES_USER=postgres
- POSTGRES_DB=grades - POSTGRES_DB=imu_data
ports: ports:
- "5432:5432" - "5432:5432"
mosquitto: mosquitto:

View File

@@ -1,7 +1,7 @@
[database] [database]
host = "localhost" host = "localhost"
port = 5432 port = 5432
dbname = "grades" dbname = "imu_data"
user = "postgres" user = "postgres"
password = "postgres" password = "postgres"
timeout = 30 timeout = 30

View File

@@ -83,7 +83,7 @@ DatabaseConfig ConfigManager::parse_database_config(const toml::table& config) c
db_config.host = database_section["host"].value_or<std::string>("localhost"); db_config.host = database_section["host"].value_or<std::string>("localhost");
db_config.port = database_section["port"].value_or<int>(5432); db_config.port = database_section["port"].value_or<int>(5432);
db_config.dbname = database_section["dbname"].value_or<std::string>("grades"); db_config.dbname = database_section["dbname"].value_or<std::string>("imu_data");
db_config.user = database_section["user"].value_or<std::string>("postgres"); db_config.user = database_section["user"].value_or<std::string>("postgres");
db_config.password = database_section["password"].value_or<std::string>("postgres"); db_config.password = database_section["password"].value_or<std::string>("postgres");
db_config.timeout = database_section["timeout"].value_or<int>(30); db_config.timeout = database_section["timeout"].value_or<int>(30);

View File

@@ -26,7 +26,7 @@ static const std::string TEST_CONFIG_NO_POOL_CONTENT = R"(
[database] [database]
host = "localhost" host = "localhost"
port = 5432 port = 5432
dbname = "grades" dbname = "imu_data"
user = "postgres" user = "postgres"
password = "postgres" password = "postgres"
)"; )";