Spaces:
Runtime error
Runtime error
for now limit the view of questions to the first group id until we fix the ui to support multiple question groups
Browse files- data_access.py +1 -1
- scripts/eval_tables.py +14 -9
data_access.py
CHANGED
|
@@ -34,7 +34,7 @@ async def get_async_connection(schema="talmudexplore"):
|
|
| 34 |
|
| 35 |
|
| 36 |
async def get_questions(conn: asyncpg.Connection):
|
| 37 |
-
questions = await conn.fetch("SELECT id, question_text FROM questions ORDER BY id")
|
| 38 |
return [{"id": q["id"], "text": q["question_text"]} for q in questions]
|
| 39 |
|
| 40 |
@cached(cache=TTLCache(ttl=1800, maxsize=1024))
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
async def get_questions(conn: asyncpg.Connection):
|
| 37 |
+
questions = await conn.fetch("SELECT id, question_text FROM questions where question_group_id = 1 ORDER BY id")
|
| 38 |
return [{"id": q["id"], "text": q["question_text"]} for q in questions]
|
| 39 |
|
| 40 |
@cached(cache=TTLCache(ttl=1800, maxsize=1024))
|
scripts/eval_tables.py
CHANGED
|
@@ -8,14 +8,23 @@ def create_eval_database():
|
|
| 8 |
"""Create SQLite database with a proper relational structure."""
|
| 9 |
# Connect to the database (creates it if it doesn't exist)
|
| 10 |
cursor = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Create questions table
|
| 13 |
cursor.execute('''
|
| 14 |
CREATE TABLE IF NOT EXISTS questions (
|
| 15 |
id SERIAL PRIMARY KEY,
|
| 16 |
question_text TEXT NOT NULL,
|
| 17 |
-
|
| 18 |
-
)
|
|
|
|
| 19 |
''')
|
| 20 |
|
| 21 |
|
|
@@ -45,7 +54,7 @@ def create_eval_database():
|
|
| 45 |
question_id INTEGER NOT NULL,
|
| 46 |
source_finder_run_id INTEGER NOT NULL,
|
| 47 |
metadata JSON,
|
| 48 |
-
FOREIGN KEY (source_finder_run_id) REFERENCES source_finder_runs(id),
|
| 49 |
FOREIGN KEY (question_id) REFERENCES questions(id),
|
| 50 |
CONSTRAINT unique_question_per_run_id UNIQUE(question_id, source_finder_run_id)
|
| 51 |
);
|
|
@@ -65,15 +74,11 @@ def create_eval_database():
|
|
| 65 |
rank INTEGER NOT NULL,
|
| 66 |
reason TEXT,
|
| 67 |
FOREIGN KEY (source_finder_run_id) REFERENCES source_finder_runs(id),
|
| 68 |
-
FOREIGN KEY (question_id) REFERENCES questions(id)
|
|
|
|
| 69 |
);
|
| 70 |
''')
|
| 71 |
|
| 72 |
-
cursor.execute('''alter table source_run_results
|
| 73 |
-
add constraint source_run_results_pk
|
| 74 |
-
unique (source_finder_run_id, question_id, sugya_id);
|
| 75 |
-
''')
|
| 76 |
-
|
| 77 |
conn.commit()
|
| 78 |
conn.close()
|
| 79 |
|
|
|
|
| 8 |
"""Create SQLite database with a proper relational structure."""
|
| 9 |
# Connect to the database (creates it if it doesn't exist)
|
| 10 |
cursor = conn.cursor()
|
| 11 |
+
cursor.execute('''
|
| 12 |
+
CREATE TABLE IF NOT EXISTS question_groups (
|
| 13 |
+
id SERIAL PRIMARY KEY,
|
| 14 |
+
group_name TEXT NOT NULL,
|
| 15 |
+
description TEXT
|
| 16 |
+
);
|
| 17 |
+
''')
|
| 18 |
+
|
| 19 |
|
| 20 |
# Create questions table
|
| 21 |
cursor.execute('''
|
| 22 |
CREATE TABLE IF NOT EXISTS questions (
|
| 23 |
id SERIAL PRIMARY KEY,
|
| 24 |
question_text TEXT NOT NULL,
|
| 25 |
+
question_group_id INTEGER,
|
| 26 |
+
CONSTRAINT unique_question_text UNIQUE (question_text),
|
| 27 |
+
FOREIGN KEY (question_group_id) REFERENCES question_groups (id);
|
| 28 |
''')
|
| 29 |
|
| 30 |
|
|
|
|
| 54 |
question_id INTEGER NOT NULL,
|
| 55 |
source_finder_run_id INTEGER NOT NULL,
|
| 56 |
metadata JSON,
|
| 57 |
+
FOREIGN KEY (source_finder_run_id) REFERENCES source_finder_runs(id),d4pnrdvjqlt9gg
|
| 58 |
FOREIGN KEY (question_id) REFERENCES questions(id),
|
| 59 |
CONSTRAINT unique_question_per_run_id UNIQUE(question_id, source_finder_run_id)
|
| 60 |
);
|
|
|
|
| 74 |
rank INTEGER NOT NULL,
|
| 75 |
reason TEXT,
|
| 76 |
FOREIGN KEY (source_finder_run_id) REFERENCES source_finder_runs(id),
|
| 77 |
+
FOREIGN KEY (question_id) REFERENCES questions(id),
|
| 78 |
+
CONSTRAINT constraint source_run_results_pk UNIQUE(source_finder_run_id, question_id, sugya_id)
|
| 79 |
);
|
| 80 |
''')
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
conn.commit()
|
| 83 |
conn.close()
|
| 84 |
|