Avatar of oaktrees
oaktrees asked on

How to Edit This Python Script

Hi,

I can't figure out where and in what format to put the sorting parameters in this python code.

from .notes import isNew, isNotNew

nidToRand = dict()
def toTup(card, params):
    """A tuple to sort the card. See bothSched.sortCids to get more
    informations."""
    l = []
    for param in params:
        if isinstance(param, tuple):
            param, reverse = param
        else:
            reverse = False
        if param == "new first":
            val = (isNotNew(card.note()))#false occurs first in list
        elif param == "seen first":
            val = (isNew(card.note()))#false occurs first in list
        elif param in {"ord", "card position"}:
            val = (card.ord)
        elif param == "note creation":
            val = (card.nid)
        elif param == "card creation":
            val = (card.id)
        elif param == "mod":
            val = (card.note().mod)
        elif param == "note random":
            if card.nid not in nidToRand:
                nidToRand[card.nid] = random()
            val = nidToRand[card.nid]
        elif param == "card random":
            val = (random())
        if reverse:
            val = -val
        l.append(val)
    return tuple(l)

Open in new window


It is from here: https://github.com/Arthur-Milchior/anki_sort_cards
Python* AnkiProgrammingCOBOL

Avatar of undefined
Last Comment
noci

8/22/2022 - Mon
noci

What to edit?  Why to edit?

notepad, notpad++  or some other flat ascii file editor will do.

the code walks a list named params.....    for each param from the list it checks if is an item or tuple of: (param, reverse)  + string, boolean.

apparantly it determins a value val depending from cards/ random depending on param..      in the case of reverse ( a boolean) the value is negated.
It creates a list of values and returns that.
ASKER
oaktrees

Hi,

You wrote:
WHAT TO EDIT?  WHY TO EDIT?

According to the script it seems it needs a tuple added.  I need to edit the script to add the tuple so it can execute correctly.  That's the why.

The "What to edit?" is actually my question.  I need to know where in the script that should go, and how it should be coded.

The Script Says
"""A tuple to sort the card. See bothSched.sortCids to get more
    informations."""

The Config Says
Configuration
The configuration is given by a list of parameter, separated by commas. (Technically, this is a json list, where the enclosings and are omitted.)

Sorting is done according to first parameter. In case of equality according to second parameter. And so on. A paramater is either a string "rule", or a pair ("rule", False). (Link)

Thanks!

OT
ASKER CERTIFIED SOLUTION
noci

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23