Skip to content

Commit

Permalink
chore: fixed some concerns of vincent
Browse files Browse the repository at this point in the history
  • Loading branch information
tyboro2002 committed Apr 14, 2024
1 parent d237642 commit eee6484
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
PUID=1000
PGID=1000
TZ=Europe/Brussels
FIXTURES=small
FIXTURE=small

# File directories
DATA_DIR="./data"
Expand Down
2 changes: 1 addition & 1 deletion .prod.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
PUID=1000
PGID=1000
TZ=Europe/Brussels
FIXTURES=large
FIXTURE=large

# File directories
DATA_DIR="./data"
Expand Down
2 changes: 1 addition & 1 deletion backend/api/fixtures/large/large.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/api/fixtures/medium/medium.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/api/fixtures/small/small.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion backend/api/logic/check_folder_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ def check_zip_structure(
zip_file_path,
directory,
obligated_extensions,
blocked_extensions)
blocked_extensions
)
if not result:
return result, message
# Check for any directories not present in the folder structure dictionary
Expand Down
69 changes: 32 additions & 37 deletions backend/api/management/commands/seed_db_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from authentication.models import User
from api.seeders.faker import faker
from api.seeders.seeder import seed_students, seed_assistants, seed_teachers, seed_courses, seed_projects, seed_groups, \
seed_submissions
seed_submissions, fillFaculties
from api.models.course import Course
from api.models.group import Group
from api.models.project import Project
from api.models.teacher import Teacher
from api.models.student import Student
from api.models.assistant import Assistant
from api.models.submission import Submission
from authentication.models import Faculty

import time

Expand Down Expand Up @@ -98,44 +99,38 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('size', type=str, help='The size you want to seed')

amount_of_students = 50_000
amount_of_assistants = 5_000
amount_of_teachers = 1_500
amount_of_courses = 1_500
amount_of_projects = 3_000
amount_of_groups = 3_000
amount_of_submissions = 3_000

def handle(self, *args, **options):
size = options['size']
if size == "small":
self.amount_of_students = 10
self.amount_of_assistants = 5
self.amount_of_teachers = 3
self.amount_of_courses = 3
self.amount_of_projects = 4
self.amount_of_groups = 7
self.amount_of_submissions = 10
amount_of_students = 10
amount_of_assistants = 5
amount_of_teachers = 3
amount_of_courses = 3
amount_of_projects = 4
amount_of_groups = 7
amount_of_submissions = 10
elif size == "medium":
self.amount_of_students = 20_000
self.amount_of_assistants = 2_000
self.amount_of_teachers = 500
self.amount_of_courses = 500
self.amount_of_projects = 1_000
self.amount_of_groups = 1_000
self.amount_of_submissions = 1_000
amount_of_students = 20_000
amount_of_assistants = 2_000
amount_of_teachers = 500
amount_of_courses = 500
amount_of_projects = 1_000
amount_of_groups = 1_000
amount_of_submissions = 1_000
elif size == "large":
self.amount_of_students = 50_000
self.amount_of_assistants = 5_000
self.amount_of_teachers = 1_500
self.amount_of_courses = 1_500
self.amount_of_projects = 3_000
self.amount_of_groups = 3_000
self.amount_of_submissions = 3_000
amount_of_students = 50_000
amount_of_assistants = 5_000
amount_of_teachers = 1_500
amount_of_courses = 1_500
amount_of_projects = 3_000
amount_of_groups = 3_000
amount_of_submissions = 3_000
else:
self.stdout.write(self.style.ERROR("give a size from small, medium or large!"))
return

Faculty.objects.all().delete()
fillFaculties() # fill the faculty table again
# Reset DB
User.objects.all().delete()
Student.objects.all().delete()
Expand All @@ -150,25 +145,25 @@ def handle(self, *args, **options):
# Seed students
fake = faker()
start_time = time.time()
seed_students(fake, self.amount_of_students, 0)
seed_students(fake, amount_of_students, 0)

