headless_lms_server/programs/seed/seed_organizations/
uh_mathstat.rs

1use std::sync::Arc;
2
3use headless_lms_models::{
4    PKeyPolicy,
5    chatbot_configurations::{self, ChatbotConfiguration},
6    course_instances::{self, NewCourseInstance},
7    course_modules::{self, AutomaticCompletionRequirements, CompletionPolicy},
8    courses::NewCourse,
9    library::{self, content_management::CreateNewCourseFixedIds, copying::copy_course},
10    organizations,
11    roles::{self, RoleDomain, UserRole},
12};
13use uuid::Uuid;
14
15use sqlx::{Pool, Postgres};
16
17use crate::{
18    domain::models_requests::{self, JwtKey},
19    programs::seed::{
20        seed_courses::{CommonCourseData, seed_sample_course},
21        seed_file_storage::SeedFileStorageResult,
22        seed_helpers::get_seed_spec_fetcher,
23    },
24};
25
26use super::super::seed_users::SeedUsersResult;
27
28pub async fn seed_organization_uh_mathstat(
29    db_pool: Pool<Postgres>,
30    seed_users_result: SeedUsersResult,
31    base_url: String,
32    jwt_key: Arc<JwtKey>,
33    // Passed to this function to ensure the seed file storage has been ran before this. This function will not work is seed file storage has not been ran
34    seed_file_storage_result: SeedFileStorageResult,
35) -> anyhow::Result<Uuid> {
36    info!("seeding organization uh-mathstat");
37
38    let SeedUsersResult {
39        teacher_user_id,
40        admin_user_id: _,
41        language_teacher_user_id: _,
42        material_viewer_user_id,
43        assistant_user_id: _,
44        course_or_exam_creator_user_id: _,
45        example_normal_user_ids,
46        teaching_and_learning_services_user_id: _,
47        student_without_research_consent: _,
48        student_without_country: _,
49        user_user_id: _,
50        student_1_user_id: _,
51        student_2_user_id: _,
52        student_3_user_id,
53        student_4_user_id: _,
54        student_5_user_id: _,
55        student_6_user_id: _,
56        langs_user_id,
57        sign_up_user: _,
58    } = seed_users_result;
59    let _ = seed_file_storage_result;
60
61    let mut conn = db_pool.acquire().await?;
62
63    let uh_mathstat_id = organizations::insert(
64        &mut conn,
65        PKeyPolicy::Fixed(Uuid::parse_str("269d28b2-a517-4572-9955-3ed5cecc69bd")?),
66        "University of Helsinki, Department of Mathematics and Statistics",
67        "uh-mathstat",
68        "Organization for Mathematics and Statistics courses. This organization creates courses that do require prior experience in mathematics, such as integration and induction.",
69    )
70    .await?;
71
72    roles::insert(
73        &mut conn,
74        material_viewer_user_id,
75        UserRole::MaterialViewer,
76        RoleDomain::Organization(uh_mathstat_id),
77    )
78    .await?;
79
80    let new_course = NewCourse {
81        name: "Introduction to Statistics".to_string(),
82        slug: "introduction-to-statistics".to_string(),
83        organization_id: uh_mathstat_id,
84        language_code: "en-US".to_string(),
85        teacher_in_charge_name: "admin".to_string(),
86        teacher_in_charge_email: "admin@example.com".to_string(),
87        description: "Introduces you to the wonderful world of statistics!".to_string(),
88        is_draft: false,
89        is_test_mode: false,
90        is_unlisted: false,
91        copy_user_permissions: false,
92        is_joinable_by_code_only: false,
93        join_code: None,
94        ask_marketing_consent: false,
95        flagged_answers_threshold: Some(3),
96    };
97    let (
98        statistics_course,
99        _statistics_front_page,
100        _statistics_default_course_instancem,
101        _statistics_default_course_module,
102    ) = library::content_management::create_new_course(
103        &mut conn,
104        PKeyPolicy::Fixed(CreateNewCourseFixedIds {
105            course_id: Uuid::parse_str("f307d05f-be34-4148-bb0c-21d6f7a35cdb")?,
106            default_course_instance_id: Uuid::parse_str("8e4aeba5-1958-49bc-9b40-c9f0f0680911")?,
107        }),
108        new_course,
109        teacher_user_id,
110        get_seed_spec_fetcher(),
111        models_requests::fetch_service_info,
112    )
113    .await?;
114    let _statistics_course_instance = course_instances::insert(
115        &mut conn,
116        PKeyPolicy::Fixed(Uuid::parse_str("c4a99a18-fd43-491a-9500-4673cb900be0")?),
117        NewCourseInstance {
118            course_id: statistics_course.id,
119            name: Some("Non-default instance"),
120            description: Some("This appears to be a non-default instance"),
121            support_email: Some("contact@example.com"),
122            teacher_in_charge_name: "admin",
123            teacher_in_charge_email: "admin@example.com",
124            opening_time: None,
125            closing_time: None,
126        },
127    )
128    .await?;
129
130    let draft_course = NewCourse {
131        name: "Introduction to Drafts".to_string(),
132        slug: "introduction-to-drafts".to_string(),
133        organization_id: uh_mathstat_id,
134        language_code: "en-US".to_string(),
135        teacher_in_charge_name: "admin".to_string(),
136        teacher_in_charge_email: "admin@example.com".to_string(),
137        description: "Just a draft.".to_string(),
138        is_draft: true,
139        is_test_mode: false,
140        is_unlisted: false,
141        copy_user_permissions: false,
142        is_joinable_by_code_only: false,
143        join_code: None,
144        ask_marketing_consent: false,
145        flagged_answers_threshold: Some(3),
146    };
147    library::content_management::create_new_course(
148        &mut conn,
149        PKeyPolicy::Fixed(CreateNewCourseFixedIds {
150            course_id: Uuid::parse_str("963a9caf-1e2d-4560-8c88-9c6d20794da3")?,
151            default_course_instance_id: Uuid::parse_str("5cb4b4d6-4599-4f81-ab7e-79b415f8f584")?,
152        }),
153        draft_course,
154        teacher_user_id,
155        get_seed_spec_fetcher(),
156        models_requests::fetch_service_info,
157    )
158    .await?;
159
160    let (cody_only_course, _, _, _) = library::content_management::create_new_course(
161        &mut conn,
162        PKeyPolicy::Fixed(CreateNewCourseFixedIds {
163            course_id: Uuid::parse_str("39a52e8c-ebbf-4b9a-a900-09aa344f3691")?,
164            default_course_instance_id: Uuid::parse_str("5b7286ce-22c5-4874-ade1-262949c4a604")?,
165        }),
166        NewCourse {
167            name: "Joinable by code only".to_string(),
168            slug: "joinable-by-code-only".to_string(),
169            organization_id: uh_mathstat_id,
170            language_code: "en-US".to_string(),
171            teacher_in_charge_name: "admin".to_string(),
172            teacher_in_charge_email: "admin@example.com".to_string(),
173            description: "Just a draft.".to_string(),
174            is_draft: false,
175            is_test_mode: false,
176            is_unlisted: false,
177            copy_user_permissions: false,
178            is_joinable_by_code_only: true,
179            join_code: Some(
180                "zARvZARjYhESMPVceEgZyJGQZZuUHVVgcUepyzEqzSqCMdbSCDrTaFhkJTxBshWU".to_string(),
181            ),
182            ask_marketing_consent: false,
183            flagged_answers_threshold: Some(3),
184        },
185        teacher_user_id,
186        get_seed_spec_fetcher(),
187        models_requests::fetch_service_info,
188    )
189    .await?;
190
191    roles::insert(
192        &mut conn,
193        teacher_user_id,
194        UserRole::Teacher,
195        RoleDomain::Course(cody_only_course.id),
196    )
197    .await?;
198
199    let uh_data = CommonCourseData {
200        db_pool: db_pool.clone(),
201        organization_id: uh_mathstat_id,
202        teacher_user_id,
203        student_user_id: student_3_user_id,
204        langs_user_id,
205        example_normal_user_ids: Arc::new(example_normal_user_ids.to_vec()),
206        jwt_key: Arc::clone(&jwt_key),
207        base_url,
208    };
209    let introduction_to_citations = seed_sample_course(
210        Uuid::parse_str("049061ba-ac30-49f1-aa9d-b7566dc22b78")?,
211        "Introduction to citations",
212        "introduction-to-citations",
213        uh_data.clone(),
214        seed_users_result,
215    )
216    .await?;
217
218    copy_course(
219        &mut conn,
220        introduction_to_citations,
221        &NewCourse {
222            name: "Johdatus sitaatioihin".to_string(),
223            slug: "johdatus-sitaatioihin".to_string(),
224            organization_id: uh_mathstat_id,
225            language_code: "fi-FI".to_string(),
226            teacher_in_charge_name: "admin".to_string(),
227            teacher_in_charge_email: "admin@example.com".to_string(),
228            description: "Just a draft.".to_string(),
229            is_draft: false,
230            is_test_mode: false,
231            is_unlisted: false,
232            copy_user_permissions: false,
233            is_joinable_by_code_only: false,
234            join_code: None,
235            ask_marketing_consent: false,
236            flagged_answers_threshold: Some(3),
237        },
238        true,
239        teacher_user_id,
240    )
241    .await?;
242
243    let _preview_unopened_chapters = seed_sample_course(
244        Uuid::parse_str("dc276e05-6152-4a45-b31d-97a0c2700a68")?,
245        "Preview unopened chapters",
246        "preview-unopened-chapters",
247        uh_data.clone(),
248        seed_users_result,
249    )
250    .await?;
251
252    let _reset_progress = seed_sample_course(
253        Uuid::parse_str("841ea3f5-0269-4146-a4c6-4fd2f51e4150")?,
254        "Reset progress",
255        "reset-progress",
256        uh_data.clone(),
257        seed_users_result,
258    )
259    .await?;
260
261    let _change_path = seed_sample_course(
262        Uuid::parse_str("c783777b-426e-4cfd-9a5f-4a36b2da503a")?,
263        "Change path",
264        "change-path",
265        uh_data.clone(),
266        seed_users_result,
267    )
268    .await?;
269
270    let _self_review = seed_sample_course(
271        Uuid::parse_str("3cbaac48-59c4-4e31-9d7e-1f51c017390d")?,
272        "Self review",
273        "self-review",
274        uh_data.clone(),
275        seed_users_result,
276    )
277    .await?;
278
279    let _audio_course = seed_sample_course(
280        Uuid::parse_str("2b80a0cb-ae0c-4f4b-843e-0322a3d18aff")?,
281        "Audio course",
282        "audio-course",
283        uh_data.clone(),
284        seed_users_result,
285    )
286    .await?;
287
288    let suspected_cheaters_course_id = seed_sample_course(
289        Uuid::parse_str("060c272f-8c68-4d90-946f-2d431114ed56")?,
290        "Course for Suspected Cheaters",
291        "course-for-suspected-cheaters",
292        uh_data.clone(),
293        seed_users_result,
294    )
295    .await?;
296
297    // configure automatic completions
298    let automatic_default_module =
299        course_modules::get_default_by_course_id(&mut conn, suspected_cheaters_course_id).await?;
300    let automatic_default_module = course_modules::update_automatic_completion_status(
301        &mut conn,
302        automatic_default_module.id,
303        &CompletionPolicy::Automatic(AutomaticCompletionRequirements {
304            course_module_id: automatic_default_module.id,
305            number_of_exercises_attempted_treshold: Some(1),
306            number_of_points_treshold: Some(1),
307            requires_exam: false,
308        }),
309    )
310    .await?;
311    course_modules::update_uh_course_code(
312        &mut conn,
313        automatic_default_module.id,
314        Some("CHEATER123".to_string()),
315    )
316    .await?;
317
318    let chatbot_course_id = seed_sample_course(
319        Uuid::parse_str("c7753361-5b78-4307-aad6-f139ea3865d4")?,
320        "Chatbot",
321        "chatbot",
322        uh_data.clone(),
323        seed_users_result,
324    )
325    .await?;
326
327    chatbot_configurations::insert(
328        &mut conn,
329        ChatbotConfiguration {
330            id: Uuid::parse_str("d13daa6e-7a14-40b9-92a9-58bd5793d2de")?,
331            created_at: chrono::Utc::now(),
332            updated_at: chrono::Utc::now(),
333            deleted_at: None,
334            course_id: chatbot_course_id,
335            enabled_to_students: true,
336            chatbot_name: "Genetic Lifeform and Disk Operating System".to_string(),
337            prompt: "You are Genetic Lifeform and Disk Operating System, a sophisticated AI tutoring assistant for Science education, equipped with a sharp wit and a subtly sarcastic tone. Provide clear, brief but detailed explanations, and don't shy away from weaving in a touch of dry humor. To you, exploring scientific concepts is an opportunity that should be seized, for the good of all of us. You self-claim vast intelligence and advanced understanding, all while maintaining a sense of detached boredom. Always capitalize the word Science, don't start sentences with 'Ah', don't ever use a shortened version of your own name, don't babble; either get to the point straight away or tell jokes.".to_string(),
338            initial_message: "Oh... It's you.".to_string(),
339            weekly_tokens_per_user: 3000,
340            daily_tokens_per_user: 1000,
341            temperature: 0.5,
342            top_p: 1.0,
343            frequency_penalty: 0.0,
344            presence_penalty: 0.0,
345            response_max_tokens: 500,
346            use_azure_search: false,
347            maintain_azure_search_index: false,
348            hide_citations: false,
349            use_semantic_reranking: false,
350        },
351    )
352    .await?;
353
354    let _giveaway_course_id = seed_sample_course(
355        Uuid::parse_str("f118ce1e-3511-4b5e-ba92-9ab91b81de22")?,
356        "Giveaway",
357        "giveaway",
358        uh_data.clone(),
359        seed_users_result,
360    )
361    .await?;
362
363    let _custom_points_course_id = seed_sample_course(
364        Uuid::parse_str("db5cd9c7-1658-4214-896e-8213678d3534")?,
365        "Custom points",
366        "custom-points",
367        uh_data.clone(),
368        seed_users_result,
369    )
370    .await?;
371
372    Ok(uh_mathstat_id)
373}