-
Notifications
You must be signed in to change notification settings - Fork 16
/
add_data.py
397 lines (364 loc) · 11.2 KB
/
add_data.py
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
import os
import django
from datetime import datetime, timedelta
os.environ.setdefault(
"DJANGO_SETTINGS_MODULE", "course_management.settings"
)
django.setup()
from django.contrib.auth import get_user_model # noqa: E402
# This will retrieve your 'CustomUser' model
from courses.models import ( # noqa: E402
Course,
Enrollment,
Homework,
HomeworkState,
Question,
Submission,
Answer,
AnswerTypes,
QuestionTypes,
Project,
ProjectState,
ProjectSubmission,
ReviewCriteria,
ReviewCriteriaTypes,
QUESTION_ANSWER_DELIMITER
)
User = get_user_model()
admin_user, created = User.objects.get_or_create(
username="admin", defaults={"email": "[email protected]"}
)
if created:
admin_user.set_password("admin")
admin_user.is_superuser = True
admin_user.is_staff = True
admin_user.save()
course = Course(
title="Fake Course",
description="This is a fake course.",
slug="fake-course",
finished=False,
)
course.save()
ten_years_later = datetime.now() + timedelta(days=365 * 10)
homework1 = Homework(
course=course,
title="Homework 1",
description="Description for Homework 1",
due_date=ten_years_later,
slug="hw1",
state=HomeworkState.CLOSED.value,
)
homework1.save()
admin_enrollment = Enrollment(
student=admin_user,
course=course,
certificate_url="https://certificate.datatalks.club/mlops-zoomcamp/2024/fe629854d45c559e9c10b3b8458ea392fdeb68a9.pdf"
)
admin_enrollment.save()
def join_possible_answers(answers: list) -> str:
return QUESTION_ANSWER_DELIMITER.join(answers)
# Questions for Homework 1
question11 = Question(
homework=homework1,
text="What is 2 + 2?",
question_type=QuestionTypes.MULTIPLE_CHOICE.value,
possible_answers=join_possible_answers(["3", "4", "5", "6"]),
correct_answer="2",
)
question11.save()
question12 = Question(
homework=homework1,
text="Explain the theory of relativity.",
question_type=QuestionTypes.FREE_FORM.value,
answer_type=AnswerTypes.ANY.value,
correct_answer="",
)
question12.save()
question13 = Question(
homework=homework1,
text="Which of these are prime numbers?",
question_type=QuestionTypes.CHECKBOXES.value,
possible_answers=join_possible_answers(["1", "2", "3", "4", "5"]),
correct_answer="2,3,5",
)
question13.save()
question14 = Question(
homework=homework1,
text="What is the capital of France?",
question_type=QuestionTypes.MULTIPLE_CHOICE.value,
possible_answers=join_possible_answers(["London", "Paris", "Berlin", "Madrid"]),
correct_answer="2",
)
question14.save()
question15 = Question(
homework=homework1,
text="Calculate the area of a circle with radius 5.",
question_type=QuestionTypes.FREE_FORM.value,
answer_type=AnswerTypes.FLOAT.value,
correct_answer="78.54",
)
question15.save()
question16 = Question(
homework=homework1,
text="Name a gas lighter than air.",
question_type=QuestionTypes.FREE_FORM.value,
answer_type=AnswerTypes.CONTAINS_STRING.value,
correct_answer="Hydrogen",
)
question16.save()
admin_submission = Submission(
homework=homework1,
student=admin_user,
enrollment=admin_enrollment,
)
admin_submission.save()
Answer(
submission=admin_submission,
question=question11,
answer_text="3",
).save()
Answer(
submission=admin_submission,
question=question12,
answer_text="E=mc^2",
).save()
Answer(
submission=admin_submission,
question=question13,
answer_text="2,3,4,5",
).save()
Answer(
submission=admin_submission,
question=question14,
answer_text="2",
).save()
Answer(
submission=admin_submission,
question=question15,
answer_text="78.54",
).save()
Answer(
submission=admin_submission,
question=question16,
answer_text="Helium",
).save()
homework2 = Homework(
course=course,
title="Homework 2",
description="Description for Homework 2",
due_date=ten_years_later,
slug="hw2",
state=HomeworkState.OPEN.value,
)
homework2.save()
# Creating questions for Homework 2
Question(
homework=homework2,
text="What is the boiling point of water?",
question_type=QuestionTypes.MULTIPLE_CHOICE.value,
possible_answers=join_possible_answers(["50", "75", "100", "125"]),
correct_answer="3",
).save()
Question(
homework=homework2,
text="Describe the process of photosynthesis.",
question_type=QuestionTypes.FREE_FORM.value,
answer_type=AnswerTypes.ANY.value,
correct_answer="",
).save()
Question(
homework=homework2,
text="Select all even numbers",
question_type=QuestionTypes.CHECKBOXES.value,
possible_answers=join_possible_answers(["1", "2", "3", "4", "5", "6"]),
correct_answer="2,4,6",
).save()
Question(
homework=homework2,
text="Who wrote Macbeth?",
question_type=QuestionTypes.MULTIPLE_CHOICE.value,
possible_answers=join_possible_answers(["William Shakespeare", "Charles Dickens", "Mark Twain"]),
correct_answer="1",
).save()
Question(
homework=homework2,
text="Solve for x in 2x + 3 = 11.",
question_type=QuestionTypes.FREE_FORM.value,
answer_type=AnswerTypes.INTEGER.value,
correct_answer="4",
).save()
Question(
homework=homework2,
text="Name a programming language used for web development.",
question_type=QuestionTypes.FREE_FORM.value,
answer_type=AnswerTypes.CONTAINS_STRING.value,
correct_answer="JavaScript",
).save()
project = Project(
course=course,
title="Fake Project",
slug="fake-project",
submission_due_date=ten_years_later,
peer_review_due_date=ten_years_later,
learning_in_public_cap_project=14,
learning_in_public_cap_review=2,
number_of_peers_to_evaluate=3,
points_to_pass=10,
state=ProjectState.COLLECTING_SUBMISSIONS.value,
)
project.save()
project_submission = ProjectSubmission(
project=project,
student=admin_user,
enrollment=admin_enrollment,
github_link="https://github.com/DataTalksClub/data-engineering-zoomcamp",
commit_id="8c45587",
learning_in_public_links={
"link1": "http://example.com",
"link2": "http://example.org",
},
faq_contribution="Contributed to the following FAQs...",
time_spent=10.0,
problems_comments="This is a test submission.",
)
project_submission.save()
criteria_data = [
{
"description": "Problem description",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{"criteria": "The problem is not described", "score": 0},
{
"criteria": "The problem is described but shortly or not clearly",
"score": 1,
},
{
"criteria": "The problem is well described and it's clear what the problem the project solves",
"score": 2,
},
],
},
{
"description": "Cloud",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{
"criteria": "Cloud is not used, things run only locally",
"score": 0,
},
{
"criteria": "The project is developed on the cloud OR uses localstack (or similar tool) OR the project is deployed to Kubernetes or similar container management platforms",
"score": 2,
},
{
"criteria": "The project is developed on the cloud and IaC tools are used for provisioning the infrastructure",
"score": 4,
},
],
},
{
"description": "Experiment tracking and model registry",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{
"criteria": "No experiment tracking or model registry",
"score": 0,
},
{
"criteria": "Experiments are tracked or models are registered in the registry",
"score": 2,
},
{
"criteria": "Both experiment tracking and model registry are used",
"score": 4,
},
],
},
{
"description": "Workflow orchestration",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{"criteria": "No workflow orchestration", "score": 0},
{"criteria": "Basic workflow orchestration", "score": 2},
{"criteria": "Fully deployed workflow", "score": 4},
],
},
{
"description": "Model deployment",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{"criteria": "Model is not deployed", "score": 0},
{
"criteria": "Model is deployed but only locally",
"score": 2,
},
{
"criteria": "The model deployment code is containerized and could be deployed to cloud or special tools for model deployment are used",
"score": 4,
},
],
},
{
"description": "Model monitoring",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{"criteria": "No model monitoring", "score": 0},
{
"criteria": "Basic model monitoring that calculates and reports metrics",
"score": 2,
},
{
"criteria": "Comprehensive model monitoring that sends alerts or runs a conditional workflow (e.g. retraining, generating debugging dashboard, switching to a different model) if the defined metrics threshold is violated",
"score": 4,
},
],
},
{
"description": "Reproducibility",
"type": ReviewCriteriaTypes.RADIO_BUTTONS.value,
"options": [
{
"criteria": "No instructions on how to run the code at all, the data is missing",
"score": 0,
},
{
"criteria": "Some instructions are there, but they are not complete OR instructions are clear and complete, the code works, but the data is missing",
"score": 2,
},
{
"criteria": "Instructions are clear, it's easy to run the code, and it works. The versions for all the dependencies are specified",
"score": 4,
},
],
},
{
"description": "Best practices",
"type": ReviewCriteriaTypes.CHECKBOXES.value,
"options": [
{"criteria": "There are unit tests", "score": 1},
{"criteria": "There is an integration test", "score": 1},
{
"criteria": "Linter and/or code formatter are used",
"score": 1,
},
{"criteria": "There's a Makefile", "score": 1},
{"criteria": "There are pre-commit hooks", "score": 1},
{"criteria": "There's a CI/CD pipeline", "score": 2},
],
},
]
for criterion in criteria_data:
ReviewCriteria.objects.create(
course=course,
description=criterion["description"],
review_criteria_type=criterion["type"],
options=criterion["options"],
)
course2 = Course(
title="Fake Course 2",
description="This is a fake course.",
slug="fake-course-2",
finished=True,
)
course2.save()