Skip to content

Commit

Permalink
Peer review cutoff time to database
Browse files Browse the repository at this point in the history
  • Loading branch information
Maija Y committed Nov 10, 2023
1 parent 364f6ce commit 289dd5c
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE peer_review_configs DROP COLUMN manual_review_cutoff_in_days;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE peer_review_configs
ADD COLUMN manual_review_cutoff_in_days INTEGER NOT NULL DEFAULT 21;
COMMENT ON COLUMN peer_review_configs.manual_review_cutoff_in_days IS 'Number of days that needs to pass for the exercise submission to move to manual review';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ mod tests {
peer_reviews_to_receive: 2,
accepting_threshold: 2.1,
accepting_strategy,
manual_review_cutoff_in_days: 21,
}
}

Expand Down
21 changes: 15 additions & 6 deletions services/headless-lms/models/src/peer_review_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct PeerReviewConfig {
pub peer_reviews_to_receive: i32,
pub accepting_threshold: f32,
pub accepting_strategy: PeerReviewAcceptingStrategy,
pub manual_review_cutoff_in_days: i32,
}

/// Like `PeerReviewConfig` but only the fields it's fine to show to all users.
Expand Down Expand Up @@ -157,7 +158,8 @@ SELECT id,
peer_reviews_to_give,
peer_reviews_to_receive,
accepting_threshold,
accepting_strategy AS "accepting_strategy: _"
accepting_strategy AS "accepting_strategy: _",
manual_review_cutoff_in_days
FROM peer_review_configs
WHERE id = $1
AND deleted_at IS NULL
Expand All @@ -173,7 +175,7 @@ WHERE id = $1
pub async fn get_by_exercise_id(
conn: &mut PgConnection,
exercise_id: Uuid,
) -> ModelResult<PeerReviewConfig> {
) -> ModelResult<Option<PeerReviewConfig>> {
let res = sqlx::query_as!(
PeerReviewConfig,
r#"
Expand All @@ -186,14 +188,15 @@ SELECT id,
peer_reviews_to_give,
peer_reviews_to_receive,
accepting_threshold,
accepting_strategy AS "accepting_strategy: _"
accepting_strategy AS "accepting_strategy: _",
manual_review_cutoff_in_days
FROM peer_review_configs
WHERE exercise_id = $1
AND deleted_at IS NULL
"#,
exercise_id
)
.fetch_one(conn)
.fetch_optional(conn)
.await?;
Ok(res)
}
Expand All @@ -207,7 +210,12 @@ pub async fn get_by_exercise_or_course_id(
if exercise.use_course_default_peer_review_config {
get_default_for_course_by_course_id(conn, course_id).await
} else {
get_by_exercise_id(conn, exercise.id).await
let config = get_by_exercise_id(conn, exercise.id).await?;
if let Some(config) = config {
Ok(config)
} else {
get_default_for_course_by_course_id(conn, course_id).await
}
}
}

Expand All @@ -227,7 +235,8 @@ SELECT id,
peer_reviews_to_give,
peer_reviews_to_receive,
accepting_threshold,
accepting_strategy AS "accepting_strategy: _"
accepting_strategy AS "accepting_strategy: _",
manual_review_cutoff_in_days
FROM peer_review_configs
WHERE course_id = $1
AND exercise_id IS NULL
Expand Down
24 changes: 24 additions & 0 deletions services/headless-lms/models/src/peer_review_queue_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,30 @@ WHERE course_instance_id = $1
Ok(res)
}

pub async fn get_entries_that_need_reviews_and_are_older_than_with_exercise_id(
conn: &mut PgConnection,
exercise_id: Uuid,
timestamp: DateTime<Utc>,
) -> ModelResult<Vec<PeerReviewQueueEntry>> {
let res = sqlx::query_as!(
PeerReviewQueueEntry,
"
SELECT *
FROM peer_review_queue_entries
WHERE exercise_id = $1
AND received_enough_peer_reviews = FALSE
AND removed_from_queue_for_unusual_reason = FALSE
AND created_at < $2
AND deleted_at IS NULL
",
exercise_id,
timestamp
)
.fetch_all(&mut *conn)
.await?;
Ok(res)
}

