Repository navigation
Expand file tree
/
Copy pathload_sample_data.py
More file actions
407 lines (348 loc) · 13.3 KB
/
Copy pathload_sample_data.py
File metadata and controls
407 lines (348 loc) · 13.3 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
"""
Sample Data Loader for Academic Evaluation System
This script populates the database with sample data for testing and demonstration.
Run after migrations and ML model training.
Usage:
python manage.py shell < load_sample_data.py
Or run in Django shell:
python manage.py shell
>>> exec(open('load_sample_data.py').read())
"""
import os
import django
# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'academic_evaluation.settings')
django.setup()
from django.contrib.auth.models import User
from django.utils import timezone
from datetime import datetime, timedelta
import random
from evaluation.models import (
Student, Project, Team, RubricCategory, Evaluation,
AttendanceRecord, Assignment, AssignmentSubmission
)
from evaluation.ml_service import update_student_risk_status
print("=" * 70)
print("Loading Sample Data for Academic Evaluation System")
print("=" * 70)
print()
# ============================================================================
# 1. Create Rubric Categories
# ============================================================================
print("1. Creating Rubric Categories...")
rubric_categories = [
{
'name': 'Technical Skills',
'description': 'Programming, coding standards, and technical implementation',
'max_score': 100,
'weight': 1.5
},
{
'name': 'Communication',
'description': 'Presentation skills, documentation, and articulation',
'max_score': 100,
'weight': 1.0
},
{
'name': 'Teamwork',
'description': 'Collaboration, team dynamics, and contribution',
'max_score': 100,
'weight': 1.0
},
{
'name': 'Problem Solving',
'description': 'Analytical thinking and problem-solving approach',
'max_score': 100,
'weight': 1.2
},
{
'name': 'Innovation',
'description': 'Creative thinking and innovative solutions',
'max_score': 100,
'weight': 1.3
}
]
for cat_data in rubric_categories:
category, created = RubricCategory.objects.get_or_create(
name=cat_data['name'],
defaults={
'description': cat_data['description'],
'max_score': cat_data['max_score'],
'weight': cat_data['weight']
}
)
if created:
print(f" ✓ Created: {category.name}")
else:
print(f" - Exists: {category.name}")
print()
# ============================================================================
# 2. Create Projects
# ============================================================================
print("2. Creating Sample Projects...")
projects_data = [
{
'project_id': 'PROJ001',
'title': 'E-Commerce Web Application',
'description': 'Full-stack e-commerce platform with payment integration',
'department': 'Computer Science',
'semester': 6
},
{
'project_id': 'PROJ002',
'title': 'IoT Smart Home System',
'description': 'IoT-based home automation using sensors and actuators',
'department': 'Electronics',
'semester': 7
},
{
'project_id': 'PROJ003',
'title': 'Machine Learning Disease Predictor',
'description': 'ML model for early disease detection using patient data',
'department': 'Computer Science',
'semester': 8
},
{
'project_id': 'PROJ004',
'title': 'Mobile Fitness Tracker',
'description': 'Cross-platform mobile app for fitness tracking',
'department': 'Information Technology',
'semester': 6
}
]
projects = []
for proj_data in projects_data:
start_date = timezone.now().date() - timedelta(days=90)
end_date = timezone.now().date() + timedelta(days=30)
project, created = Project.objects.get_or_create(
project_id=proj_data['project_id'],
defaults={
'title': proj_data['title'],
'description': proj_data['description'],
'department': proj_data['department'],
'semester': proj_data['semester'],
'start_date': start_date,
'end_date': end_date,
'max_team_size': 4
}
)
projects.append(project)
if created:
print(f" ✓ Created: {project.project_id} - {project.title}")
else:
print(f" - Exists: {project.project_id}")
print()
# ============================================================================
# 3. Create Sample Students
# ============================================================================
print("3. Creating Sample Students...")
departments = ['Computer Science', 'Electronics', 'Information Technology', 'Mechanical']
first_names = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve', 'Frank', 'Grace', 'Henry', 'Ivy', 'Jack']
last_names = ['Anderson', 'Brown', 'Chen', 'Davis', 'Evans', 'Garcia', 'Hall', 'Ibrahim', 'Johnson', 'Kumar']
students = []
for i in range(20):
student_id = f'STU{2024001 + i}'
# Create varied student profiles
if i < 12: # Safe students
cgpa = round(random.uniform(6.5, 9.5), 2)
attendance = round(random.uniform(75, 98), 2)
assignment_comp = round(random.uniform(80, 100), 2)
participation = round(random.uniform(70, 95), 2)
else: # At-risk students
cgpa = round(random.uniform(3.5, 6.0), 2)
attendance = round(random.uniform(45, 70), 2)
assignment_comp = round(random.uniform(40, 75), 2)
participation = round(random.uniform(35, 65), 2)
first_name = random.choice(first_names)
last_name = random.choice(last_names)
department = random.choice(departments)
semester = random.randint(5, 8)
student, created = Student.objects.get_or_create(
student_id=student_id,
defaults={
'first_name': first_name,
'last_name': last_name,
'email': f'{first_name.lower()}.{last_name.lower()}@university.edu',
'phone': f'+91-98{random.randint(10000000, 99999999)}',
'department': department,
'semester': semester,
'enrollment_year': 2024 - (semester // 2),
'cgpa': cgpa,
'attendance_percentage': attendance,
'assignment_completion': assignment_comp,
'participation_score': participation
}
)
if created:
students.append(student)
print(f" ✓ Created: {student.student_id} - {student.full_name}")
# Update ML risk status
try:
update_student_risk_status(student)
print(f" Risk: {student.risk_status} ({student.risk_confidence:.2%})")
except Exception as e:
print(f" ⚠ Risk prediction failed: {e}")
else:
students.append(student)
print(f" - Exists: {student.student_id}")
print()
# ============================================================================
# 4. Create Teams
# ============================================================================
print("4. Creating Teams...")
# Create 5 teams
for i in range(5):
team_id = f'TEAM{i+1:03d}'
team_name = f'Team {chr(65+i)}' # Team A, Team B, etc.
# Assign 3-4 students per team
team_students = students[i*4:(i+1)*4]
if not team_students:
continue
project = projects[i % len(projects)]
team, created = Team.objects.get_or_create(
team_id=team_id,
defaults={
'team_name': team_name,
'project': project,
'team_leader': team_students[0] if team_students else None
}
)
if created:
team.students.set(team_students)
print(f" ✓ Created: {team.team_id} - {team.team_name} ({len(team_students)} members)")
else:
print(f" - Exists: {team.team_id}")
print()
# ============================================================================
# 5. Create Evaluations
# ============================================================================
print("5. Creating Sample Evaluations...")
# Create admin user if doesn't exist for evaluator
admin_user, _ = User.objects.get_or_create(
username='admin',
defaults={
'email': 'admin@university.edu',
'is_staff': True,
'is_superuser': True
}
)
evaluation_types = ['Mid-Term', 'Final', 'Weekly', 'Presentation']
categories = list(RubricCategory.objects.all())
eval_count = 0
for student in students[:10]: # Create evaluations for first 10 students
project = random.choice(projects)
# Create 2-3 evaluations per student
for _ in range(random.randint(2, 3)):
eval_id = f'EVAL{2024001 + eval_count}'
eval_type = random.choice(evaluation_types)
category = random.choice(categories)
# Score correlates with student performance
base_score = (student.cgpa / 10) * 100
score = max(0, min(100, base_score + random.uniform(-15, 15)))
evaluation, created = Evaluation.objects.get_or_create(
evaluation_id=eval_id,
defaults={
'student': student,
'project': project,
'evaluator': admin_user,
'evaluation_type': eval_type,
'evaluation_date': timezone.now() - timedelta(days=random.randint(1, 60)),
'rubric_category': category,
'score': round(score, 2),
'max_score': 100.0,
'comments': f'Good work on {category.name.lower()}. Keep it up!',
'strengths': 'Strong technical understanding',
'improvements': 'Can improve on time management'
}
)
if created:
eval_count += 1
if eval_count <= 5: # Show first 5
print(f" ✓ {eval_id}: {student.student_id} - {eval_type} - {score:.1f}/100")
if eval_count > 5:
print(f" ... and {eval_count - 5} more evaluations")
print()
# ============================================================================
# 6. Create Attendance Records
# ============================================================================
print("6. Creating Attendance Records...")
session_types = ['Lecture', 'Lab', 'Tutorial', 'Project']
attendance_count = 0
for student in students[:10]:
# Create 10 attendance records per student
for day_offset in range(10):
date = timezone.now().date() - timedelta(days=day_offset)
session = random.choice(session_types)
# Status based on student's attendance percentage
rand_val = random.uniform(0, 100)
if rand_val < student.attendance_percentage:
status = 'Present'
elif rand_val < student.attendance_percentage + 5:
status = 'Late'
else:
status = 'Absent'
record, created = AttendanceRecord.objects.get_or_create(
student=student,
date=date,
session_type=session,
defaults={'status': status}
)
if created:
attendance_count += 1
print(f" ✓ Created {attendance_count} attendance records")
print()
# ============================================================================
# 7. Create Assignments
# ============================================================================
print("7. Creating Assignments...")
for project in projects[:2]:
for i in range(3):
assignment_id = f'ASSGN{project.project_id[-3:]}0{i+1}'
assignment, created = Assignment.objects.get_or_create(
assignment_id=assignment_id,
defaults={
'title': f'Assignment {i+1} - {project.title}',
'description': f'Complete part {i+1} of the project',
'project': project,
'due_date': timezone.now() + timedelta(days=random.randint(5, 30)),
'max_marks': 100.0
}
)
if created:
print(f" ✓ Created: {assignment.assignment_id}")
print()
# ============================================================================
# Summary
# ============================================================================
print("=" * 70)
print("Sample Data Loading Complete!")
print("=" * 70)
print()
print(f"✓ Rubric Categories: {RubricCategory.objects.count()}")
print(f"✓ Projects: {Project.objects.count()}")
print(f"✓ Students: {Student.objects.count()}")
print(f"✓ Teams: {Team.objects.count()}")
print(f"✓ Evaluations: {Evaluation.objects.count()}")
print(f"✓ Attendance Records: {AttendanceRecord.objects.count()}")
print(f"✓ Assignments: {Assignment.objects.count()}")
print()
# Risk Status Summary
safe_count = Student.objects.filter(risk_status='Safe').count()
at_risk_count = Student.objects.filter(risk_status='At Risk').count()
unknown_count = Student.objects.filter(risk_status='Unknown').count()
print("Risk Status Distribution:")
print(f" Safe: {safe_count}")
print(f" At Risk: {at_risk_count}")
print(f" Unknown: {unknown_count}")
print()
print("🎉 You can now:")
print(" 1. Access dashboards at http://localhost:8000/")
print(" 2. Login to admin at http://localhost:8000/admin/")
print(" 3. View students at http://localhost:8000/students/")
print(" 4. Test API endpoints")
print()
print("Sample login credentials (if created):")
print(" Username: admin")
print(" Password: (what you set during createsuperuser)")
print()
print("=" * 70)