Quantipy / quantipy

Python for people data
MIT License
66 stars 14 forks source link

Block nets need text_keys and textual representation #75

Closed jamesrkg closed 8 years ago

jamesrkg commented 9 years ago

Block nets are currently done like this:

net_views.add_method(
    name='Top_Middle_Bottom',
    kwargs={
        'logic': [
            {'Top 2 Box': frange('9,10')},
            {'Middle 3 Box': frange('6-8')},
            {'Bottom 5 Box': frange('1-5')}]})

But the problem here is the lack of a conventional text object that supports multiple labels via text_key. All labels in Quantipy must provide multi-label support.

To that end we should implement a block- kwarg for defning multiple uses of the same method that are returned in a single group.

The following example shows the first of these we need to implement: block-logic.

net_views.add_method(
    name='Top_Middle_Bottom',
    kwargs={
        'block-logic': {
            'items': [
                {'top2': frange('9,10'), 'text': {'main': 'Top 2 Box'}},
                {'mid3': frange('6-8'), 'text': {'main': 'Middle 3 Box'}},
                {'bot5': frange('1-5'), 'text': {'main': 'Bottom 5 Box'}}]}})

The -logic part of the block- kwarg informs how the content of the items object should be interpreted. This allows the textual representation of each item to be given in place of where 'logic' would normally appear, so that 'top2': frange('9,10') is read as 'logic': frange('9,10') with the textual representation top2.

The unpainted version of the resulting dataframe will show an index with the values 'top2', 'mid3' and 'bot5'. When painted those representations will be translated by the given text_key as per any normal data value from a single or delimited set column.

The block- kwarg needs to itself be a dict with an items object to provide space for additional instructions, such as rules and additional custom properties.

jamesrkg commented 8 years ago

This will be resolved by #290.