-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #79, Testing Current Score #84
Draft
JolanThomassin
wants to merge
2
commits into
main
Choose a base branch
from
issue#79-testing-current-score
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,39 @@ def get_random_chunk(cursor, schema_version, seed=None): | |
|
||
cursor.execute(query) | ||
return cursor.fetchall() | ||
|
||
|
||
def get_random_document_score(cursor, schema_version, seed=None): | ||
if seed is None: | ||
seed = math.sin(time.time()) | ||
|
||
# Execute the SET commands separately | ||
cursor.execute(f'SET SEARCH_PATH TO "{schema_version}", public;') | ||
cursor.execute(f"SET SEED TO {seed};") | ||
|
||
query = """ | ||
WITH random_crawl AS ( | ||
SELECT id | ||
FROM crawl | ||
ORDER BY | ||
floor(random() * ( | ||
SELECT | ||
COUNT(*) | ||
FROM | ||
Chunk | ||
)) | ||
LIMIT | ||
1 | ||
) | ||
SELECT | ||
cr.id AS crawl_id, cr.url AS crawl_url, sc.score, sc.score_type | ||
FROM | ||
crawl cr | ||
INNER JOIN | ||
score sc ON cr.id = sc.entity_id | ||
WHERE | ||
cr.id = (SELECT id FROM random_crawl) | ||
""" | ||
|
||
cursor.execute(query) | ||
return cursor.fetchall() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EOF newline There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this should be validated by the repo standards check) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import ailab.db as db | ||
|
||
from ailab.db.finesse.test_queries import get_random_document_score | ||
|
||
|
||
class NoChunkFoundError(Exception): | ||
pass | ||
|
||
|
||
## This is a comment. | ||
def evaluate_random_document(project_db): | ||
|
||
if project_db is None: | ||
print("Database connection failed.") | ||
return None | ||
|
||
with project_db.cursor() as cursor: | ||
|
||
random_chunk = get_random_document_score(cursor, "louis_v005") | ||
|
||
if not random_chunk: | ||
raise NoChunkFoundError("No chunk found in the database.") | ||
|
||
print("\n-------------") | ||
print("crawl_id:", random_chunk[0]["crawl_id"]) | ||
print("crawl_url:", random_chunk[0]["crawl_url"]) | ||
print("\n") | ||
|
||
print("-------------") | ||
for chunk in random_chunk: | ||
print("score_type:", chunk["score_type"]) | ||
print("score:", chunk["score"]) | ||
print("\n") | ||
|
||
return | ||
|
||
|
||
|
||
def main(): | ||
project_db = db.connect_db() | ||
evaluate_random_document(project_db) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
DIRNAME=$(dirname "$0") | ||
. "$DIRNAME"/lib.sh | ||
|
||
|
||
PYTHONPATH=$PROJECT_DIR python "$DIRNAME"/testing-current-score.py |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this came up before; ordering randomly the table is expensive means you are fetching every row and then picking up one.
it's cheaper to pick a row between 1 and count(*) and use that with OFFSET combined with LIMIT:
https://www.postgresql.org/docs/current/queries-limit.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you told me about that, when I copy paste the query I forgot to change
ORDER
byOFFSET
. It will be changed soon.