View Single Post
Old 04-24-2023, 03:21 PM   #5
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Since this is an old thread that predates the introduction of python templates by chaley, here is the python equivalent for the chaley's GPM template:

Code:
python:
def evaluate(book, context):
    vals = context.globals.get('highest_index_ids')
    if not vals:
        vals = context.globals['highest_index_ids'] = []
        db = context.db
        cats = db.new_api.get_categories(book_ids=None)
        all_series = [ t.name for t in cats['series'] ]
        for series in all_series:
            book_ids = db.data.search_getting_ids(f'series:"={series}"', '')
            indices = {}
            for book_id in book_ids:
                idx = db.new_api.field_for('series_index', book_id)
                indices[idx] = book_id
            vals.append(indices[max(indices.keys())])
    return '1' if book.id in vals else '0'
This should be a little faster.

Last edited by capink; 04-24-2023 at 04:27 PM.
capink is offline   Reply With Quote