-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_default_data.py
More file actions
332 lines (284 loc) · 11.9 KB
/
Copy pathsetup_default_data.py
File metadata and controls
332 lines (284 loc) · 11.9 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
import json
import sys
import random
from datetime import datetime, timedelta
sys.path.append('.')
from utils.database import DatabaseConnection
def setup_default_sections_and_students():
"""Setup default sections and students"""
db = DatabaseConnection()
# Load students from JSON
with open('utils/default_students.json', 'r') as f:
students = json.load(f)
# User ID
user_id = 1
# Create ITEC 104 section
print("Creating ITEC 104 section...")
success1, message1, section_id1 = db.add_section(
section_name="ITEC 104",
user_id=user_id,
section="BSCS 2B",
subject="ITEC 104",
room="Room 301"
)
if success1:
print(f"✓ {message1} (ID: {section_id1})")
else:
print(f"✗ {message1}")
if "already exists" not in message1.lower():
return
# Create CMSC 203 section
print("\nCreating CMSC 203 section...")
success2, message2, section_id2 = db.add_section(
section_name="CMSC 203",
user_id=user_id,
section="BSCS 2B",
subject="CMSC 203",
room="Room 302"
)
if success2:
print(f"✓ {message2} (ID: {section_id2})")
else:
print(f"✗ {message2}")
if "already exists" not in message2.lower():
return
# Get existing section IDs if already created
if not success1 or not success2:
if not db.connect():
print("Database connection failed")
return
cursor = db.connection.cursor()
if not success1:
cursor.execute("SELECT section_id FROM sections WHERE section_name = %s AND user_id = %s AND is_archived = FALSE", ("ITEC 104", user_id))
result = cursor.fetchone()
if result:
section_id1 = result[0]
if not success2:
cursor.execute("SELECT section_id FROM sections WHERE section_name = %s AND user_id = %s AND is_archived = FALSE", ("CMSC 203", user_id))
result = cursor.fetchone()
if result:
section_id2 = result[0]
cursor.close()
db.disconnect()
# Add students to ITEC 104
print(f"\nAdding {len(students)} students to ITEC 104...")
added_count1 = 0
for student in students:
student_data = {
'student_id': student['student_id'],
'section_id': section_id1,
'first_name': student['first_name'],
'last_name': student['last_name'],
'age': student['age'],
'email': student['email'],
'phone': student['phone'],
'birthday': student['birthday'],
'address': student['address']
}
success, message = db.add_student(student_data)
if success:
added_count1 += 1
print(f" ✓ Added {student['first_name']} {student['last_name']}")
else:
print(f" ✗ {student['first_name']} {student['last_name']}: {message}")
print(f"\nTotal students added to ITEC 104: {added_count1}/{len(students)}")
# Add students to CMSC 203
print(f"\nAdding {len(students)} students to CMSC 203...")
added_count2 = 0
for student in students:
student_data = {
'student_id': student['student_id'],
'section_id': section_id2,
'first_name': student['first_name'],
'last_name': student['last_name'],
'age': student['age'],
'email': student['email'],
'phone': student['phone'],
'birthday': student['birthday'],
'address': student['address']
}
success, message = db.add_student(student_data)
if success:
added_count2 += 1
print(f" ✓ Added {student['first_name']} {student['last_name']}")
else:
print(f" ✗ {student['first_name']} {student['last_name']}: {message}")
print(f"\nTotal students added to CMSC 203: {added_count2}/{len(students)}")
# Add grades for ITEC 104 students
print(f"\n{'='*60}")
print("Adding grades for ITEC 104 students...")
print(f"{'='*60}")
grades_count1 = 0
for student in students:
# Random grades (1.00 to 3.00)
midterm = round(random.uniform(1.00, 3.00), 2)
final = round(random.uniform(1.00, 3.00), 2)
success = db.save_student_grades(
student['student_id'],
section_id1,
midterm,
final
)
if success:
grades_count1 += 1
semestral = (midterm + final) / 2
print(f" ✓ {student['first_name']} {student['last_name']}: Midterm={midterm}, Final={final}, Semestral={semestral:.2f}")
print(f"\nTotal grades added for ITEC 104: {grades_count1}/{len(students)}")
# Add grades for CMSC 203 students
print(f"\n{'='*60}")
print("Adding grades for CMSC 203 students...")
print(f"{'='*60}")
grades_count2 = 0
for student in students:
# Random grades (1.00 to 3.00)
midterm = round(random.uniform(1.00, 3.00), 2)
final = round(random.uniform(1.00, 3.00), 2)
success = db.save_student_grades(
student['student_id'],
section_id2,
midterm,
final
)
if success:
grades_count2 += 1
semestral = (midterm + final) / 2
print(f" ✓ {student['first_name']} {student['last_name']}: Midterm={midterm}, Final={final}, Semestral={semestral:.2f}")
print(f"\nTotal grades added for CMSC 203: {grades_count2}/{len(students)}")
# Add attendance records (Nov 27 to present)
print(f"\n{'='*60}")
print("Adding attendance records (Nov 27 - Present)...")
print(f"{'='*60}")
start_date = datetime(2025, 11, 27)
end_date = datetime.now()
current_date = start_date
attendance_count = 0
while current_date <= end_date:
# Weekdays only (Monday-Friday)
if current_date.weekday() < 5:
date_str = current_date.strftime('%Y-%m-%d')
# ITEC 104 attendance
attendance_data1 = {}
for student in students:
# 85% chance of being present
status = 'present' if random.random() < 0.85 else 'absent'
attendance_data1[student['student_id']] = {'status': status}
success1 = db.save_attendance(section_id1, date_str, attendance_data1)
if success1:
attendance_count += 1
present_count = sum(1 for data in attendance_data1.values() if data['status'] == 'present')
print(f" ✓ ITEC 104 - {date_str}: {present_count}/{len(students)} present")
# CMSC 203 attendance
attendance_data2 = {}
for student in students:
# 85% present chance
status = 'present' if random.random() < 0.85 else 'absent'
attendance_data2[student['student_id']] = {'status': status}
success2 = db.save_attendance(section_id2, date_str, attendance_data2)
if success2:
attendance_count += 1
present_count = sum(1 for data in attendance_data2.values() if data['status'] == 'present')
print(f" ✓ CMSC 203 - {date_str}: {present_count}/{len(students)} present")
current_date += timedelta(days=1)
print(f"\nTotal attendance records added: {attendance_count}")
# Create archived sections
print(f"\n{'='*60}")
print("Creating archived sections...")
print(f"{'='*60}")
archived_sections = [
("CMSC 202", "BSCS 2A", "CMSC 202", "Room 201"),
("ITEC 102", "BSCS 2A", "ITEC 102", "Room 202"),
("ITEC 106", "BSCS 2A", "ITEC 106", "Room 203")
]
archived_count = 0
for section_name, section, subject, room in archived_sections:
# Create archived section
success, message, section_id = db.add_section(
section_name=section_name,
user_id=user_id,
section=section,
subject=subject,
room=room
)
if success or "already exists" in message.lower():
if not success:
# Get section ID if exists
if not db.connect():
continue
cursor = db.connection.cursor()
cursor.execute("SELECT section_id FROM sections WHERE section_name = %s AND user_id = %s", (section_name, user_id))
result = cursor.fetchone()
if result:
section_id = result[0]
cursor.close()
db.disconnect()
# Add 10 students to archived section
for student in students[:10]:
student_data = {
'student_id': student['student_id'],
'section_id': section_id,
'first_name': student['first_name'],
'last_name': student['last_name'],
'age': student['age'],
'email': student['email'],
'phone': student['phone'],
'birthday': student['birthday'],
'address': student['address']
}
db.add_student(student_data)
# Archive section
archive_success, archive_msg = db.archive_section(section_id)
if archive_success:
archived_count += 1
print(f" ✓ {section_name} archived with 10 students")
print(f"\nTotal archived sections: {archived_count}")
# Add default schedules
print(f"\n{'='*60}")
print("Adding default schedules...")
print(f"{'='*60}")
schedules = [
# Tuesday
("CMSC 203", "BSCS 2B", "Tuesday", "7:00-9:00", "107", "#B5EAD7"),
("CMSC 203", "BSCS 2B", "Tuesday", "10:00-1:00", "206", "#F7D08A"),
# Wednesday
("CMSC 203", "BSCS 2A", "Wednesday", "7:00-9:00", "102", "#F0C7CF"),
("CMSC 203", "BSCS 2A", "Wednesday", "10:00-1:00", "102", "#F0C7CF"),
("ITST 301", "BSIT 3D", "Wednesday", "1:00-3:00", "103", "#F0C7CF"),
# Thursday
("ITEC 104", "BSCS 2B", "Thursday", "7:00-9:00", "107", "#F0C7CF"),
("ITEC 104", "BSCS 2B", "Thursday", "10:00-1:00", "205", "#A3C7D6"),
("ITST 301", "BSIT 3D", "Thursday", "2:00-5:00", "105", "#B5EAD7"),
# Friday
("ITEC 104", "BSCS 2A", "Friday", "7:00-9:00", "109", "#D5D0D5"),
("ITEC 104", "BSCS 2A", "Friday", "10:00-1:00", "201", "#A3C7D6"),
("CMSC 308", "BSCS 3B", "Friday", "2:00-5:00", "109", "#A3C7D6"),
# Saturday
("CMSC 308", "BSCS 3B", "Saturday", "7:00-12:00", "110", "#D5D0D5"),
("CMSC 308", "BSCS 3A", "Saturday", "1:00-5:00", "102", "#F7D08A"),
# Monday
("CMSC 308", "BSCS 3A", "Monday", "1:00-5:00", "101", "#F0C7CF"),
]
schedule_count = 0
for subject, section, day, time, room, color in schedules:
success = db.add_schedule(
user_id,
subject,
section,
day,
time,
room,
color
)
if success:
schedule_count += 1
print(f" ✓ {subject} ({section}) - {day} {time} in Room {room}")
print(f"\nTotal schedules added: {schedule_count}/{len(schedules)}")
print("\n" + "="*60)
print("Setup complete!")
print(f"ITEC 104 - BSCS 2B: {added_count1} students, {grades_count1} grades")
print(f"CMSC 203 - BSCS 2B: {added_count2} students, {grades_count2} grades")
print(f"Attendance records: {attendance_count} (Nov 27 - Present)")
print(f"Archived sections: {archived_count}")
print(f"Schedules: {schedule_count}")
print("="*60)
if __name__ == "__main__":
setup_default_sections_and_students()