# Seed assistants
seed_assistants(fake, self.amount_of_assistants, self.amount_of_students)
seed_assistants(fake, amount_of_assistants, amount_of_students)

# Seed teachers
seed_teachers(fake, self.amount_of_teachers, self.amount_of_students + self.amount_of_assistants)
seed_teachers(fake, amount_of_teachers, amount_of_students + amount_of_assistants)

# Seed courses
seed_courses(faker(), self.amount_of_courses)
seed_courses(faker(), amount_of_courses)

# Seed projects
seed_projects(faker(), self.amount_of_projects)
seed_projects(faker(), amount_of_projects)

# Seed groups
seed_groups(faker(), self.amount_of_groups)
seed_groups(faker(), amount_of_groups)

# Seed submissions
seed_submissions(faker(), self.amount_of_submissions)
seed_submissions(faker(), amount_of_submissions)

end_time = time.time()
execution_time = end_time - start_time
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.0.4 on 2024-04-14 12:25

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0015_checkresult_remove_extrachecksresult_error_message_and_more'),
]

operations = [
migrations.AlterField(
model_name='checkresult',
name='submission',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='results', to='api.submission'),
),
migrations.AlterField(
model_name='extracheckresult',
name='extra_check',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='extra_check', to='api.extracheck'),
),
migrations.AlterField(
model_name='structurecheckresult',
name='structure_check',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='structure_check', to='api.structurecheck'),
),
]
2 changes: 1 addition & 1 deletion backend/api/models/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StructureCheck(models.Model):

# ID should be generated automatically

# Name of the structure check
# Name of the directory the structure check checks in
name = models.CharField(
max_length=100,
blank=False,
Expand Down
29 changes: 27 additions & 2 deletions backend/api/seeders/seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
from django.utils import timezone


def fillFaculties():
with connection.cursor() as cursor:
faculties = [
["Bio-ingenieurswetenschappen", "faculties.bioscience_engineering"],
["Diergeneeskunde", "faculties.veterinary_medicine"],
["Economie_Bedrijfskunde", "faculties.economics_business_administration"],
["Farmaceutische_Wetenschappen", "faculties.pharmaceutical_sciences"],
["Geneeskunde_Gezondheidswetenschappen", "faculties.medicine_health_sciences"],
["Ingenieurswetenschappen_Architectuur", "faculties.engineering_architecture"],
["Letteren_Wijsbegeerte", "faculties.arts_philosophy"],
["Politieke_Sociale_Wetenschappen", "faculties.political_social_sciences"],
["Psychologie_PedagogischeWetenschappen", "faculties.psychology_educational_sciences"],
["Recht_Criminologie", "faculties.law_criminology"],
["Wetenschappen", "faculties.sciences"]
]

cursor.executemany(
"INSERT INTO authentication_faculty(id, name) VALUES (?, ?)", faculties
)


def format_time(execution_time):
if execution_time < 1:
return f"{execution_time * 1000:.2f} milliseconds"
Expand All @@ -23,6 +44,7 @@ def timer(func):
def handle(*args, **kwargs):
start = time()

# print(f"{func.__name__} running")
result = func(*args, **kwargs)

print('Seeder {} took {}'.format(
Expand Down Expand Up @@ -323,12 +345,15 @@ def seed_submissions(faker, count: int = 4_000, struct_check_passed_prob: float

# Create submissions
submissions = [
[faker.date_this_month(), faker.boolean(chance_of_getting_true=struct_check_passed_prob), choice(groups)]
[
faker.date_this_month(),
choice(groups)
]
for _ in range(count)
]

# Insert submissions
cursor.executemany(
"INSERT INTO api_submission(submission_time, structure_checks_passed, group_id) VALUES (?, ?, ?)",
"INSERT INTO api_submission(submission_time, group_id) VALUES (?, ?)",
submissions
)
2 changes: 1 addition & 1 deletion backend/authentication/fixtures/large/large.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/authentication/fixtures/medium/medium.json

Large diffs are not rendered by default.

Loading

0 comments on commit eee6484

Please sign in to comment.