Skip to content

index score column and faster row counting #12

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/base/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Molecule(db.Model, Serializer):

smi = Column(PickleType) # pickled smiles string
mol = Column(PickleType) # pickled molblock
score = Column(Float)
score = Column(Float, index=True)
ifp = Column(PickleType)
inters = Column(JSON)
meta = Column(JSON)
Expand Down
9 changes: 5 additions & 4 deletions app/base/molecule_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import json
import numpy as np

from sqlalchemy import desc, and_, or_
from sqlalchemy import desc, and_, or_, func
from sqlalchemy.sql import exists, false
from sqlalchemy.orm.exc import NoResultFound

Expand Down Expand Up @@ -53,7 +53,7 @@ def get_molecule_by_id(mol_id, return_grade = False, return_pred = False, party_
def get_ordered_molecules(screen_id, party_id, name = None, orderby = "score", mode = "annotate", modetime = None,
limit = None, offset = None):

all_mols = db.session.query(Molecule).all()
# all_mols = db.session.query(Molecule).all()

"""
Return molecules that do NOT already have grades, sorted by requested method
Expand Down Expand Up @@ -82,12 +82,13 @@ def get_ordered_molecules(screen_id, party_id, name = None, orderby = "score", m
query = query.outerjoin(Prediction
).filter(Prediction.hp_settings_id == party_id)

unordered_mols = query.offset(offset).limit(limit).all()
# unordered_mols = query.offset(offset).limit(limit).all()

# decide ordering - either score, uncertainty, prediction, or disagreement(error)
if orderby != 'name':
query = query.order_by(*orderby_dict[orderby])
total = query.count()
total = db.session.query(func.count(Molecule.id)).filter(Molecule.run_id == screen_id).filter(~exclude).scalar()


mols = query.offset(offset).limit(limit).all()

Expand Down