diff --git a/api/schema/classroom_compliance.sql b/api/schema/classroom_compliance.sql index 1e20a4c..f9fee75 100644 --- a/api/schema/classroom_compliance.sql +++ b/api/schema/classroom_compliance.sql @@ -6,7 +6,7 @@ CREATE TABLE classroom_compliance_class ( user_id BIGINT NOT NULL REFERENCES auth_user(id) ON UPDATE CASCADE ON DELETE CASCADE, - score_expression VARCHAR(255) NOT NULL DEFAULT '0.3 * phone + 0.7 * (behavior_good * 1 + behavior_mediocre * 0.5)', + score_expression VARCHAR(255) NOT NULL DEFAULT '0.5 * phone + 0.5 * behavior', score_period VARCHAR(64) NOT NULL DEFAULT 'week', CONSTRAINT unique_class_numbers_per_school_year UNIQUE(number, school_year, user_id) diff --git a/api/source/sample_data.d b/api/source/sample_data.d index b2e81a6..7cde680 100644 --- a/api/source/sample_data.d +++ b/api/source/sample_data.d @@ -51,6 +51,12 @@ void insertSampleData() { ulong adminUserId = addUser(conn, "test", "test", false, true); ulong normalUserId = addUser(conn, "test2", "test", false, false); Random rand = Random(0); + addClassroomComplianceSampleData(rand, adminUserId, conn); + addClassroomComplianceSampleData(rand, normalUserId, conn); + info("Inserted sample data."); +} + +void addClassroomComplianceSampleData(ref Random rand, ulong adminUserId, Connection conn) { const SysTime now = Clock.currTime(); const Date today = Date(now.year, now.month, now.day); @@ -80,14 +86,15 @@ void insertSampleData() { if (uniform01(rand) < 0.25) { behaviorRating = 2; if (uniform01(rand) < 0.5) { - behaviorRating = 3; + behaviorRating = 1; } } - addEntry(conn, classId, studentId, entryDate, absent, phoneCompliant, behaviorRating); + bool hasComment = uniform01(rand) < 0.2; + string comment = hasComment ? "Test comment." : ""; + addEntry(conn, classId, studentId, entryDate, absent, phoneCompliant, behaviorRating, comment); } } } - info("Inserted sample data."); } ulong addUser(Connection conn, string username, string password, bool locked, bool admin) { @@ -125,7 +132,8 @@ void addEntry( Date date, bool absent, bool phoneCompliant, - ubyte behaviorRating + ubyte behaviorRating, + string comment ) { const entryQuery = " INSERT INTO classroom_compliance_entry @@ -137,7 +145,11 @@ void addEntry( ps.setUlong(2, studentId); ps.setDate(3, date); ps.setBoolean(4, absent); - ps.setString(5, "Testing comment"); + if (comment is null) { + ps.setString(5, ""); + } else { + ps.setString(5, comment); + } if (absent) { ps.setNull(6); ps.setNull(7);