def getCreatedSameDay(index, editor, nid): stamp = utility.misc.get_milisec_stamp() index.ui.latest = stamp index.lastSearch = (nid, None, "createdSameDay") try: nidMinusOneDay = nid - (24 * 60 * 60 * 1000) nidPlusOneDay = nid + (24 * 60 * 60 * 1000) res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where nid > %s and nid < %s order by nid desc" % (nidMinusOneDay, nidPlusOneDay)).fetchall() dayOfNote = int(time.strftime("%d", time.localtime(nid / 1000))) rList = [] c = 0 for r in res: dayCreated = int( time.strftime("%d", time.localtime(int(r[0]) / 1000))) if dayCreated != dayOfNote: continue if not str(r[0]) in index.pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) c += 1 if c >= index.limit: break if check_index(): if len(rList) > 0: index.ui.print_search_results(rList, stamp, editor) else: index.ui.empty_result("No results found.") except: if check_index(): index.ui.empty_result("Error in calculation.")
def getLastModifiedNotes(index, editor, decks, limit): stamp = utility.misc.get_milisec_stamp() index.ui.latest = stamp index.lastSearch = (None, decks, "lastModified") if not "-1" in decks and len(decks) > 0: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if len(deckQ) > 0: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid where did in %s order by notes.mod desc limit %s" % (deckQ, limit)).fetchall() else: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid order by notes.mod desc limit %s" % (limit)).fetchall() rList = [] for r in res: if not str(r[0]) in index.pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) if check_index(): if len(rList) > 0: index.ui.print_search_results(rList, stamp, editor) else: index.ui.empty_result("No results found.")
def getCreatedNotesOrderedByDate(index, editor, decks, limit, sortOrder): stamp = utility.misc.get_milisec_stamp() index.ui.latest = stamp if sortOrder == "desc": index.lastSearch = (None, decks, "lastCreated", limit) else: index.lastSearch = (None, decks, "firstCreated", limit) if not "-1" in decks and len(decks) > 0: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if len(deckQ) > 0: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where did in %s order by nid %s limit %s" % (deckQ, sortOrder, limit)).fetchall() else: res = mw.col.db.execute( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid order by nid %s limit %s" % (sortOrder, limit)).fetchall() rList = [] for r in res: #pinned items should not appear in the results if not str(r[0]) in index.pinned: #todo get refs rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) if check_index(): if len(rList) > 0: index.ui.print_search_results(rList, stamp, editor) else: index.ui.empty_result("No results found.")
def get_notes_by_created_date(index, editor, decks, limit, sortOrder) -> List[IndexNote]: if sortOrder == "desc": index.lastSearch = (None, decks, "lastCreated", limit) else: index.lastSearch = (None, decks, "firstCreated", limit) if not "-1" in decks and len(decks) > 0: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if len(deckQ) > 0: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where did in %s order by nid %s limit %s" % (deckQ, sortOrder, limit)) else: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid order by nid %s limit %s" % (sortOrder, limit)) rList = [] for r in res: #pinned items should not appear in the results if not str(r[0]) in index.pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def get_created_same_day(nid, pinned, limit) -> List[IndexNote]: try: nidMinusOneDay = nid - (24 * 60 * 60 * 1000) nidPlusOneDay = nid + (24 * 60 * 60 * 1000) res = mw.col.db.all( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where nid > %s and nid < %s order by nid desc" % (nidMinusOneDay, nidPlusOneDay)) dayOfNote = int(time.strftime("%d", time.localtime(nid / 1000))) rList = [] c = 0 for r in res: dayCreated = int( time.strftime("%d", time.localtime(int(r[0]) / 1000))) if dayCreated != dayOfNote: continue if not str(r[0]) in pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) c += 1 if c >= limit: break return rList except: return []
def findNotesWithHighestPerformance(decks, limit, pinned, retOnly=False): scores = _calcScores(decks, limit, retOnly) scores = sorted(scores.items(), key=lambda x: x[1][0], reverse=True) rList = [] c = 0 for r in scores: if str(r[1][1][0]) not in pinned: rList.append(IndexNote((r[1][1][0], r[1][1][2], r[1][1][3], r[1][1][4], r[1][1][2], -1, r[1][1][5], "", -1))) c += 1 if c >= limit: break return rList
def getByTimeTaken(decks: List[int], limit: int, mode: str) -> List[IndexNote]: deckQ = _deck_query(decks) if deckQ: cmd = "with cr as (select cards.nid, cards.id, cards.did, revlog.time, revlog.id as rid, revlog.ease from revlog join cards on cards.id = revlog.cid) select distinct notes.id, flds, tags, cr.did, notes.mid, avg(cr.time) as timeavg from notes join cr on notes.id = cr.nid where cr.ease = 1 and cr.did in %s group by cr.nid order by timeavg %s limit %s" % ( deckQ, mode, limit) else: cmd = "with cr as (select cards.nid, cards.id, cards.did, revlog.time, revlog.id as rid, revlog.ease from revlog join cards on cards.id = revlog.cid) select distinct notes.id, flds, tags, cr.did, notes.mid, avg(cr.time) as timeavg from notes join cr on notes.id = cr.nid where cr.ease = 1 group by cr.nid order by timeavg %s limit %s" % ( mode, limit) res = mw.col.db.all(cmd) rList = [] for r in res: #rList.append((r[1], r[2], r[3], r[0], 1, r[4], "")) rList.append(IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def getSortedByInterval(decks, limit, pinned, sortOrder): if not "-1" in decks: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if deckQ: res = mw.col.db.all("select notes.id, flds, tags, did, cards.nid, notes.mid FROM cards left join notes on cards.nid = notes.id where did in %s and reps > 0 group by cards.nid order by ivl %s limit %s" % ( deckQ, sortOrder, limit)) else: res = mw.col.db.all("select notes.id, flds, tags, did, cards.nid, notes.mid FROM cards left join notes on cards.nid = notes.id where reps > 0 group by cards.nid order by ivl %s limit %s" % ( sortOrder, limit)) rList = [] for r in res: if not str(r[0]) in pinned: #. rList.append((r[1], r[2], r[3], r[0], 1, r[5])) rList.append(IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def getByTimeTaken(decks, limit, mode): if decks is not None and len(decks) > 0 and not "-1" in decks: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if deckQ: cmd = "with cr as (select cards.nid, cards.id, cards.did, revlog.time, revlog.id as rid, revlog.ease from revlog join cards on cards.id = revlog.cid) select distinct notes.id, flds, tags, cr.did, notes.mid, avg(cr.time) as timeavg from notes join cr on notes.id = cr.nid where cr.ease = 1 and cr.did in %s group by cr.nid order by timeavg %s limit %s" % ( deckQ, mode, limit) else: cmd = "with cr as (select cards.nid, cards.id, cards.did, revlog.time, revlog.id as rid, revlog.ease from revlog join cards on cards.id = revlog.cid) select distinct notes.id, flds, tags, cr.did, notes.mid, avg(cr.time) as timeavg from notes join cr on notes.id = cr.nid where cr.ease = 1 group by cr.nid order by timeavg %s limit %s" % ( mode, limit) res = mw.col.db.execute(cmd).fetchall() rList = [] for r in res: #rList.append((r[1], r[2], r[3], r[0], 1, r[4], "")) rList.append(IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def get_last_modified_notes(index, decks: List[int], limit: int) -> List[IndexNote]: deckQ = _deck_query(decks) if len(deckQ) > 0: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid where did in %s order by notes.mod desc limit %s" % (deckQ, limit)) else: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid order by notes.mod desc limit %s" % (limit)) rList = [] for r in res: if not str(r[0]) in index.pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def findNotesWithLongestText(decks, limit, pinned) -> List[IndexNote]: deckQ = _deck_query(decks) if pinned is None: pinned = [] if len(deckQ) > 0: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid where did in %s order by length(replace(trim(flds), '\u001f', '')) desc limit %s" % (deckQ, limit)) else: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, mid from notes left join cards on notes.id = cards.nid order by length(replace(trim(flds), '\u001f', '')) desc limit %s" % (limit)) rList = [] for r in res: #pinned items should not appear in the results if not str(r[0]) in pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def get_last_modified_notes(index, editor, decks, limit): if not "-1" in decks and len(decks) > 0: deckQ = "(%s)" % ",".join(decks) else: deckQ = "" if len(deckQ) > 0: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid where did in %s order by notes.mod desc limit %s" % (deckQ, limit)) else: res = mw.col.db.all( "select distinct notes.id, flds, tags, did, notes.mid, notes.mod from notes left join cards on notes.id = cards.nid order by notes.mod desc limit %s" % (limit)) rList = [] for r in res: if not str(r[0]) in index.pinned: rList.append( IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], ""))) return rList
def to_notes(db_list): return list( map(lambda r: IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], "")), db_list))
def to_notes(db_list: List[Tuple[Any]]) -> List[IndexNote]: return list( map(lambda r: IndexNote((r[0], r[1], r[2], r[3], r[1], -1, r[4], "")), db_list))