2023-09-24 15:34:39 +02:00
|
|
|
from sqlalchemy import delete, select
|
2023-09-17 16:34:30 +02:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
2023-09-24 16:23:45 +02:00
|
|
|
from sqlalchemy.orm import selectinload
|
2023-09-17 16:34:30 +02:00
|
|
|
|
|
|
|
from database.engine import DBSession
|
2023-09-24 15:34:39 +02:00
|
|
|
from database.schemas import UforaCourse, UforaCourseAlias
|
2023-09-17 16:34:30 +02:00
|
|
|
|
|
|
|
__all__ = ["main"]
|
|
|
|
|
|
|
|
|
2023-09-24 16:23:45 +02:00
|
|
|
async def purge_aliases(session: AsyncSession):
|
|
|
|
"""Delete old aliases for courses that will get a new id"""
|
|
|
|
codes = ["C004074", "C004073", "C004075", "C002309"]
|
|
|
|
for course_code in codes:
|
|
|
|
select_stmt = (
|
|
|
|
select(UforaCourse).where(UforaCourse.code == course_code).options(selectinload(UforaCourse.aliases))
|
|
|
|
)
|
|
|
|
course: UforaCourse = (await session.execute(select_stmt)).scalar_one()
|
|
|
|
|
|
|
|
for alias in list(course.aliases):
|
|
|
|
await session.delete(alias)
|
|
|
|
|
|
|
|
await session.commit()
|
|
|
|
|
|
|
|
|
2023-09-17 16:34:30 +02:00
|
|
|
async def main():
|
|
|
|
"""Add the Ufora courses for the 2023-2024 academic year"""
|
|
|
|
session: AsyncSession
|
|
|
|
async with DBSession() as session:
|
2023-09-24 15:34:39 +02:00
|
|
|
# # Remove Advanced Databases (which no longer exists)
|
|
|
|
delete_stmt = delete(UforaCourse).where(UforaCourse.code == "E018441")
|
|
|
|
await session.execute(delete_stmt)
|
|
|
|
await session.commit()
|
|
|
|
|
2023-09-24 16:23:45 +02:00
|
|
|
# Delete aliases of courses with new IDs
|
|
|
|
await purge_aliases(session)
|
|
|
|
|
2023-09-24 15:40:27 +02:00
|
|
|
# Fix IDs of compulsory courses and enable announcements
|
|
|
|
select_stmt = select(UforaCourse).where(UforaCourse.code == "C004074")
|
|
|
|
bds: UforaCourse = (await session.execute(select_stmt)).scalar_one()
|
|
|
|
bds.course_id = 828305
|
|
|
|
bds.log_announcements = True
|
|
|
|
session.add(bds)
|
|
|
|
|
|
|
|
select_stmt = select(UforaCourse).where(UforaCourse.code == "C004073")
|
|
|
|
cg: UforaCourse = (await session.execute(select_stmt)).scalar_one()
|
|
|
|
cg.course_id = 828293
|
|
|
|
cg.log_announcements = True
|
2023-09-24 16:23:45 +02:00
|
|
|
session.add(cg)
|
2023-09-24 15:34:39 +02:00
|
|
|
|
|
|
|
select_stmt = select(UforaCourse).where(UforaCourse.code == "C004075")
|
|
|
|
stage: UforaCourse = (await session.execute(select_stmt)).scalar_one()
|
|
|
|
stage.course_id = 857878
|
2023-09-24 15:40:27 +02:00
|
|
|
stage.log_announcements = True
|
2023-09-24 15:34:39 +02:00
|
|
|
session.add(stage)
|
|
|
|
|
2023-09-24 15:40:27 +02:00
|
|
|
select_stmt = select(UforaCourse).where(UforaCourse.code == "C002309")
|
2023-09-24 15:34:39 +02:00
|
|
|
thesis: UforaCourse = (await session.execute(select_stmt)).scalar_one()
|
|
|
|
thesis.course_id = 828446
|
2023-09-24 15:40:27 +02:00
|
|
|
thesis.log_announcements = True
|
2023-09-24 15:34:39 +02:00
|
|
|
session.add(thesis)
|
|
|
|
|
|
|
|
await session.commit()
|
|
|
|
|
2023-09-24 16:23:45 +02:00
|
|
|
# Add new aliases for these courses
|
|
|
|
cg_alias = UforaCourseAlias(course_id=cg.course_id, alias="Computer Graphics")
|
|
|
|
stage_alias = UforaCourseAlias(course_id=stage.course_id, alias="Stage")
|
|
|
|
thesis_alias = UforaCourseAlias(course_id=thesis.course_id, alias="Thesis")
|
|
|
|
|
|
|
|
session.add_all([cg_alias, stage_alias, thesis_alias])
|
|
|
|
await session.commit()
|
|
|
|
|
2023-09-24 15:34:39 +02:00
|
|
|
# New elective courses
|
|
|
|
bed_eco = UforaCourse(
|
|
|
|
code="H001535", name="Bedrijfseconomie", year=6, compulsory=False, role_id=1155496199000952922
|
|
|
|
)
|
|
|
|
|
|
|
|
beg_eco = UforaCourse(
|
|
|
|
code="D012144", name="Beginselen van economie", year=6, compulsory=False, role_id=1155495997024247948
|
|
|
|
)
|
|
|
|
|
|
|
|
big_data_tech = UforaCourse(
|
|
|
|
code="E018240", name="Big Data Technology", year=6, compulsory=False, role_id=1155490114282201148
|
|
|
|
)
|
|
|
|
|
|
|
|
cloud_storage = UforaCourse(
|
|
|
|
code="E017310", name="Cloud Storage and Computing", year=6, compulsory=False, role_id=1155490706849271841
|
|
|
|
)
|
|
|
|
|
|
|
|
criminologie = UforaCourse(
|
|
|
|
code="B001623", name="Inleiding tot Criminologie", year=6, compulsory=False, role_id=1155486768477515936
|
|
|
|
)
|
|
|
|
|
|
|
|
data_quality = UforaCourse(
|
|
|
|
code="E018700", name="Data Quality", year=6, compulsory=False, role_id=1155491028707586180
|
|
|
|
)
|
|
|
|
|
|
|
|
data_vis_ai = UforaCourse(
|
|
|
|
code="E061370",
|
|
|
|
name="Data Visualization for and with AI",
|
|
|
|
year=6,
|
|
|
|
compulsory=False,
|
|
|
|
role_id=1155491854687686746,
|
|
|
|
)
|
|
|
|
|
|
|
|
db_design = UforaCourse(
|
|
|
|
code="E018610", name="Database Design", year=6, compulsory=False, role_id=1155489846345875489
|
|
|
|
)
|
|
|
|
|
|
|
|
finance_markets = UforaCourse(
|
|
|
|
code="F000093",
|
|
|
|
name="Financiële Markten en Instellingen",
|
|
|
|
year=6,
|
|
|
|
compulsory=False,
|
|
|
|
role_id=1155492815615299634,
|
|
|
|
)
|
|
|
|
|
|
|
|
game_theory = UforaCourse(
|
|
|
|
code="E003710",
|
|
|
|
name="Game Theory and Multiagent Systems",
|
|
|
|
year=6,
|
|
|
|
compulsory=False,
|
|
|
|
role_id=1155488481666154506,
|
|
|
|
)
|
|
|
|
|
|
|
|
knowledge_graphs = UforaCourse(
|
|
|
|
code="E018160", name="Knowledge Graphs", year=6, compulsory=False, role_id=1155491648323735592
|
|
|
|
)
|
|
|
|
|
|
|
|
natural_language_processing = UforaCourse(
|
|
|
|
code="E061341", name="Natural Language Processing", year=6, compulsory=False, role_id=1155487540992823348
|
|
|
|
)
|
|
|
|
|
|
|
|
nosql = UforaCourse(
|
|
|
|
code="E018130", name="NoSQL Databases", year=6, compulsory=False, role_id=1155491405955878973
|
|
|
|
)
|
|
|
|
|
|
|
|
secure_ss = UforaCourse(
|
|
|
|
code="E017950", name="Secure Software and Systems", year=6, compulsory=False, role_id=1155492095281340467
|
|
|
|
)
|
|
|
|
|
|
|
|
session.add_all(
|
|
|
|
[
|
|
|
|
bed_eco,
|
|
|
|
beg_eco,
|
|
|
|
big_data_tech,
|
|
|
|
cloud_storage,
|
|
|
|
criminologie,
|
|
|
|
data_quality,
|
|
|
|
data_vis_ai,
|
|
|
|
db_design,
|
|
|
|
finance_markets,
|
|
|
|
game_theory,
|
|
|
|
knowledge_graphs,
|
|
|
|
natural_language_processing,
|
|
|
|
nosql,
|
|
|
|
secure_ss,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
await session.commit()
|
|
|
|
|
|
|
|
# Aliases for new elective courses
|
|
|
|
datakwaliteit = UforaCourseAlias(course_id=data_quality.course_id, alias="Datakwaliteit")
|
|
|
|
devops = UforaCourseAlias(course_id=cloud_storage.course_id, alias="DevOps")
|
|
|
|
nlp = UforaCourseAlias(course_id=natural_language_processing.course_id, alias="NLP")
|
|
|
|
nlp_nl = UforaCourseAlias(course_id=natural_language_processing.course_id, alias="Natuurlijke Taalverwerking")
|
|
|
|
|
|
|
|
session.add_all([datakwaliteit, devops, nlp, nlp_nl])
|
|
|
|
|
|
|
|
await session.commit()
|