-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataGenerator.py
More file actions
1376 lines (1232 loc) · 59.2 KB
/
Copy pathdataGenerator.py
File metadata and controls
1376 lines (1232 loc) · 59.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import random
from faker import Faker
from datetime import datetime, timedelta, time
faker = Faker()
Faker.seed(2137)
# ==============================================================================
# CONFIG CONSTANTS
# ==============================================================================
# =============== USER/EMPLOYEE
NUM_USERTYPES = 3
NUM_LOCATIONS = 23
NUM_LANGUAGES = 5
NUM_DEGREES = 5
NUM_USERS = 1500 # total
NUM_USERCONTACT = 1500
NUM_USERADDRESS = 1200
NUM_EMPLOYEES = 100 # subset of users
NUM_STUDENTS = 1400 # subset of users
NUM_TRANSLATORS = 8 # subset of employees
MIN_EMPLOYEE_SUPERIORS = 0
# =============== COLLEGE/ACADEMIC
NUM_GRADES = 6
NUM_STUDIES = 15
NUM_SUBJECTS = 40
MIN_SEMESTERS_PER_STUDY = 4
MAX_SEMESTERS_PER_STUDY = 7
MIN_SUBJECTS_PER_STUDY = 5
MAX_SUBJECTS_PER_STUDY = 20
NUM_INTERNSHIPS = 4
NUM_INTERNSHIP_DETAILS = 8
MIN_CLASSMEETINGS_PER_SUBJECT = 5
MAX_CLASSMEETINGS_PER_SUBJECT = 20
NUM_ATONEMENTS = 0
NUM_SUBJECT_DETAILS_PER_SUBJECT = 30
MIN_CONVENTIONS_PER_SEMESTER = 4
MAX_CONVENTIONS_PER_SEMESTER = 10
# =============== PAYMENTS
# NUM_SERVICES = 12
NUM_ORDERS = 750
MIN_SERVICES_PER_ORDER = 1
MAX_SERVICES_PER_ORDER = 3
NUM_PAYMENTS = 2000
# ==============================================================================
# HELPER FUNCTIONS
# ==============================================================================
def quote_str(s: str) -> str:
"""Escape single quotes for SQL."""
if s is None:
return ""
return s.replace("'", "''")
def format_date(d) -> str:
"""Format a datetime/date as 'YYYY-MM-DD', or 'NULL' if None."""
if d is None:
return "NULL"
if isinstance(d, datetime):
return d.strftime("'%Y-%m-%d'")
return f"'{d}'"
def format_datetime(dt) -> str:
"""Format a datetime as 'YYYY-MM-DD HH:MM:SS', or 'NULL' if None."""
if dt is None:
return "NULL"
return f"'{dt.strftime('%Y-%m-%d %H:%M:%S')}'"
def random_date_between(start_days=-365, end_days=365):
start_date = datetime.now() + timedelta(days=start_days)
end_date = datetime.now() + timedelta(days=end_days)
return faker.date_between(start_date=start_date, end_date=end_date)
def format_money(val) -> str:
"""Format a float as a numeric or money type. Adjust if your DB syntax differs."""
return f"{val:.2f}"
room_schedule_records = []
room_details_records = []
# ==============================================================================
# 1) USERTYPE
# ==============================================================================
fixed_user_types = [
(1, "Student"),
(2, "Lecturer"),
(3, "Translator")
]
user_type_records = []
for (tid, tname) in fixed_user_types[:NUM_USERTYPES]:
user_type_records.append({
'UserTypeID': tid,
'UserTypeName': tname
})
user_type_permissions = []
user_type_permissions.append({
'UserTypeID': 3,
'DirectTypeSupervisor': 2
})
# ==============================================================================
# 2) LOCATIONS
# ==============================================================================
location_records = []
for i in range(1, NUM_LOCATIONS+1):
location_records.append({
'LocationID': i,
'CountryName': faker.country(),
'ProvinceName': faker.state(),
'CityName': faker.city()
})
# ==============================================================================
# 3) LANGUAGES
# ==============================================================================
language_records = []
for i in range(1, NUM_LANGUAGES+1):
language_records.append({
'LanguageID': i,
'LanguageName': faker.language_name()
})
# ==============================================================================
# 4) DEGREES
# ==============================================================================
possible_degrees = [
(1, "Bachelor", "BSc Something"),
(2, "Masters", "MSc Something"),
(3, "PhD", "PhD Something"),
(4, "Prof", "Professor Something")
]
degree_records = []
for (did, lvl, nm) in possible_degrees[:NUM_DEGREES]:
degree_records.append({
'DegreeID': did,
'DegreeLevel': lvl,
'DegreeName': nm
})
# ==============================================================================
# 5) GRADES (for StudiesDetails, InternshipDetails, etc.)
# ==============================================================================
grade_list = [
(1, 2.0, "Sufficient"),
(2, 3.0, "Fair"),
(3, 3.5, "Satisfactory"),
(4, 4.0, "Good"),
(5, 4.5, "Very Good"),
(6, 5.0, "Excellent"),
]
grade_records = []
for (gid, val, name) in grade_list[:NUM_GRADES]:
grade_records.append({
'GradeID': gid,
'GradeValue': val,
'GradeName': name
})
# ==============================================================================
# 6) CREATE USERS
# ==============================================================================
all_user_ids = list(range(1, NUM_USERS+1))
random.shuffle(all_user_ids)
student_user_ids = all_user_ids[:NUM_STUDENTS] #zaklada sie ze students rozlaczne z employees chyba tutaj
rest_ids = all_user_ids[NUM_STUDENTS:]
employee_user_ids = rest_ids[:NUM_EMPLOYEES]
rest_ids = rest_ids[NUM_EMPLOYEES:]
user_records = []
# STUDENT TYPE=1
for uid in student_user_ids:
user_records.append({
'UserID': uid,
'FirstName': faker.first_name(),
'LastName': faker.last_name(),
'DateOfBirth': faker.date_of_birth(minimum_age=18, maximum_age=30),
'UserTypeID': 1
})
# EMPLOYEES TYPE in [2,3]
employee_type_ids = [2,3]
for uid in employee_user_ids:
chosen_type = random.choice(employee_type_ids)
user_records.append({
'UserID': uid,
'FirstName': faker.first_name(),
'LastName': faker.last_name(),
'DateOfBirth': faker.date_of_birth(minimum_age=25, maximum_age=60),
'UserTypeID': chosen_type
})
# The leftover
for uid in rest_ids:
random_type = 2
user_records.append({
'UserID': uid,
'FirstName': faker.first_name(),
'LastName': faker.last_name(),
'DateOfBirth': faker.date_of_birth(minimum_age=18, maximum_age=60),
'UserTypeID': random_type
})
# ==============================================================================
# 7) USERCONTACT
# ==============================================================================
user_contact_records = []
random_ids_for_contact = random.sample(all_user_ids, k=min(NUM_USERCONTACT, len(all_user_ids)))
for uid in random_ids_for_contact:
user_contact_records.append({
'UserID': uid,
'Email': faker.email(),
'Phone': faker.phone_number()
})
# ==============================================================================
# 8) USERADDRESSDETAILS
# ==============================================================================
user_address_records = []
a_users_ids = [u['UserID'] for u in user_records]
for uid in a_users_ids:
loc = random.choice(location_records)
user_address_records.append({
'UserID': uid,
'Address': faker.street_address()[:30],
'PostalCode': faker.postcode()[:10],
'LocationID': loc['LocationID']
})
# ==============================================================================
# 9) EMPLOYEES (UserType in [2,3])
# ==============================================================================
employee_records = []
for u in user_records:
if u['UserTypeID'] in [2,3]:
employee_records.append({
'EmployeeID': u['UserID'],
'DateOfHire': faker.date_between(start_date='-10y', end_date='today')
})
# ==============================================================================
# 10) EMPLOYEESUPERIOR
# ==============================================================================
employees_superior_records = []
if len(employee_records) > 1:
for e in employee_records:
if random.choice([True, False]):
possible_superiors = [x for x in employee_records if x['EmployeeID'] != e['EmployeeID']]
if possible_superiors:
sup = random.choice(possible_superiors)
employees_superior_records.append({
'EmployeeID': e['EmployeeID'],
'ReportsTo': sup['EmployeeID']
})
# ==============================================================================
# 11) TRANSLATORS
# ==============================================================================
translator_records = []
trans_emps = [e for e in employee_records
if next(u for u in user_records if u['UserID'] == e['EmployeeID'])['UserTypeID'] == 3]
chosen_trans = random.sample(trans_emps, k=min(NUM_TRANSLATORS, len(trans_emps)))
for ct in chosen_trans:
translator_records.append({
'TranslatorID': ct['EmployeeID']
})
# 11b) TRANSLATORS LANGUAGES
translators_languages_records = []
for tr in translator_records:
how_many_langs = random.randint(1, len(language_records))
chosen_langs = random.sample(language_records, k=how_many_langs)
for cl in chosen_langs:
translators_languages_records.append({
'TranslatorID': tr['TranslatorID'],
'LanguageID': cl['LanguageID']
})
# ==============================================================================
# 12) EMPLOYEEDEGREE
# ==============================================================================
employee_degree_records = []
for e in employee_records:
how_many_degs = random.choice([0, 1, 1, 1, 1])
if how_many_degs > 0:
deg = random.choice(degree_records)
employee_degree_records.append({
'EmployeeID': e['EmployeeID'],
'DegreeID': deg['DegreeID']
})
# ==============================================================================
# 13) SERVICEUSERDETAILS + STUDENT (College logic)
# ==============================================================================
service_user_details_records = []
student_coll_records = []
for u in user_records:
if u['UserTypeID'] == 1: # student
service_user_details_records.append({
'ServiceUserID': u['UserID'],
'DateOfRegistration': faker.date_between(start_date='-4y', end_date='today')
})
student_coll_records.append({
'StudentID': u['UserID'],
'FirstName': u['FirstName'],
'LastName': u['LastName'],
'DateOfBirth': u['DateOfBirth']
})
# ==============================================================================
# 14) STUDIES
# ==============================================================================
possible_coordinator_emps = [e for e in employee_records
if next(u for u in user_records if u['UserID']==e['EmployeeID'])['UserTypeID'] in [2,4]]
studies_records = []
for i in range(1, NUM_STUDIES+1):
coordinator = random.choice(possible_coordinator_emps) if possible_coordinator_emps else None
enrollment_deadline_dt = faker.date_between(start_date='-3y', end_date='+1y')
grad_dt = enrollment_deadline_dt + timedelta(days=365*random.randint(2,4))
su = random.choice(service_user_details_records) if service_user_details_records else None
studies_records.append({
'StudiesID': i,
'StudiesName': faker.word().title() + " Studies",
'StudiesDescription': faker.sentence(nb_words=5),
'StudiesCoordinatorID': coordinator['EmployeeID'] if coordinator else 'NULL',
'EnrollmentLimit': random.randint(10,50),
'EnrollmentDeadline': enrollment_deadline_dt,
'ExpectedGraduationDate': grad_dt,
'ServiceID': su['ServiceUserID'] if su else 1
})
# ==============================================================================
# 15) SEMESTERDETAILS
# ==============================================================================
semester_records = []
next_sem_id = 1
for st in studies_records:
study_id = st['StudiesID']
num_sem = (st['ExpectedGraduationDate'] - st['EnrollmentDeadline']).days // 365
base_dt = st['EnrollmentDeadline']
if not isinstance(base_dt, datetime):
base_dt = datetime.strptime(str(base_dt), '%Y-%m-%d')
for _ in range(num_sem):
sem_start_offset = random.randint(-90, 90)
sem_start_dt = base_dt + timedelta(days=sem_start_offset)
sem_end_dt = sem_start_dt + timedelta(days=120)
semester_records.append({
'SemesterID': next_sem_id,
'StudiesID': study_id,
'StartDate': sem_start_dt,
'EndDate': sem_end_dt
})
next_sem_id += 1
base_dt = sem_end_dt + timedelta(days=20)
# ==============================================================================
# 16) SUBJECT
# ==============================================================================
possible_subject_coordinators = employee_records
subject_records = []
for i in range(1, NUM_SUBJECTS+1):
coord_emp = random.choice(possible_subject_coordinators) if possible_subject_coordinators else None
su = random.choice(service_user_details_records) if service_user_details_records else None
studies_id = random.choice(studies_records)['StudiesID']
subject_records.append({
'SubjectID': i,
'StudiesID': studies_id,
'SubjectName': faker.word().capitalize(),
'SubjectCoordinatorID': coord_emp['EmployeeID'] if coord_emp else 'NULL',
'SubjectDescription': faker.sentence(nb_words=5),
'ServiceID': su['ServiceUserID'] if su else 1,
'Meetings': random.randint(5,15)
})
# ==============================================================================
# 17) SUBJECTTOSTUDIESASSIGNMENT
# ==============================================================================
# We'll keep a map: StudiesID -> list of SubjectIDs
study_sub_map = {}
subject_to_studies_records = []
for st in studies_records:
study_id = st['StudiesID']
how_many_sub = random.randint(MIN_SUBJECTS_PER_STUDY, MAX_SUBJECTS_PER_STUDY)
chosen_subs = random.sample(subject_records, k=how_many_sub)
for sub in chosen_subs:
subject_to_studies_records.append({
'StudiesID': study_id,
'SubjectID': sub['SubjectID']
})
if study_id not in study_sub_map:
study_sub_map[study_id] = []
study_sub_map[study_id].append(sub['SubjectID'])
# ==============================================================================
# 18) INTERNSHIP
# ==============================================================================
internship_records = []
for i in range(1, NUM_INTERNSHIPS+1):
chosen_study = random.choice(studies_records)
start_dt = faker.date_between(start_date='-2y', end_date='+1y')
internship_records.append({
'InternshipID': i,
'StudiesID': chosen_study['StudiesID'],
'StartDate': start_dt
})
# ==============================================================================
# 19) STUDIESDETAILS
# ==============================================================================
studies_details_records = []
all_grade_ids = [g['GradeID'] for g in grade_records]
study_students_map = {}
for st in studies_records:
study_id = st['StudiesID']
chosen_students = random.sample(student_coll_records, k=random.randint(7, st['EnrollmentLimit']))
for cs in chosen_students:
assigned_grade = random.choice(all_grade_ids)
studies_details_records.append({
'StudiesID': study_id,
'StudentID': cs['StudentID'],
'StudiesGrade': assigned_grade,
# FIXME: assign all semesters for a student
'SemesterID': random.choice([s['SemesterID'] for s in semester_records if s['StudiesID']==study_id])
})
if study_id not in study_students_map:
study_students_map[study_id] = []
study_students_map[study_id].append(cs['StudentID'])
# ==============================================================================
# 20) INTERNSHIPDETAILS
# ==============================================================================
internship_details_records = []
for _ in range(NUM_INTERNSHIP_DETAILS):
it = random.choice(internship_records)
sid = it['StudiesID']
studs = study_students_map.get(sid, [])
if not studs:
continue
chosen_stud = random.choice(studs)
chosen_grade = random.choice(all_grade_ids)
internship_details_records.append({
'InternshipID': it['InternshipID'],
'StudentID': chosen_stud,
'Duration': random.randint(30,180),
'InternshipGrade': chosen_grade,
'InternshipAttendance': random.choice([0,1])
})
# ==============================================================================
# 21) CONVENTION (with integer Duration)
# ==============================================================================
convention_records = []
next_convention_id = 1
# subject_convention_map[subjectID] -> list of {StartDate, DurationDays, ...}
subject_convention_map = {}
idx = 1
for sem in semester_records:
sem_id = sem['SemesterID']
st_id = sem['StudiesID']
possible_subs = study_sub_map.get(st_id, [])
if not possible_subs:
continue
num_convs = random.randint(MIN_CONVENTIONS_PER_SEMESTER, MAX_CONVENTIONS_PER_SEMESTER)
for _ in range(num_convs):
cid = next_convention_id
next_convention_id += 1
chosen_sub = random.choice(possible_subs)
su = random.choice(service_user_details_records) if service_user_details_records else None
cstart = faker.date_between(start_date=sem['StartDate'], end_date=sem['EndDate'])
duration_days = random.randint(2, 7)
convention_records.append({
'ConventionID': cid,
'SemesterID': sem_id,
'ConventionID': idx,
'SubjectID': chosen_sub,
'ServiceID': su['ServiceUserID'] if su else 1,
'StartDate': cstart,
'Duration': duration_days
})
idx += 1
if chosen_sub not in subject_convention_map:
subject_convention_map[chosen_sub] = []
subject_convention_map[chosen_sub].append({
'ConventionID': cid,
'StartDate': cstart,
'DurationDays': duration_days
})
# ==============================================================================
# 22) CLASSMEETING + SUBCLASSES + Sync/Async, all within a Convention window
# ==============================================================================
class_meeting_records = []
stationary_class_records = []
online_live_class_records = []
offline_video_class_records = []
sync_class_details_records = []
async_class_details_records = []
possible_teachers = [
e for e in employee_records
if next(u for u in user_records if u['UserID']==e['EmployeeID'])['UserTypeID'] == 2
]
translator_ids = [t['TranslatorID'] for t in translator_records]
next_meeting_id = 1
for s2s in subject_to_studies_records:
s_id = s2s['StudiesID']
subj_id = s2s['SubjectID']
# how many total meetings for this subject?
how_many_meet = random.randint(MIN_CLASSMEETINGS_PER_SUBJECT, MAX_CLASSMEETINGS_PER_SUBJECT)
# if the subject has NO conventions, we skip generation
if subj_id not in subject_convention_map or not subject_convention_map[subj_id]:
continue
for _ in range(how_many_meet):
cm_id = next_meeting_id
next_meeting_id += 1
# pick a random Convention for this subject
chosen_conv = random.choice(subject_convention_map[subj_id])
conv_start = chosen_conv['StartDate']
conv_dur = chosen_conv['DurationDays']
offset_days = random.randint(0, max(0, conv_dur - 1))
meet_date = conv_start + timedelta(days=offset_days)
meeting_hour = time(hour=faker.random_int(min=8, max=18), minute=0)
meet_dt = datetime.combine(meet_date, meeting_hour)
teacher_emp = random.choice(possible_teachers) if possible_teachers else None
chosen_translator = random.choice(translator_ids) if translator_ids else None
mtype = random.choice(["stationary","online","offline"])
class_meeting_records.append({
'ClassMeetingID': cm_id,
'SubjectID': subj_id,
'TeacherID': teacher_emp['EmployeeID'] if teacher_emp else 'NULL',
'MeetingName': faker.word().capitalize() + " " + mtype,
'TranslatorID': chosen_translator if chosen_translator else 'NULL',
'LanguageID': 'NULL',
'ServiceID': random.choice(service_user_details_records)['ServiceUserID']
if service_user_details_records else 1,
'MeetingType': mtype,
'MeetingDate': meet_date
})
# decide sub-type
subtype = mtype
# duration should be in HH:MM:SS format and equal to 01:30:00 or 00:45:00 or 02:00:00
if subtype == "stationary":
stationary_class_records.append({
'MeetingID': cm_id,
'RoomID': random.randint(100,200),
'GroupSize': random.randint(5,30),
'StartDate': meet_dt.strftime('%Y-%m-%d %H:%M:%S'),
'Duration': random.choice(['01:30:00', '01:30:00', '01:30:00','01:30:00','01:30:00', '02:00:00', '00:45:00', '00:45:00'])
})
room_schedule_records.append({
'RoomID': cm_id,
'StartDate': meet_dt.strftime('%Y-%m-%d %H:%M:%S'),
'SlotID': 1 if not len(room_schedule_records) else max(r['SlotID'] for r in room_schedule_records)+1,
'EndDate': (meet_dt + timedelta(hours=1, minutes=30)).strftime('%Y-%m-%d %H:%M:%S'),
'SlotAvailability': 0
})
room_details_records.append({
'RoomID': cm_id,
'ScheduleOnDate': meet_date.strftime('%Y-%m-%d'),
'SlotID': 1 if not len(room_details_records) else max(r['SlotID'] for r in room_details_records)+1
})
# sync
studs_here = study_students_map.get(s_id, [])
# ???
student_sample = random.sample(studs_here, k=len(studs_here))
for s in student_sample:
sync_class_details_records.append({
'MeetingID': cm_id,
'StudentID': s,
'Attendance': random.choice([0,1,1,1,1])
})
elif subtype == "online":
online_live_class_records.append({
'MeetingID': cm_id,
'Link': faker.uri(),
'StartDate': meet_dt.strftime('%Y-%m-%d %H:%M:%S'),
'Duration': random.choice(['01:30:00', '01:30:00', '01:30:00','01:30:00','01:30:00', '02:00:00', '00:45:00', '00:45:00'])
})
# sync
studs_here = study_students_map.get(s_id, [])
student_sample = random.sample(studs_here, k=min(5, len(studs_here)))
for s in student_sample:
sync_class_details_records.append({
'MeetingID': cm_id,
'StudentID': s,
'Attendance': random.choice([0,1])
})
else:
# offline
offline_video_class_records.append({
'MeetingID': cm_id,
'VideoLink': faker.uri_path(),
'StartDate': meet_date.strftime('%Y-%m-%d'),
'Deadline': (meet_date + timedelta(days=7)).strftime('%Y-%m-%d')
})
studs_here = study_students_map.get(s_id, [])
student_sample = random.sample(studs_here, k=min(5, len(studs_here)))
for s in student_sample:
seen = random.choice([0,1,1,1])
async_class_details_records.append({
'MeetingID': cm_id,
'StudentID': s,
'ViewDate': (meet_date + timedelta(days=random.randint(1,5))).strftime('%Y-%m-%d') if seen else 'NULL'
})
# ==============================================================================
# 23) SUBJECTDETAILS
# ==============================================================================
subject_details_records = []
for subj in subject_records:
studies_with_subject = [s2s['StudiesID'] for s2s in subject_to_studies_records if s2s['SubjectID'] == subj['SubjectID']]
students_from_studies = [s['StudentID'] for s in studies_details_records if s['StudiesID'] in studies_with_subject]
for cst in students_from_studies:
subject_details_records.append({
'SubjectID': subj['SubjectID'],
'StudentID': cst,
'SubjectGrade': round(random.uniform(2.0,5.0),1),
'Attendance': round(random.uniform(0,100),2)
})
# ==============================================================================
# COURSES
# ==============================================================================
NUM_COURSES = 20
NUM_MODULES = 100
possible_coordinator_emps = [e for e in employee_records
if next(u for u in user_records if u['UserID']==e['EmployeeID'])['UserTypeID'] in [2,4]]
courses_records = []
for i in range(1, NUM_COURSES + 1):
coordinator = random.choice(possible_coordinator_emps) if possible_coordinator_emps else None
course_date = faker.date_between(start_date='-2y', end_date='+1y')
courses_records.append({
'CourseID': i,
'CourseName': faker.word().title() + " Course",
'CourseDescription': faker.sentence(nb_words=10),
'CourseCoordinatorID': coordinator['EmployeeID'] if coordinator else 'NULL',
'ServiceID': None,
'CourseDate': course_date,
'EnrollmentLimit': random.randint(10,100)
})
# ==============================================================================
# Modules
# ==============================================================================
modules_records = []
possible_coordinator_emps = [e for e in employee_records if next(u for u in user_records if u['UserID'] == e['EmployeeID'])['UserTypeID'] in [2, 4]]
possible_module_types = ['Stationary', 'Hybrid', 'Online Lives', 'Offline Videos'] # Typy modułów
possible_translators = [e['EmployeeID'] for e in employee_records if next(u for u in user_records if u['UserID'] == e['EmployeeID'])['UserTypeID'] == 3] # Pracownicy z TranslatorID
for i in range(1, NUM_MODULES + 1):
course = random.choice(courses_records) # Wybór losowego kursu
coordinator = random.choice(possible_coordinator_emps) if possible_coordinator_emps else 'NULL'
translator = random.choice(possible_translators) if random.random() > 0.5 else 'NULL' # Czasami może nie być tłumacza
language = random.choice(language_records)['LanguageID']
modules_records.append({
'ModuleID': i,
'LanguageID': language,
'CourseID': course['CourseID'],
'TranslatorID': translator,
'ModuleCoordinatorID': coordinator['EmployeeID'] if coordinator else 'NULL',
'ModuleType': random.choice(possible_module_types)
})
# ==============================================================================
# Meetings
# ==============================================================================
NUM_MEETINGS = 1000
meeting_types = ["stationary", "offline video", "online live"]
stationary_meetings_records = []
offline_video_records = []
online_live_meetings_records = []
for i in range(1, NUM_MEETINGS + 1):
module = random.choice(modules_records) # losuj modul
if module['ModuleType'] == 'Stationary':
meeting_type = "stationary"
elif module['ModuleType'] == 'Offline Videos':
meeting_type = 'offline video'
elif module['ModuleType'] == 'Online Lives':
meeting_type = 'online live'
else:
meeting_type = random.choice(meeting_types) #losuj typ spotkania
teacher_id = random.choice([e['EmployeeID'] for e in employee_records if next(u for u in user_records if u['UserID'] == e['EmployeeID'])['UserTypeID'] == 2]) # Losowy nauczyciel
if meeting_type == "stationary":
meeting_date = faker.date_time_between(start_date='-2y', end_date='+1y')
meeting_duration = random.choice(['01:30:00', '01:30:00', '01:30:00','01:30:00','01:30:00', '01:30:00', '00:45:00', '00:45:00'])
room_id = random.randint(100,200) # Przykładowe ID pomieszczenia
group_size = random.randint(5, 30) # Rozmiar grupy
stationary_meetings_records.append({
'MeetingID': i,
'MeetingDate': meeting_date,
'MeetingDuration': meeting_duration,
'ModuleID': module['ModuleID'],
'RoomID': room_id,
'GroupSize': group_size,
'TeacherID': teacher_id
})
room_details_records.append({
'RoomID': room_id,
'ScheduleOnDate': meeting_date.strftime('%Y-%m-%d'),
'SlotID': 1 if not len(room_details_records) else max(r['SlotID'] for r in room_details_records) + 1
})
room_schedule_records.append({
'RoomID': room_id,
'StartDate': meeting_date.strftime('%Y-%m-%d %H:%M:%S'),
'SlotID': 1 if not len(room_schedule_records) else max(r['SlotID'] for r in room_schedule_records) + 1,
'EndDate': (meeting_date + timedelta(hours=1, minutes=30)).strftime('%Y-%m-%d %H:%M:%S'),
'SlotAvailability': 0
})
elif meeting_type == "offline video":
video_link = faker.url() # Generowanie linku do nagrania
video_duration = random.choice(['01:30:00', '01:30:00', '01:30:00','01:30:00','01:30:00', '01:30:00', '00:45:00', '00:45:00'])
offline_video_records.append({
'MeetingID': i,
'VideoLink': video_link,
'ModuleID': module['ModuleID'],
'VideoDuration': video_duration,
'TeacherID': teacher_id
})
else:
platform_name = random.choice(['Zoom', 'Teams', 'Google Meet', 'Skype', 'NULL']) # Platforma
link = faker.url() if platform_name else 'NULL' # Link do spotkania
video_link = faker.url() if random.random() > 0.5 else 'NULL' # Link do nagrania
meeting_date = faker.date_time_between(start_date='-2y', end_date='+1y')
video_duration = random.choice(['01:30:00', '01:30:00', '01:30:00','01:30:00','01:30:00', '01:30:00', '00:45:00', '00:45:00'])
online_live_meetings_records.append({
'MeetingID': i,
'PlatformName': platform_name,
'Link': link,
'VideoLink': video_link,
'ModuleID': module['ModuleID'],
'MeetingDate': meeting_date,
'MeetingDuration': video_duration,
'TeacherID': teacher_id
})
# ==============================================================================
# CourseParticipants
# ==============================================================================
course_participants_records = []
for course in courses_records:
course_participants = random.shuffle(service_user_details_records[::])
course_participants_cnt = random.randint(0, course['EnrollmentLimit'])
selected_participants = service_user_details_records[:course_participants_cnt]
for participant in selected_participants:
course_participants_records.append({
'ParticipantID': participant['ServiceUserID'],
'CourseID': course['CourseID']
})
# ==============================================================================
# MeetingsDetails - na razie dodaje participantow tylko zapisanych do kursu, moze powinien tez dodawac kilka losowych userow
# ==============================================================================
stationary_meeting_details_records = []
offline_video_details_records = []
online_live_meeting_details_records = []
for meeting in stationary_meetings_records:
modules = tuple(filter(lambda module: module['ModuleID'] == meeting['ModuleID'], modules_records))[0]
course = tuple(filter(lambda course: course['CourseID'] == module['CourseID'], courses_records))[0]
course_participantsIDs = list(map(lambda pair: pair['ParticipantID'], filter(lambda pair: pair['CourseID'] == course['CourseID'], course_participants_records)))
for participantID in course_participantsIDs:
stationary_meeting_details_records.append({
'MeetingID': meeting['MeetingID'],
'ParticipantID': participantID,
'Attendance': random.choice([0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) # Obecność na spotkaniu
})
for video in offline_video_records:
modules = tuple(filter(lambda module: module['ModuleID'] == video['ModuleID'], modules_records))[0]
course = tuple(filter(lambda course: course['CourseID'] == module['CourseID'], courses_records))[0]
course_participantsIDs = list(map(lambda pair: pair['ParticipantID'], filter(lambda pair: pair['CourseID'] == course['CourseID'], course_participants_records)))
for participantID in course_participantsIDs:
offline_video_details_records.append({
'MeetingID': video['MeetingID'],
'ParticipantID': participantID,
'dateOfViewing': random.choice([faker.date_time_between(start_date='-1y', end_date='now')]*40+ ['NULL']) # Data obejrzenia
})
for live_meeting in online_live_meetings_records:
modules = tuple(filter(lambda module: module['ModuleID'] == live_meeting['ModuleID'], modules_records))[0]
course = tuple(filter(lambda course: course['CourseID'] == module['CourseID'], courses_records))[0]
course_participantsIDs = list(map(lambda pair: pair['ParticipantID'], filter(lambda pair: pair['CourseID'] == course['CourseID'], course_participants_records)))
for participantID in course_participantsIDs:
online_live_meeting_details_records.append({
'MeetingID': live_meeting['MeetingID'],
'ParticipantID': participantID,
'Attendance': random.choice([0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) # Obecność na spotkaniu
})
# ==============================================================================
# 24) WEBINARS
# ==============================================================================
NUM_WEBINARS = 300 # how many webinars
MAX_PARTICIPANTS_PER_WEBINAR = 20
webinars_data = []
webinardetails_data = []
for i in range(1, NUM_WEBINARS + 1):
# pick random teacher if available
teacher_id = random.choice(possible_teachers)['EmployeeID'] if possible_teachers else None
translator_id = random.choice(translator_ids) if translator_ids else None
wname = faker.word().title() + " Webinar"
wdate = faker.date_time_between(start_date='-1y', end_date='now')
link = faker.uri()
dur_minutes = random.randint(30, 120)
hh = dur_minutes // 60
mm = dur_minutes % 60
duration_str = f"{hh:02d}:{mm:02d}:00"
link_video = faker.uri()
descr = faker.sentence(nb_words=8)
langid = random.choice([l['LanguageID'] for l in language_records])
webinars_data.append({
'WebinarID': i,
'TeacherID': teacher_id,
'TranslatorID': translator_id,
'WebinarName': wname,
'WebinarDate': wdate,
'Link': link,
'DurationTime': duration_str,
'LinkToVideo': link_video,
'WebinarDescription': descr,
'LanguageID': langid,
'ServiceID': 1
})
# pick random participants (any user with userType=1 => "students")
student_user_ids = [u['UserID'] for u in user_records if u['UserTypeID'] == 1]
# if no students, fallback to any user
if not student_user_ids:
student_user_ids = [u['UserID'] for u in user_records]
num_parts = random.randint(1, MAX_PARTICIPANTS_PER_WEBINAR)
chosen = random.sample(student_user_ids, k=min(num_parts, len(student_user_ids)))
for part_id in chosen:
avdue = faker.date_between(start_date='today', end_date='+30d')
webinardetails_data.append({
'ParticipantID': part_id,
'WebinarID': i,
'AvailableDue': avdue
})
# ==============================================================================
# 25) PAYMENT SYSTEM (Services, Orders, OrderDetails, Payments, etc.)
# ==============================================================================
service_types = [
"ClassMeetingService",
"StudiesService",
"ConventionService",
"WebinarService",
"CourseService"
]
services_records = []
class_meeting_service_records = []
studies_service_records = []
convention_service_records = []
webinar_service_records = []
course_service_records = []
next_service_id = 1
lens = [len(class_meeting_records), len(studies_records), len(convention_records), len(courses_records), len(webinars_data)]# len(webinars_records) zamiast 0
prefix_lens = [sum(lens[:(i + 1)]) for i in range (len(lens))] #XD
NUM_SERVICES = sum(lens)
for i in range(1, NUM_SERVICES + 1):
if i <= prefix_lens[0]:
stype = "ClassMeetingService"
class_meeting_records[i - 1]['ServiceID'] = i
price_students = round(random.uniform(10, 50), 2)
price_others = round(price_students + random.uniform(5, 30), 2)
class_meeting_service_records.append({
'ServiceID': i,
'PriceStudents': price_students,
'PriceOthers': price_others
})
elif i <= prefix_lens[1]:
stype = "StudiesService"
# class_meeting_records[i - prefix_lens[0] - 1]['ServiceID'] = i
studies_records[i - prefix_lens[0] - 1]['ServiceID'] = i
entry_fee = round(random.uniform(100, 500), 2)
studies_service_records.append({
'ServiceID': i,
'EntryFee': entry_fee
})
elif i <= prefix_lens[2]:
stype = "ConventionService"
# class_meeting_records[i - prefix_lens[1] - 1]['ServiceID'] = i
convention_records[i - prefix_lens[1] - 1]['ServiceID'] = i
conv_price = round(random.uniform(50, 250), 2)
convention_service_records.append({
'ServiceID': i,
'Price': conv_price
})
elif i <= prefix_lens[3]:
stype = "CourseService"
# class_meeting_records[i - prefix_lens[2] - 1]['ServiceID'] = i
courses_records[i - prefix_lens[2] - 1]['ServiceID'] = i
adv_val = round(random.uniform(50, 200), 2)
full_val = adv_val + round(random.uniform(50, 300), 2)
course_service_records.append({
'ServiceID': i,
'AdvanceValue': adv_val,
'FullPrice': full_val
})
else:
stype = "WebinarService"
webinars_data[i - prefix_lens[3] - 1]['ServiceID'] = i
web_price = round(random.uniform(20, 150), 2)
webinar_service_records.append({
'ServiceID': i,
'Price': web_price
})
services_records.append({
'ServiceID': i,
'ServiceType': stype
})
order_records = []
next_order_id = 1
student_user_ids = [u['UserID'] for u in user_records if u['UserTypeID'] == 1]
for _ in range(NUM_ORDERS):
if not student_user_ids:
break
buyer_id = random.choice(student_user_ids)
order_date = faker.date_time_between(start_date='-1y', end_date='now')
pay_link = faker.uri()[:60] if random.choice([True, False]) else None
order_records.append({
'OrderID': next_order_id,
'UserID': buyer_id,
'OrderDate': order_date,
'PaymentLink': pay_link
})
next_order_id += 1
# OrderDetails
order_details_records = []
for odr in order_records:
how_many_srv = random.randint(MIN_SERVICES_PER_ORDER, MAX_SERVICES_PER_ORDER)
chosen_srv = random.sample(services_records, k=how_many_srv)
for srv in chosen_srv:
order_details_records.append({
'OrderID': odr['OrderID'],
'ServiceID': srv['ServiceID'],
'PrincipalAgreement': random.choice([0,0,0,0,0,0,0,0,0,1])
})
# Payments
payment_records = []
next_payment_id = 1
if order_details_records:
for _ in range(NUM_PAYMENTS):
od = random.choice(order_details_records)
paid_or_not = random.choice([True, False, False]) # ~1/3 chance is unpaid
if paid_or_not:
pay_value = round(random.uniform(10, 500), 2)
pay_date = faker.date_time_between(start_date='-6m', end_date='now')
else:
pay_value = round(random.uniform(10, 500), 2)
pay_date = None
payment_records.append({
'PaymentID': next_payment_id,
'PaymentValue': pay_value,
'PaymentDate': pay_date,
'ServiceID': od['ServiceID'],
'OrderID': od['OrderID']
})
next_payment_id += 1
#==============================================================================
# 26) Rooms
#==============================================================================
NUM_ROOMS = 100
rooms_records = []
for i in range(100):