v.0.13

On 2022.12.23

This version has been deprecated. If used with the current API version it can produce unexpected behaviour or errors.

The package shimoku-api-python is no longer maintained

pip install --upgrade shimoku-api-python

This version is another small upgrade with some fixes and new plots. The next versions will bring key features and quality of life upgrades!

Fixes

  • Now the horizontal barchart and zero centered barchart follow the Shimoku style of plots and don't ignore the axis name parameters:

  • When passing the access token to the initialization function it returns an appropiate error.

    Executing this code:

    universe_id: str = getenv('UNIVERSE_ID')
    
    s = Shimoku.Client(
        access_token=None,
        universe_id=universe_id,
    )

    the resulting error is:

Improvements

  • Has been added a type of input conditionally dependent on other input results. To use it, the name of the parent input has to be inculded as the parameter 'dependsOn' of the child, like so:

    report_dataset_properties = {
        'fields': [{
                'title': 'Conditional input form',
                'fields': [
                    {
                        'mapping': 'country',
                        'fieldName': 'Country',
                        'inputType': 'select',
                        'options': ['España', 'Colombia']
                    },
                    {
                        'dependsOn': 'Country',
                        'mapping': 'city',
                        'fieldName': 'City',
                        'inputType': 'select',
                        'options': {
                            'España': ['Madrid', 'Barcelona'],
                            'Colombia': ['Bogotá', 'Medellin']
                        }
                    }
                ]
            }
        ]
    }
    s.plt.input_form(
        menu_path='test/input-form', order=0,
        report_dataset_properties=report_dataset_properties
    )

    When the input has the parameter 'dependsOn', it has to define a set of options for every option in the parent input. In the case shown above the parent input has the options: 'España', 'Colombia', so the child input defines the list ['Madrid', 'Barcelona'] for 'España' and ['Bogotá', 'Medellin'] for 'Colombia'. The result is:

  • Now multiple input groups can be chained so that they are shown sequentially, through the use of a button. To use this feature the function s.plt.generate_input_form_groups has to be used. It eases the creation of multiple input forms groups, the user just has to define a dictionary where each key is the name of the group and the value is the list of input components. To activate the sequential show, the parameter dynamic_sequential_show has to be set to True.

    The following example:

    form_groups = {f'form group {i}': [{
                    'mapping': 'country',
                    'fieldName': f'Country {i}',
                    'inputType': 'select',
                    'options': ['España', 'Colombia']
                  },
                  {
                    'dependsOn': f'Country {i}',
                    'mapping': 'city',
                    'fieldName': f'City {i}',
                    'inputType': 'select',
                    'options': {
                        'España': ['Madrid', 'Barcelona'],
                        'Colombia': ['Bogotá', 'Medellin']
                    }
                  }] for i in range(4)}
    
    form_groups['Personal information'] = \
        [
            {
                'mapping': 'name',
                'fieldName': 'name',
                'inputType': 'text',
            },
            {
                'mapping': 'surname',
                'fieldName': 'surname',
                'inputType': 'text',
            },
            {
                'mapping': 'age',
                'fieldName': 'age',
                'inputType': 'number',
            },
            {
                'mapping': 'tel',
                'fieldName': 'phone',
                'inputType': 'tel',
            },
            {
                'mapping': 'gender',
                'fieldName': 'Gender',
                'inputType': 'radio',
                'options': ['Male', 'Female', 'No-binary', 'Undefined'],
            },
            {
                'mapping': 'email',
                'fieldName': 'email',
                'inputType': 'email',
            },
        ]
    
    form_groups['Other data'] = \
        [
            {
                'mapping': 'skills',
                'fieldName': 'Skills',
                'options': ['Backend', 'Frontend', 'UX/UI', 'Api Builder', 'DevOps'],
                'inputType': 'checkbox',
            },
            {
                'mapping': 'birthDay',
                'fieldName': 'Birthday',
                'inputType': 'date',
            },
            {
                'mapping': 'onCompany',
                'fieldName': 'Time on Shimoku',
                'inputType': 'dateRange',
            },
            {
                'mapping': 'hobbies',
                'fieldName': 'Hobbies',
                'inputType': 'select',
                'options': ['Make Strong Api', 'Sailing to Canarias', 'Send Abracitos'],
            },
            {
                'mapping': 'textField2',
                'fieldName': 'Test Text',
                'inputType': 'text',
            },
            {
                'mapping': 'objectives',
                'fieldName': 'Objetivos',
                'inputType': 'multiSelect',
                'options': ['sleep', 'close eyes', 'awake']
            }
        ]
    
    s.plt.generate_input_form_groups(
        menu_path='test/input-form', order=0,
        form_groups=form_groups,
        dynamic_sequential_show=True
    )

    results in:

  • Two derivative plots from the stacked barchart have been added! This are the horizontal stacked barchart and the stacked area chart, they have the same functionalities as the stacked barchart from v.0.12. This chart now preserve the order of the data, so they will show the data on the dashboard the same way it is ordered in the SDK call. The toolbox has been moved to the bottom right of these plots for visibility's sake.

    Using the same data as the stacked barchart example:

    menu_path = 'test/horizontal_stacked_distribution'
    data_ = pd.read_csv('../data/test_stack_distribution.csv')
    
    s.plt.stacked_horizontal_barchart(
        data=data_,
        menu_path=menu_path,
        x="Segment",
        x_axis_name='Distribution and weight of the Drivers',
        order=0,
    )
    
    s.plt.stacked_horizontal_barchart(
        data=data_,
        menu_path=menu_path,
        x="Segment",
        x_axis_name='Distribution and weight of the Drivers',
        order=1,
        show_values=['Price'],
        calculate_percentages=True,
    )

    The result is:

    And the stacked area chart follows the same pattern, after executing the following code:

    menu_path = 'test/stacked-area-chart'
    data_ = [
        {'Weekday': 'Mon', 'Email': 120, 'Union Ads': 132, 'Video Ads': 101, 'Search Engine': 134},
        {'Weekday': 'Tue', 'Email': 220, 'Union Ads': 182, 'Video Ads': 191, 'Search Engine': 234},
        {'Weekday': 'Wed', 'Email': 150, 'Union Ads': 232, 'Video Ads': 201, 'Search Engine': 154},
        {'Weekday': 'Thu', 'Email': 820, 'Union Ads': 932, 'Video Ads': 901, 'Search Engine': 934},
        {'Weekday': 'Fri', 'Email': 120, 'Union Ads': 132, 'Video Ads': 101, 'Search Engine': 134},
        {'Weekday': 'Sat', 'Email': 220, 'Union Ads': 182, 'Video Ads': 191, 'Search Engine': 234},
        {'Weekday': 'Sun', 'Email': 150, 'Union Ads': 232, 'Video Ads': 201, 'Search Engine': 154},
    ]
    
    s.plt.stacked_area_chart(
        data=data_,
        menu_path=menu_path,
        x="Weekday",
        x_axis_name='Visits per weekday',
        order=0,
    )
    
    s.plt.stacked_area_chart(
        data=data_,
        menu_path=menu_path,
        x="Weekday",
        x_axis_name='Visits per weekday',
        order=1,
        show_values=['Search Engine', 'Union Ads'],
        calculate_percentages=True,
    )

    The result is:

  • The doughnut chart has been added! It uses the same principle as the pie chart, where more degrees mean a bigger value, but it has an empty center and it shows the name of the category when the mouse hovers above one of the sectors. It has the option to have rounded edges or hard edges, find your fit!

    The function needs to know which columns are the 'name' and the 'value', by default it will use the strings 'name' and 'value' respectively, but this can be changed setting the parameters name and value to the desired strings.

    An example on how to use it is:

    menu_path = 'test/doughnut'
    data_ = [
        {'value': 1048, 'name': 'Search Engine'},
        {'value': 735, 'name': 'Direct'},
        {'value': 580, 'name': 'Email'},
        {'value': 484, 'name': 'Union Ads'},
        {'value': 300, 'name': 'Video Ads'}
    ]
    s.plt.doughnut(data_, menu_path=menu_path, order=0)
    s.plt.doughnut(data_, menu_path=menu_path, order=1, rounded=False)
    
    # Same data as for the stacked barcharts
    df = pd.read_csv('../data/test_stack_distribution.csv')
    doughnut_data = pd.DataFrame(columns=["name", "value"])
    df_transposed = df.transpose().reset_index().drop(0)
    value_columns = [col for col in df_transposed.columns if col != "index"]
    doughnut_data["value"] = df_transposed[value_columns].apply(lambda row: sum(row), axis=1)
    doughnut_data["name"] = df_transposed['index']
    s.plt.doughnut(doughnut_data, menu_path=menu_path, order=2,
                   rows_size=3, cols_size=6)

    Resulting in:

    The last plot that has been added is the rose chart! This chart is very similar to the doughnut chart but instead of being the sectors degrees indicating the size of the value, it is the radius of the sector, this means that all sectors are equal in width but vary in height.

    After executing the following code:

    menu_path = 'test/rose'
    data_ = [
        {'value': 1048, 'name': 'Search Engine'},
        {'value': 735, 'name': 'Direct'},
        {'value': 580, 'name': 'Email'},
        {'value': 484, 'name': 'Union Ads'},
        {'value': 300, 'name': 'Video Ads'}
    ]
    s.plt.rose(data_, menu_path=menu_path, order=0)
    s.plt.rose(data_, menu_path=menu_path, order=1, rounded=False)
    
    # Same data as for the stacked barcharts
    df = pd.read_csv('../data/test_stack_distribution.csv')
    rose_data = pd.DataFrame(columns=["name", "value"])
    df_transposed = df.transpose().reset_index().drop(0)
    value_columns = [col for col in df_transposed.columns if col != "index"]
    rose_data["value"] = df_transposed[value_columns].apply(lambda row: sum(row), axis=1)
    rose_data["name"] = df_transposed['index']
    s.plt.rose(rose_data, menu_path=menu_path, order=2,
               rows_size=3, cols_size=6)

    The result is:

Last updated