feat: Simplify grade handling by removing score scaling logic and updating the API to accept scores directly in a 0-100 range.
This commit is contained in:
@@ -33,6 +33,4 @@ MP_NOTIFICATION_URL=
|
|||||||
# External MySQL Integration
|
# External MySQL Integration
|
||||||
MYSQL_DATABASE_URL=mysql://db_user:db_password@localhost:3306/external_database_name
|
MYSQL_DATABASE_URL=mysql://db_user:db_password@localhost:3306/external_database_name
|
||||||
EXTERNAL_TABLE_GRADES=notas
|
EXTERNAL_TABLE_GRADES=notas
|
||||||
EXTERNAL_GRADE_SCALE_MIN=1
|
|
||||||
EXTERNAL_GRADE_SCALE_MAX=7
|
|
||||||
EXTERNAL_ID_TIPO_NOTA=1
|
EXTERNAL_ID_TIPO_NOTA=1
|
||||||
|
|||||||
@@ -1205,12 +1205,8 @@ pub async fn submit_lesson_score(
|
|||||||
if let Some(id_detalle_contrato) = external_id {
|
if let Some(id_detalle_contrato) = external_id {
|
||||||
let table = env::var("EXTERNAL_TABLE_GRADES").unwrap_or_else(|_| "notas".to_string());
|
let table = env::var("EXTERNAL_TABLE_GRADES").unwrap_or_else(|_| "notas".to_string());
|
||||||
|
|
||||||
// Convert score from 0.0-1.0 to integer scale (1-7 Chilean grades by default)
|
// The external MySQL table uses the exact same 0-100 scale.
|
||||||
let scale_max: f32 = env::var("EXTERNAL_GRADE_SCALE_MAX")
|
let nota = payload.score.round() as i32;
|
||||||
.ok().and_then(|v| v.parse().ok()).unwrap_or(7.0);
|
|
||||||
let scale_min: f32 = env::var("EXTERNAL_GRADE_SCALE_MIN")
|
|
||||||
.ok().and_then(|v| v.parse().ok()).unwrap_or(1.0);
|
|
||||||
let nota = (scale_min + (payload.score * (scale_max - scale_min))).round() as i32;
|
|
||||||
|
|
||||||
// Resolve idTipoNota from the lesson's grading category (tipo_nota_id),
|
// Resolve idTipoNota from the lesson's grading category (tipo_nota_id),
|
||||||
// falling back to the EXTERNAL_ID_TIPO_NOTA env var.
|
// falling back to the EXTERNAL_ID_TIPO_NOTA env var.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub struct GradeSubmissionRequest {
|
|||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
pub course_id: String,
|
pub course_id: String,
|
||||||
pub lesson_id: String,
|
pub lesson_id: String,
|
||||||
/// Puntaje entre 0.0 y 1.0 — se convertirá a la escala local (ej: 1-7)
|
/// Puntaje entre 0 y 100
|
||||||
pub score: f32,
|
pub score: f32,
|
||||||
pub metadata: Option<serde_json::Value>,
|
pub metadata: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
@@ -184,8 +184,8 @@ pub fn enroll_user() {}
|
|||||||
/// localmente en PostgreSQL y se sincroniza automáticamente a MySQL en la tabla `notas`
|
/// localmente en PostgreSQL y se sincroniza automáticamente a MySQL en la tabla `notas`
|
||||||
/// usando el `idDetalleContrato` guardado al momento de la inscripción.
|
/// usando el `idDetalleContrato` guardado al momento de la inscripción.
|
||||||
///
|
///
|
||||||
/// El campo `score` debe estar entre 0.0 y 1.0 — se convertirá a la escala
|
/// El campo `score` debe estar entre 0 y 100 — la nota se insertará
|
||||||
/// entera configurada (por defecto a escala chilena 1–7).
|
/// directamente en la base de datos externa como valor entero.
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
path = "/grades",
|
path = "/grades",
|
||||||
|
|||||||
Reference in New Issue
Block a user