@@ -89,6 +89,107 @@ def get_chat_messages(db_path: Path) -> Dict[str, Dict[str, Any]]:
8989 print (f"Error querying database: { e } " )
9090 raise
9191
92+ def get_submission_chats (db_path : Path ) -> Dict [str , Dict [str , Any ]]:
93+ """Query the SQLite database and extract all submission chats.
94+
95+ Args:
96+ db_path: Path to the SQLite database file
97+
98+ Returns:
99+ Dictionary with SubmissionChatID as keys and chat data as values
100+
101+ Raises:
102+ sqlite3.Error: If there's a database error
103+ Exception: For other unexpected errors
104+ """
105+ try :
106+ with sqlite3 .connect (db_path ) as conn :
107+ conn .row_factory = sqlite3 .Row
108+ cursor = conn .cursor ()
109+ cursor .execute ('SELECT * FROM results' )
110+
111+ chats = {}
112+ for row in cursor .fetchall ():
113+ row_dict = dict (row )
114+ chat_id = row_dict ['SubmissionChatID' ]
115+ chats [chat_id ] = row_dict
116+
117+ return chats
118+
119+ except sqlite3 .Error as e :
120+ print (f"SQLite error: { e } " )
121+ raise
122+ except Exception as e :
123+ print (f"Error querying database: { e } " )
124+ raise
125+
126+ def get_submissions (db_path : Path ) -> Dict [str , Dict [str , Any ]]:
127+ """Query the SQLite database and extract all submissions.
128+
129+ Args:
130+ db_path: Path to the SQLite database file
131+
132+ Returns:
133+ Dictionary with SubmissionID as keys and submission data as values
134+
135+ Raises:
136+ sqlite3.Error: If there's a database error
137+ Exception: For other unexpected errors
138+ """
139+ try :
140+ with sqlite3 .connect (db_path ) as conn :
141+ conn .row_factory = sqlite3 .Row
142+ cursor = conn .cursor ()
143+ cursor .execute ('SELECT * FROM results' )
144+
145+ submissions = {}
146+ for row in cursor .fetchall ():
147+ row_dict = dict (row )
148+ submission_id = row_dict ['SubmissionID' ]
149+ submissions [submission_id ] = row_dict
150+
151+ return submissions
152+
153+ except sqlite3 .Error as e :
154+ print (f"SQLite error: { e } " )
155+ raise
156+ except Exception as e :
157+ print (f"Error querying database: { e } " )
158+ raise
159+
160+ def get_users (db_path : Path ) -> Dict [str , Dict [str , Any ]]:
161+ """Query the SQLite database and extract all users.
162+
163+ Args:
164+ db_path: Path to the SQLite database file
165+
166+ Returns:
167+ Dictionary with UserID as keys and user data as values
168+
169+ Raises:
170+ sqlite3.Error: If there's a database error
171+ Exception: For other unexpected errors
172+ """
173+ try :
174+ with sqlite3 .connect (db_path ) as conn :
175+ conn .row_factory = sqlite3 .Row
176+ cursor = conn .cursor ()
177+ cursor .execute ('SELECT * FROM results' )
178+
179+ users = {}
180+ for row in cursor .fetchall ():
181+ row_dict = dict (row )
182+ user_id = row_dict ['UserID' ]
183+ users [user_id ] = row_dict
184+
185+ return users
186+
187+ except sqlite3 .Error as e :
188+ print (f"SQLite error: { e } " )
189+ raise
190+ except Exception as e :
191+ print (f"Error querying database: { e } " )
192+ raise
92193
93194def save_stats_to_json (data : Dict [str , Any ], output_path : Path ) -> None :
94195 """Save data to a JSON file.
0 commit comments