feat: add documentation for ELSA and extend functionality, include new icons and update semester logic

This commit is contained in:
2024-12-10 11:24:04 +01:00
parent 7d78c09480
commit f84c030eea
17 changed files with 149 additions and 39 deletions

View File

@@ -11,7 +11,6 @@ from omegaconf import OmegaConf
from src.backend.db import (
CREATE_ELSA_FILES_TABLE,
CREATE_ELSA_MEDIA_TABLE,
CREATE_ELSA_PROF_TABLE,
CREATE_ELSA_TABLE,
CREATE_TABLE_APPARAT,
CREATE_TABLE_APPKONTOS,
@@ -1203,7 +1202,8 @@ class Database:
Returns:
list[str]: a list of all the roles
"""
return self.query_db("SELECT role FROM user")
roles = self.query_db("SELECT role FROM user")
return [i[0] for i in roles]
def checkUsername(self, user) -> bool:
"""a check to see if the username is already present in the database
@@ -1311,26 +1311,29 @@ class Database:
)
# ELSA
def createElsaProf(self, name):
"""create a new professor in the database for the ELSA system
Args:
name (str): the name of the professor
"""
self.query_db("INSERT INTO elsa_prof (name) VALUES (?)", (name,))
def createElsaApparat(self, date, prof_id, semester):
def createElsaApparat(self, date, prof_id, semester) -> int:
"""create a new apparat in the database for the ELSA system
Args:
date (str): the name of the apparat
prof_id (int): the id of the professor
semester (str): the semester the apparat is created in
Returns:
int: the id of the apparat
"""
self.query_db(
"INSERT OR IGNORE INTO elsa (date, prof_id, semester) VALUES (?,?,?)",
(date, prof_id, semester),
)
# get the id of the apparat
apparat_id = self.query_db(
"SELECT id FROM elsa WHERE date=? AND prof_id=? AND semester=?",
(date, prof_id, semester),
one=True,
)[0]
return apparat_id
def updateElsaApparat(self, date, prof_id, semester, elsa_id):
"""update an ELSA apparat in the database
@@ -1446,9 +1449,13 @@ class Database:
Returns:
int: the id of the ELSA apparat
"""
prof_id = self.getElsaProfId(prof)
if prof_id is None:
return None
data = self.query_db(
"SELECT id FROM elsa WHERE prof_id=? AND semester=? AND date=?",
(prof, semester, date),
(prof_id, semester, date),
one=True,
)
if data is None:
@@ -1497,22 +1504,7 @@ class Database:
if data:
return data[0][0]
else: return None
def createElsaProf(self, profname)-> int:
pId = self.getElsaProfId(profname)
if pId:
return pId
query = f"INSERT INTO elsa_prof (fullname) VALUES ('{profname}')"
self.query_db(query)
return self.getElsaProfId(profname)
def getElsaProf(self, prof_id)->str:
query = f"SELECT fullname FROM elsa_prof WHERE id = '{prof_id}'"
data = self.query_db(query)
if data:
return data[0][0]
else: return None
def getElsaProfs(self)->list[str]:
query = f"SELECT fullname FROM elsa_prof"
data = self.query_db(query)
@@ -1521,6 +1513,14 @@ class Database:
else: return []
def getProfId(self, profdata: dict|Prof):
"""Get the prof ID based on the profdata
Args:
profdata (dict | Prof): either a dictionary containing the prof data or a Prof object
Returns:
int | None: The id of the prof or None if not found
"""
conn = self.connect()
cursor = conn.cursor()
if isinstance(profdata, Prof):
@@ -1557,8 +1557,61 @@ class Database:
if result:
return Prof().from_tuple(result)
else: return Prof()
def getProfNameByApparat(self, apprarat_id):
query = f"SELECT prof_id from semesterapparat WHERE appnr = '{apprarat_id}'"
def getProfIDByApparat(self, apprarat_id):
"""Get the prof id based on the semesterapparat id from the database
Args:
apprarat_id (int): Number of the apparat
Returns:
int | None: The id of the prof or None if not found
"""
query = f"SELECT prof_id from semesterapparat WHERE id = '{apprarat_id}' and deletion_status = 0"
data = self.query_db(query)
if data:
return data[0][0]
else:
return None
def copyBookToApparat(self, book_id, apparat):
# get book data
new_apparat_id = apparat
new_prof_id = self.getProfIDByApparat(new_apparat_id)
query = f"""
INSERT INTO media (bookdata, app_id, prof_id, deleted, available, reservation)
SELECT
bookdata,
'{new_apparat_id}',
'{new_prof_id}',
0,
available,
reservation
FROM media
where id = '{book_id}'"""
connection = self.connect()
cursor = connection.cursor()
cursor.execute(query)
connection.commit()
connection.close()
def moveBookToApparat(self, book_id, appratat):
"""Move the book to the new apparat
Args:
book_id (int): the ID of the book
appratat (int): the ID of the new apparat
"""
# get book data
query = f"UPDATE media SET app_id = '{appratat}' WHERE id = '{book_id}'"
connection = self.connect()
cursor = connection.cursor()
cursor.execute(query)
connection.commit()
connection.close()
def getApparatNameByAppNr(self, appnr):
query = f"SELECT name FROM semesterapparat WHERE appnr = '{appnr}' and deletion_status = 0"
data = self.query_db(query)
if data:
return data[0][0]

View File

@@ -5,6 +5,7 @@ def generateSemesterByDate(next:bool = False):
currentYear = datetime.datetime.now().year
currentYear = int(str(currentYear)[-2:])
month = datetime.datetime.now().month
# month = month + 1
if next:
month += 1
if month > 12:
@@ -13,7 +14,7 @@ def generateSemesterByDate(next:bool = False):
if month >= 4 and month <= 9:
return "SoSe " + str(currentYear)
else:
if month == 10 or month == 11:
if month == any([10, 11, 12]):
return f"WiSe {currentYear}/{currentYear+1}"
else:
return f"WiSe {currentYear-1}/{currentYear}"
@@ -38,4 +39,8 @@ def generateSemesterByOffset(offset):
else:
return f"WiSe {currentYear+1}/{currentYear+2}"
else:
return f"WiSe {currentYear+offset//2}/{currentYear+1+offset//2}"
return f"WiSe {currentYear+offset//2}/{currentYear+1+offset//2}"
if __name__ == "__main__":
print(generateSemesterByDate(next=True))

View File

@@ -30,6 +30,11 @@ class Prof:
setattr(self, "telnr", data[6])
return self
def name(self, comma=False):
if comma:
return f"{self.lastname}, {self.firstname}"
return f"{self.lastname} {self.firstname}"
@dataclass
class ApparatData:

View File

@@ -33,15 +33,11 @@ class AutoAdder(QThread):
item = 0
for entry in self.data:
try:
# webdata = WebRequest().get_ppn(entry).get_data()
# bd = BibTextTransformer("ARRAY").get_data(webdata).return_data()
# bd.signature = entry
self.updateSignal.emit(item)
self.setTextSignal.emit(entry)
# qsleep
item += 1
self.progress.emit(item)
# print(item, len(self.data))
time.sleep(1)
except Exception as e: