Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP identify suspected cheaters #1249

Merged
merged 34 commits into from
May 7, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a8515d1
add migration files for the feature
george-misan Mar 12, 2024
a693be6
[cheater-feature]: update migration files
george-misan Apr 4, 2024
43998a5
[cheater-feature]: update migration files
george-misan Apr 4, 2024
d40c2f8
[cheater-feature]: update migration files
george-misan Apr 4, 2024
c66b946
[cheater-feature]: update migration files
george-misan Apr 4, 2024
3341d1d
[cheater-feature]: update migration files
george-misan Apr 4, 2024
fce9ec2
[cheater-feature]: update migration files
george-misan Apr 4, 2024
ceb852b
[cheater-feature]: update migration files
george-misan Apr 4, 2024
818e1a7
[cheater-feature]: update migration files
george-misan Apr 4, 2024
7cc7d8a
[cheater-feature]: update migration files
george-misan Apr 4, 2024
5047e7f
[cheater-feature]: update migration files
george-misan Apr 4, 2024
5fedc99
[cheater-feature]: update migration files
george-misan Apr 4, 2024
45d75aa
[migration-task]: merge migration into one file
george-misan Apr 4, 2024
d5d9b03
[cheater-feature]: WIP
george-misan Apr 8, 2024
7d58e6d
[cheater-feature]: add cheater_thresholds TABLE
george-misan Apr 9, 2024
e1f3df0
[cheater-feature]: add cheater_thresholds TABLE
george-misan Apr 9, 2024
1cdb94f
stash commit
george-misan Apr 15, 2024
bd6cac2
[cheater-feature]: add function to get total points of student in a c…
george-misan Apr 18, 2024
ff943d9
[cheater-feature]: add function to get total points of student in a c…
george-misan Apr 18, 2024
c74b4b2
[lint-job]: remove unused import
george-misan Apr 21, 2024
7a553e0
[cheater-feature]: add files
george-misan Apr 21, 2024
c3c3420
[cheater-feature]: generate bindings
george-misan Apr 21, 2024
d1a3240
[cheater-feature]: add suspected-cheaters route
george-misan Apr 21, 2024
9101911
[cheater-feature]: update insert route for suspected-cheaters
george-misan Apr 24, 2024
72ef938
[migration-job]: run migration
george-misan Apr 24, 2024
82d5b25
[cleanup]: update and test suspected -cheaters route
george-misan Apr 25, 2024
ef89e6c
[cheater-feature]: update suspected-cheaters route to use average dur…
george-misan Apr 26, 2024
7774e55
[cheater-feature]: update suspected-cheaters route to use average dur…
george-misan Apr 26, 2024
0faa462
[cheater-feature]: update suspected-cheaters route to use average dur…
george-misan Apr 26, 2024
d1ccf99
[migration-job]: update migaration file
george-misan Apr 27, 2024
fae2fdc
[cleanup]: remove unused code
george-misan Apr 27, 2024
387fbad
[cleanup]: remove unused code
george-misan Apr 27, 2024
6c7b340
[cleanup]: remove redundant commment
george-misan Apr 27, 2024
f7d499b
[code-review]: update migration & insert_suspected_cheaters route
george-misan May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions services/headless-lms/models/src/suspected_cheaters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use crate::prelude::*;

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "ts_rs", derive(TS))]
pub struct SuspectedCheaters {
george-misan marked this conversation as resolved.
Show resolved Hide resolved
pub id: Uuid,
pub user_id: Uuid,
pub created_at: DateTime<Utc>,
pub deleted_at: Option<DateTime<Utc>>,
pub updated_at: Option<DateTime<Utc>>,
pub total_duration: u64, // Represented in milliseconds
george-misan marked this conversation as resolved.
Show resolved Hide resolved
pub total_points: f32,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[cfg_attr(feature = "ts_rs", derive(TS))]
pub struct Threshold {
pub id: Uuid,
pub course_id: Option<Uuid>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub deleted_at: Option<DateTime<Utc>>,
pub score_threshold: f32,
pub duration_threshold: Option<u64>,
}

pub async fn insert(
conn: &mut PgConnection,
user_id: Uuid,
total_duration: u64,
score_threshold: f32,
) -> SuspectedCheaters<()> {
sqlx::query!(
"
INSERT INTO suspected_cheaters (
user_id,
total_duration,
total_points
)
VALUES ($1, $2, $3)
",
user_id,
total_duration,
total_points
)
.execute(conn)
.await?;
Ok(())
}

pub async fn insert_threshold(
conn: &mut PgConnection,
user_id: Uuid,
duration: Option<u64>,
points: f32,
) -> SuspectedCheaters<()> {
sqlx::query!(
"
INSERT INTO suspected_cheaters (
user_id,
duration,
points
)
VALUES ($1, $2, $3)
",
user_id,
duration,
points
)
.execute(conn)
.await?;
Ok(())
}

pub async fn delete_suspected_cheaters(
conn: &mut PgConnection,
id: Uuid
) -> ModelResult<String> {
let repsonse = sqlx::query!(
r#"
UPDATE suspected_cheaters
SET deleted_at = now()
WHERE id = $1
RETURNING id
"#,
id
)
.fetch_one(conn)
.await?;
Ok(response.id)
}

pub async fn get_suspected_cheaters_by_id(
conn: &mut PgConnection,
id: Uuid,
) -> ModelResult<SuspectedCheaters> {
let cheaters = sqlx::query_as!(
SuspectedCheaters,
"
SELECT *
FROM suspected_cheaters
WHERE id = $1
AND deleted_at IS NULL;
",
id
)
.fetch_one(conn)
.await?;
Ok(cheaters)
}
Loading