generated from wessel/boilerplate
fix(retakenodes): Fix retake functionality, add Database functions
This commit is contained in:
@@ -7,5 +7,8 @@
|
||||
</node>
|
||||
<node pkg="g2_2025_grade_calculator_pkg" exec="grade_calculator"/>
|
||||
<node pkg="g2_2025_grade_calculator_pkg" exec="retake_grade_determinator"/>
|
||||
<node pkg="g2_2025_grade_calculator_pkg" exec="retake_scheduler"/>
|
||||
<node pkg="g2_2025_grade_calculator_pkg" exec="retake_scheduler">
|
||||
<param name="retake_check_interval_sec" value="30"/>
|
||||
</node>
|
||||
|
||||
</launch>
|
||||
|
||||
@@ -295,4 +295,23 @@ std::vector<StudentCourse> DatabaseManager::get_failed_course_results() {
|
||||
return failed_courses;
|
||||
}
|
||||
|
||||
bool DatabaseManager::update_retake_status(const StudentCourse& sc) {
|
||||
if (!is_connected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
pqxx::work txn(*conn_);
|
||||
txn.exec_params(SQL_UPDATE_RETAKE_STATUS, sc.student_name, sc.course_name);
|
||||
txn.commit();
|
||||
return true;
|
||||
} catch (const pqxx::sql_error &e) {
|
||||
RCLCPP_ERROR(logger_, "[DBS] 'update retake status' failed: %s", e.what());
|
||||
return false;
|
||||
} catch (const std::exception &e) {
|
||||
RCLCPP_ERROR(logger_, "[DBS] database error: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace assignments::one
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
|
||||
int get_final_course_grade(const StudentCourse& sc);
|
||||
std::vector<StudentCourse> get_failed_course_results();
|
||||
bool update_retake_status(const StudentCourse &sc);
|
||||
|
||||
private:
|
||||
rclcpp::Logger logger_;
|
||||
|
||||
@@ -36,6 +36,7 @@ static const std::string SQL_CREATE_COURSE_RESULTS = R"(
|
||||
exam_count INTEGER NOT NULL,
|
||||
final_grade INTEGER NOT NULL,
|
||||
is_retake BOOLEAN DEFAULT FALSE,
|
||||
retake_done BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
)";
|
||||
@@ -64,7 +65,7 @@ static const std::string SQL_SELECT_STUDENT_EXAM_RESULTS = R"(
|
||||
static const std::string SQL_SELECT_FAILED_COURSE_RESULTS = R"(
|
||||
SELECT fcr.student_name, fcr.course_name, fcr.final_grade, fcr.exam_count
|
||||
FROM final_course_results fcr
|
||||
WHERE fcr.final_grade < 55 AND fcr.is_retake = FALSE
|
||||
WHERE fcr.final_grade < 55 AND fcr.retake_done = FALSE
|
||||
)";
|
||||
|
||||
static const std::string SQL_INSERT_EXAM_RESULT = R"(
|
||||
@@ -89,6 +90,12 @@ static const std::string SQL_SELECT_STUDENT_LIST = R"(
|
||||
SELECT COUNT(*) FROM student_enrollments
|
||||
)";
|
||||
|
||||
static const std::string SQL_UPDATE_RETAKE_STATUS = R"(
|
||||
UPDATE final_course_results
|
||||
SET retake_done = TRUE
|
||||
WHERE student_name = $1 AND course_name = $2 AND retake_done = FALSE
|
||||
)";
|
||||
|
||||
static const std::string SQL_INSERT_FINAL_COURSE_RESULT = R"(
|
||||
INSERT INTO final_course_results (student_name, course_name, exam_count, final_grade, is_retake)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
|
||||
@@ -90,6 +90,8 @@ void RetakeGradeDeterminator::grade_calculator_response(
|
||||
RCLCPP_WARN(this->get_logger(), "no database connection");
|
||||
return;
|
||||
}
|
||||
data_map_[studentCourseCombo].clear();
|
||||
db_manager_->update_retake_status(studentCourseCombo);
|
||||
|
||||
auto response = future.get();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user