Skip to content

Commit

Permalink
feat: add completed to get judge
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Aug 25, 2024
1 parent faefa72 commit cabd7ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/controller/judge/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ use crate::model::judge::{get_judge_result};
pub async fn auto_judge(Query(query): Query<JudgeRequest>, AdminTokenInfo(admin): AdminTokenInfo) -> Result<String, ErrorMessage> {
info!("Admin {} is judging answer {}", admin.id, query.answer);

let (scores, user, full) = get_judge_result(query.answer, admin.id).await?;
let (scores, user, full, completed) = get_judge_result(query.answer, admin.id).await?;

let response = JudgeResponse {
full,
user,
scores,
completed
};

Ok(serde_json::to_string(&response).unwrap())
Expand All @@ -38,4 +39,5 @@ pub struct JudgeResponse {
pub full: i32,
pub user: i32,
pub scores: HashMap<Uuid, i32>,
pub completed: bool,
}
7 changes: 3 additions & 4 deletions src/model/judge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use sea_orm::{ActiveModelTrait, ColumnTrait, NotSet};
use sea_orm::{EntityTrait, QueryFilter};
use std::collections::HashMap;
use uuid::Uuid;
use crate::model::question::ConditionType::Not;

pub async fn get_judge_result(answer: i32, judge: i64) -> Result<(HashMap<Uuid, i32>, i32, i32), ErrorMessage> {
pub async fn get_judge_result(answer: i32, judge: i64) -> Result<(HashMap<Uuid, i32>, i32, i32, bool), ErrorMessage> {
let score = score::Entity::find()
.filter(score::Column::Id.eq(answer))
.one(&*DATABASE)
Expand All @@ -22,12 +21,12 @@ pub async fn get_judge_result(answer: i32, judge: i64) -> Result<(HashMap<Uuid,
if let Some(res) = score {
let score: HashMap<Uuid, i32> = serde_json::from_value(res.scores).unwrap();

return Ok((score, res.user_score, res.full_score));
return Ok((score, res.user_score, res.full_score, res.completed));
}

let result = auto_judge(answer, judge).await?;

Ok(result)
Ok((result.0, result.1, result.2, false))
}

async fn auto_judge(answer: i32, judge: i64) -> Result<(HashMap<Uuid, i32>, i32, i32), ErrorMessage> {
Expand Down

0 comments on commit cabd7ea

Please sign in to comment.