pub async fn remove_from_queue_and_add_to_manual_review(
conn: &mut PgConnection,
peer_review_queue_entry: &PeerReviewQueueEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ fn models() {
peer_reviews_to_receive: 2,
accepting_threshold: 3.0,
accepting_strategy: PeerReviewAcceptingStrategy::AutomaticallyAcceptOrManualReviewByAverage,
manual_review_cutoff_in_days: 21,
});
doc!(
T,
Expand Down
49 changes: 40 additions & 9 deletions services/headless-lms/server/src/programs/peer_review_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,49 @@ pub async fn main() -> anyhow::Result<()> {
let mut moved_to_manual_review = 0;

for course_instance in all_course_instances.iter() {
let should_be_added_to_manual_review = headless_lms_models::peer_review_queue_entries::get_entries_that_need_reviews_and_are_older_than(&mut conn, course_instance.id, manual_review_cutoff).await?;
if should_be_added_to_manual_review.is_empty() {
continue;
}
info!(course_instance_id = ?course_instance.id, "Found {:?} answers that have been added to the peer review queue before {:?} and have not received enough peer reviews or have not been reviewed manually. Adding them to be manually reviewed by the teachers.", should_be_added_to_manual_review.len(), manual_review_cutoff);
for peer_review_queue_entry in should_be_added_to_manual_review {
peer_review_queue_entries::remove_from_queue_and_add_to_manual_review(
//List of exercises in a course instance
let all_exercises_in_course_instance =
headless_lms_models::exercises::get_exercises_by_course_instance_id(
&mut conn,
&peer_review_queue_entry,
course_instance.id,
)
.await?;
moved_to_manual_review += 1

for exercise in all_exercises_in_course_instance.iter() {
if !exercise.needs_peer_review {
continue;
}

let course_id = exercise.course_id;
if course_id.is_some() {
let exercise_config =
headless_lms_models::peer_review_configs::get_by_exercise_or_course_id(
&mut conn,
exercise,
course_id.unwrap(),
)
.await?;

let manual_review_cutoff_in_days = exercise_config.manual_review_cutoff_in_days;

let timestamp = now - chrono::Duration::days(manual_review_cutoff_in_days.into());

let should_be_added_to_manual_review = headless_lms_models::peer_review_queue_entries::get_entries_that_need_reviews_and_are_older_than_with_exercise_id(&mut conn, exercise.id, timestamp).await?;
if should_be_added_to_manual_review.is_empty() {
continue;
}

info!(exercise.id = ?exercise.id, "Found {:?} answers that have been added to the peer review queue before {:?} and have not received enough peer reviews or have not been reviewed manually. Adding them to be manually reviewed by the teachers.", should_be_added_to_manual_review.len(), timestamp);

for peer_review_queue_entry in should_be_added_to_manual_review {
peer_review_queue_entries::remove_from_queue_and_add_to_manual_review(
&mut conn,
&peer_review_queue_entry,
)
.await?;
moved_to_manual_review += 1
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion shared-module/src/bindings.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,8 @@ export function isPeerReviewConfig(obj: unknown): obj is PeerReviewConfig {
typeof typedObj["peer_reviews_to_give"] === "number" &&
typeof typedObj["peer_reviews_to_receive"] === "number" &&
typeof typedObj["accepting_threshold"] === "number" &&
(isPeerReviewAcceptingStrategy(typedObj["accepting_strategy"]) as boolean)
(isPeerReviewAcceptingStrategy(typedObj["accepting_strategy"]) as boolean) &&
typeof typedObj["manual_review_cutoff_in_days"] === "number"
)
}

Expand Down
1 change: 1 addition & 0 deletions shared-module/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ export interface PeerReviewConfig {
peer_reviews_to_receive: number
accepting_threshold: number
accepting_strategy: PeerReviewAcceptingStrategy
manual_review_cutoff_in_days: number
}

export interface PeerReviewSubmission {
Expand Down

0 comments on commit 289dd5c

Please sign in to comment.