From 99b518a432640a7a847192e6de5f7f2e7a8bfef4 Mon Sep 17 00:00:00 2001 From: clodman84 Date: Sun, 21 Jul 2024 16:02:11 +0530 Subject: [PATCH 1/3] added nickname support to the database --- Application/database.py | 2 +- Application/search.py | 6 ++++-- Data/schema.sql | 13 +++++++------ GUI/bill.py | 1 + 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Application/database.py b/Application/database.py index 2c832cb..2e637a7 100644 --- a/Application/database.py +++ b/Application/database.py @@ -77,7 +77,7 @@ def read_mess_list(path: Path): connection = connect() vals = [row for row in reader] connection.executemany( - "INSERT OR IGNORE INTO students VALUES(?, ?, ?, ?, ?, ?, ?)", vals[1:] + "INSERT OR IGNORE INTO students VALUES(?, ?, ?, ?, ?, ?, ?, NULL)", vals[1:] ) connection.commit() diff --git a/Application/search.py b/Application/search.py index 447f9d2..76dc07e 100644 --- a/Application/search.py +++ b/Application/search.py @@ -59,7 +59,7 @@ def set_or(x, y): class SearchMachine: def __init__(self) -> None: self.parser = parser() - self.fts_text = f"SELECT name, idno, hoscode, roomno FROM students WHERE rowid IN (SELECT rowid FROM students_fts WHERE name MATCH ? ORDER BY rank)" + self.fts_text = """SELECT name, idno, hoscode, roomno FROM students WHERE rowid IN (SELECT * from (SELECT rowid FROM students_fts WHERE name MATCH ? ORDER BY rank) UNION SELECT * from (SELECT rowid FROM students_fts WHERE nick MATCH ? ORDER BY rank))""" self.id_text = ( f"SELECT name, idno, hoscode, roomno from students WHERE idno LIKE ?" ) @@ -72,7 +72,9 @@ def __init__(self) -> None: def get_name(self, argument): with ConnectionPool() as db: - cursor = db.execute(self.fts_text, (argument,)) + cursor = db.execute( + self.fts_text, (argument, argument) + ) # argument, argument since the querry uses the search term twice :( return {tuple(item) for item in cursor} def get_id(self, argument): diff --git a/Data/schema.sql b/Data/schema.sql index a2a8d17..215af02 100644 --- a/Data/schema.sql +++ b/Data/schema.sql @@ -5,12 +5,13 @@ CREATE TABLE IF NOT EXISTS students( GENDER text, HOSCODE text, ROOMNO text, - PROG_ID int + PROG_ID int, + NICK text UNIQUE ); -- full text search capabilities for students DROP table IF EXISTS students_fts; -CREATE VIRTUAL TABLE students_fts USING fts5(NAME, IDNO UNINDEXED, content='students', tokenize='trigram'); +CREATE VIRTUAL TABLE students_fts USING fts5(NAME, NICK, IDNO UNINDEXED, content='students', tokenize='trigram'); DROP TRIGGER IF EXISTS students_ai; DROP TRIGGER IF EXISTS students_ad; @@ -18,14 +19,14 @@ DROP TRIGGER IF EXISTS students_au; -- Triggers to keep the FTS index up to date. CREATE TRIGGER students_ai AFTER INSERT ON students BEGIN - INSERT INTO students_fts(rowid, NAME, IDNO) VALUES (new.rowid, new.NAME , new.IDNO); + INSERT INTO students_fts(rowid, NAME, NICK, IDNO) VALUES (new.rowid, new.NAME , new.NICK, new.IDNO); END; CREATE TRIGGER students_ad AFTER DELETE ON students BEGIN - INSERT INTO students_fts(students_fts, rowid, NAME, IDNO) VALUES('delete', old.rowid, old.NAME, old.IDNO); + INSERT INTO students_fts(students_fts, rowid, NAME, NICK, IDNO) VALUES('delete', old.rowid, old.NAME, old.NICK, old.IDNO); END; CREATE TRIGGER students_au AFTER UPDATE ON students BEGIN - INSERT INTO students_fts(students_fts, rowid, NAME, IDNO) VALUES('delete', old.rowid, old.NAME, old.IDNO); - INSERT INTO students_fts(rowid, NAME, IDNO) VALUES (new.rowid, new.NAME, new.IDNO); + INSERT INTO students_fts(students_fts, rowid, NAME, NICK, IDNO) VALUES('delete', old.rowid, old.NAME, old.NICK, old.IDNO); + INSERT INTO students_fts(rowid, NAME, NICK, IDNO) VALUES (new.rowid, new.NAME, new.NICK, new.IDNO); END; INSERT INTO students_fts(students_fts) VALUES('rebuild'); diff --git a/GUI/bill.py b/GUI/bill.py index 7c0c591..78fc2df 100644 --- a/GUI/bill.py +++ b/GUI/bill.py @@ -67,6 +67,7 @@ def export(self): def suggest(self, sender, app_data, user_data): if len(app_data) > 0: matches = self.search_machine.search(app_data) + logger.info(matches) else: return From c6423404b51ee49fde2c069475b899b24b3077b0 Mon Sep 17 00:00:00 2001 From: clodman84 Date: Sun, 21 Jul 2024 16:07:06 +0530 Subject: [PATCH 2/3] removed useless log statement --- GUI/bill.py | 1 - 1 file changed, 1 deletion(-) diff --git a/GUI/bill.py b/GUI/bill.py index 78fc2df..7c0c591 100644 --- a/GUI/bill.py +++ b/GUI/bill.py @@ -67,7 +67,6 @@ def export(self): def suggest(self, sender, app_data, user_data): if len(app_data) > 0: matches = self.search_machine.search(app_data) - logger.info(matches) else: return From 1ae75a1c9243f75e88c479368c49152ce7a4b8a1 Mon Sep 17 00:00:00 2001 From: clodman84 Date: Mon, 22 Jul 2024 14:08:27 +0530 Subject: [PATCH 3/3] added dev tools in the gui --- main.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.py b/main.py index 7542167..da30f6f 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from pathlib import Path import dearpygui.dearpygui as dpg +from dearpygui import demo import Application import GUI @@ -86,6 +87,14 @@ def main(): dpg.add_menu_item( label="Show Performance Metrics", callback=dpg.show_metrics ) + with dpg.menu(label="Dev"): + dpg.add_menu_item( + label="Spawn Billing Window", + callback=lambda: GUI.BillingWindow( + roll="Dev", path=Path("Data/Dev") + ), + ) + dpg.add_menu_item(label="Show GUI Demo", callback=demo.show_demo) dpg.add_button( label="Music",