コード例 #1
0
def faceoff_overview_chart(logger, ctitle, ismobile, data_dic):
    """ create chart 5v5 pace """
    # pylint: disable=E0602
    logger.debug('faceoff_overview_chart()')

    variable_dic = variables_get(ismobile)

    chart_options = {

        'chart': {
            'type': 'scatter',
            'height': '80%',
            'style': chartstyle()
        },

        'exporting': exporting(filename=ctitle),
        'title': title(ctitle, variable_dic['title_size'], decoration=True),
        'credits': credit(),
        'legend': legend(enabled=1),
        'responsive': responsive_y1(),

        'tooltip': {
            'useHTML': 1,
            'headerFormat': '',
            'pointFormat': '<span><b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.sum_faceoffswon}</span><br><span style="font-size: %s">%s: {point.sum_faceoffslost}</span><br/><span style="font-size: %s">%s: {point.y}</span><br/>' % (font_size, _('Faceoffs won'), font_size, _('Faceoffs lost'), font_size, _('Faceoffs win percentage'))
        },

        'xAxis': {
            'labels': {
                'enabled': 0
            },
            'tickInterval': 0,
        },

        'yAxis': {
            'title': title(ctitle, font_size),
            # 'tickInterval': 1,
            'maxPadding': 0.1,
            'min': data_dic['y_min_minmax'] - 2,
            'max': data_dic['y_max_minmax'] + 2,
            'labels': {'style': {'fontSize': font_size},},
            'gridLineWidth': 1,
            'plotBands': [{'from': data_dic['y_avg'] - data_dic['y_deviation']/2, 'to': data_dic['y_avg'] + data_dic['y_deviation']/2, 'color': chart_color6}],
            'plotLines': [{'zIndex': 3, 'color': plotlines_color, 'width': 2, 'value': data_dic['y_avg']}],
        },

        'series': [{'zIndex': 1, 'name': _('Standard Deviation'), 'color': plotlines_color, 'data': data_dic['data']}]

    }

    return chart_options
コード例 #2
0
def goaliepullen_updates_get(logger, data_dic):
    """ build structure for goaliepull updates """
    logger.debug(
        'scgoaliepullen_updates_getoregoaliepullen_updates_geten_updates_get()'
    )

    updates_dic = {}
    for ele in data_dic:
        updates_dic[ele] = {
            'chartoptions': {
                'xAxis': {
                    'categories': data_dic[ele]['team_list'],
                    'labels': {
                        'useHTML': 1,
                        'align': 'center'
                    },
                    'title': title('', font_size)
                },
                'series': [
                    # pylint: disable=E0602
                    {
                        'name': _('Goals after pulling goalie'),
                        'data': data_dic[ele]['goals_wogoalie_for_list'],
                        'color': chart_color3
                    },
                    {
                        'name': _('Emptynet goals taken'),
                        'data': data_dic[ele]['goals_en_against_list'],
                        'color': chart_color1
                    },
                ]
            }
        }

    return updates_dic
コード例 #3
0
def scoreen_updates_get(logger, data_dic):
    """ build structure for empty net_chart updates """
    logger.debug('scoreen_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        updates_dic[ele] = {
            'chartoptions': {
                'xAxis': {
                    'categories': data_dic[ele]['team_list'],
                    'labels': {
                        'useHTML': 1,
                        'align': 'center'
                    },
                    'title': title('', font_size)
                },
                'series': [
                    # pylint: disable=E0602
                    {
                        'name': _('Empty net changes'),
                        'data': data_dic[ele]['goalie_other_pull_list'],
                        'color': chart_color2
                    },
                    {
                        'name': _('Empty net goals'),
                        'data': data_dic[ele]['goals_en_list'],
                        'color': chart_color3
                    },
                ]
            }
        }

    return updates_dic
コード例 #4
0
ファイル: faceoff.py プロジェクト: grindsa/hockey_graphs
def faceoffs_updates_get(logger, ctitle, data_dic):
    """ get data for slider update """
    logger.debug('faceoffs_updates_get()')

    updates_dic = {}

    for ele in data_dic:
        updates_dic[ele] = {
            'text': ele,
            'chartoptions':  {
                'series': [{
                    # pylint: disable=E0602
                    'name': _('Standard Deviation'),
                    'color': plotlines_color,
                    'marker': {'symbol': 'square'},
                    'data': data_dic[ele]['data']
                }],
                'yAxis': {
                    'title': title(ctitle, font_size),
                    'min': data_dic[ele]['y_min_minmax'] - 2,
                    'max':  data_dic[ele]['y_max_minmax'] + 2,
                    'plotBands': [{'from':  data_dic[ele]['y_avg'] -  data_dic[ele]['y_deviation']/2, 'to':  data_dic[ele]['y_avg'] +  data_dic[ele]['y_deviation']/2, 'color': chart_color6}],
                    'plotLines': [{'zIndex': 3, 'color': plotlines_color, 'width': 3, 'value':  data_dic[ele]['y_avg']}],
                },
            }
        }

    return updates_dic
コード例 #5
0
def teamcomparison_chart_get(logger, ctitle, csubtitle, ismobile, data_dic):
    """ team comparison heatmap chart """
    logger.debug('teamcomparison_chart_get()')

    variable_dic = variables_get(ismobile)

    chart_options = {

        'chart': {
            'type': 'heatmap',
            'height': '110%',
            'inverted': 1,
            'style': chartstyle()
        },

        'exporting': exporting(filename=ctitle, allowhtml=0),
        'title': title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle': subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits': credit(),

        'xAxis': {
            'categories': data_dic['x_category'],
            'type': 'category',
            'labels': {'useHTML': 1, 'align': 'center'}
        },

        'yAxis': {
            'categories': data_dic['y_category'],
            'title': '',
            'opposite':1,
        },

        'tooltip': {
            'headerFormat': '',
            'pointFormat': '<b>{point.y_name}</b>: {point.ovalue}',
            'split': 1,
        },

        'legend': {
            'align': 'center',
            'layout': 'horizontal',
            'verticalAlign': 'bottom',
            'useHTML': 0,
            'itemStyle': {'color': text_color, 'font-size': font_size},
        },

        'colorAxis': color_axis(showinlegend=0),

        'series': [{
            'marker': {'symbol': 'square'},
            'borderWidth': variable_dic['border_width'],
            'borderColor': '#ffffff',
            'data': data_dic['data'],
            'showInLegend': 0,
            'dataLabels': {'enabled': 0}
        }],
    }

    return chart_options
コード例 #6
0
def shiftsupdates_get(logger, subtitle, ismobile, chart_data):
    """ get updates for shiftchart """
    logger.debug('shiftsupdates_get()')
    # pylint: disable=E0602
    variable_dic = variables_get(ismobile)

    # this is a dictionary containing period names
    periodname_dic = {1: '1st', 2: '2nd', 3: '3rd', 4: 'OT', 5: 'Full Game'}

    updates_dic = {}
    for period in chart_data:
        # create structure to store the updates
        updates_dic[period] = {'name': periodname_dic[period], 'data': {}}
        # update chart-title
        updates_dic[period]['data']['subtitle'] = {'text': '{0} - {1}'.format(subtitle, periodname_dic[period])}

        # update series
        updates_dic[period]['data']['series'] = [{'name': ('Even Strength'), 'data': chart_data[period]['shifts_list'], 'color': '#404040', 'marker': {'symbol': 'square'}}]

        updates_dic[period]['data']['xAxis'] = [{
            'title': title(_('Game Time'), variable_dic['font_size']),
            'labels': {'align': 'center', 'style': {'fontSize': variable_dic['font_size']}},
            #'categories': chart_data[period]['x_list'],
            'type': 'datetime',
            'tickInterval': 300000,
            #'tickPositions': chart_data[period]['xtickposition_list'],
            'tickWidth': 1,
            'grid': {'enabled': 0},
            'opposite': 0,
        }, {
            'title': title(_('Goals'), variable_dic['font_size'], offset=15),
            'labels': {'useHTML': 1, 'align': 'center'},
            'tickPositions': [],
            'plotLines': chart_data[period]['x2_plotlines_list'],
            'plotBands': chart_data[period]['plotbands_list'],
            'tickWidth': 0,
            'grid': {'enabled': 0},
            'opposite': 1,
        }]

    # default checked value in chart
    updates_dic[5]['checked'] = True

    return updates_dic
コード例 #7
0
ファイル: pdo.py プロジェクト: grindsa/hockey_graphs
def ppg_updates_get(logger, data_dic, ctitle):
    """ get updates for points per game chart """
    logger.debug('ppg_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        updates_dic[ele] = {
            'text': ele,
            'chartoptions': {
                'series': [{
                    # pylint: disable=E0602
                    'name': _('Standard Deviation'),
                    'color': plotlines_color,
                    'marker': {
                        'symbol': 'square'
                    },
                    'data': data_dic[ele]['data']
                }],
                'yAxis': {
                    'title':
                    title(ctitle, font_size),
                    'min':
                    0,
                    'tickInterval':
                    0.5,
                    # 'max':  data_dic[ele]['y_max'] + 2,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['y_avg'] -
                        data_dic[ele]['y_deviation'] / 2,
                        'to':
                        data_dic[ele]['y_avg'] +
                        data_dic[ele]['y_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 3,
                        'value': data_dic[ele]['y_avg']
                    }],
                },
            }
        }

    return updates_dic
コード例 #8
0
ファイル: pdo.py プロジェクト: grindsa/hockey_graphs
def overview_updates_get(logger, data_dic):
    """ build structure for pdo_overview_chart updates """
    logger.debug('breakdown_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        updates_dic[ele] = {
            'chartoptions': {
                'xAxis': {
                    'categories': data_dic[ele]['team_list'],
                    'labels': {
                        'useHTML': 1,
                        'align': 'center'
                    },
                    'title': title('', font_size)
                },
                'series': [
                    # pylint: disable=E0602
                    {
                        'name': _('Save percentage (Sv%)'),
                        'marker': {
                            'symbol': 'square'
                        },
                        'data': data_dic[ele]['sv_list'],
                        'color': chart_color3
                    },
                    {
                        'name': _('Shooting percentage (Sh%)'),
                        'marker': {
                            'symbol': 'square'
                        },
                        'data': data_dic[ele]['sh_list'],
                        'color': chart_color1
                    },
                ]
            }
        }

    return updates_dic
コード例 #9
0
def rebound_updates_get(logger, _ctitle, data_dic, key1, key2):
    """ build structure for chart updates """
    logger.debug('rebound_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        updates_dic[ele] = {
            'chartoptions': {
                'xAxis': {
                    'categories': data_dic[ele]['x_category'],
                    'title': title(''),
                    'maxPadding': 0.1,
                    'labels': {
                        'useHTML': 1,
                        'align': 'center'
                    }
                },
                'series': [
                    # pylint: disable=E0602
                    {
                        'index': 0,
                        'name': _('leading to own goal'),
                        'data': data_dic[ele][key1],
                        'color': chart_color3
                    },
                    {
                        'index': 1,
                        'name': _('leading to goal against'),
                        'data': data_dic[ele][key2],
                        'color': chart_color2
                    },
                ]
            }
        }

    return updates_dic
コード例 #10
0
ファイル: pppkchart.py プロジェクト: grindsa/hockey_graphs
def pppk_chart_get(logger, ctitle, csubtitle, ismobile, pppk_data):
    # pylint: disable=E0602
    """ pdo breakdown """
    logger.debug('pdo_breakdown_chart()')

    variable_dic = variables_get(ismobile)

    # dirty hack
    if pppk_data['x_min'] == 0:
        pppk_data['x_min'] = 1
    if pppk_data['y_min'] == 0:
        pppk_data['y_min'] = 1
    if pppk_data['x_max'] == 100:
        pppk_data['x_max'] = 99
    if pppk_data['y_max'] == 100:
        pppk_data['y_max'] = 99

    minmax_dic = {
        'x_min': pppk_data['x_min'] - 1,
        'y_min': pppk_data['y_min'] - 1,
        'x_max': pppk_data['x_max'] + 1,
        'y_max': pppk_data['y_max'] + 1
    }

    chart_options = {
        'chart': {
            'type': 'scatter',
            'height': '120%',
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend': {
            'enabled': 1
        },
        'responsive':
        responsive_y1(),
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span><b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.x}%s</span><br><span style="font-size: %s">%s: {point.y}%s</span><br/>'
            % (font_size, _('Shooting percentage (Sh%)'), '%', font_size,
               _('Save percentage (Sv%)'), '%s')
        },
        'xAxis': {
            'title':
            title(_('Powerplay percentage (Pp%)'), font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'min':
            minmax_dic['x_min'],
            'max':
            minmax_dic['x_max'],
            'tickInterval':
            1,
            'showFirstLabel':
            1,
            'showLastLabel':
            1,
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                pppk_data['x_avg'] - pppk_data['x_deviation'] / 2,
                'to':
                pppk_data['x_avg'] + pppk_data['x_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': pppk_data['x_avg']
            }],
        },
        'yAxis': {
            'title':
            title(_('Penalty Kill percentage (Pk%)'), font_size),
            'maxPadding':
            0.1,
            'min':
            minmax_dic['y_min'],
            'max':
            minmax_dic['y_max'],
            'tickInterval':
            1,
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                pppk_data['y_avg'] - pppk_data['y_deviation'] / 2,
                'to':
                pppk_data['y_avg'] + pppk_data['y_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': pppk_data['y_avg']
            }],
        },
        'series': [{
            'zIndex': 1,
            'name': _('Standard Deviation'),
            'color': plotlines_color,
            'marker': {
                'symbol': 'square'
            },
            'data': pppk_data['data']
        }],
        'annotations':
        corner_annotations(ismobile, minmax_dic, _('Defensive'),
                           _('Overstrained'), _('Agressive'), _('Offensive')),
    }
    return chart_options
コード例 #11
0
ファイル: pppkchart.py プロジェクト: grindsa/hockey_graphs
def scoreenchart_get(logger, ctitle, csubtitle, ismobile, data_dic):
    # pylint: disable=E0602, R0914
    """ create time-on-ice chart """
    logger.debug('gametoichart_create()')

    variable_dic = variables_get(ismobile)

    chart_options = {
        'chart': {
            'type': 'column',
            'height': '80%',
            'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend':
        legend(),
        'responsive':
        responsive_y1(),
        'tooltip': {
            'sharted':
            1,
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span> <b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.goalie_other_pull}</span><br><span style="font-size: %s">%s: {point.goals_en_for}</span><br/><span style="font-size: %s">%s: {point.goals_en_for_pctg}%s </span><br/>'
            % (font_size, _('Empty net changes'), font_size,
               _('Empty net goals'), font_size, _('Scoring percentage'), '%')
        },
        'plotOptions': {
            'series': {
                'states': {
                    'inactive': {
                        'opacity': 1
                    }
                },
                'dataLabels': {
                    'enabled': 1,
                    'style': {
                        'fontSize': font_size,
                        'textOutline': 0,
                        'color': '#000000',
                        'fontWeight': 0
                    },
                }
            }
        },
        'xAxis': {
            'categories': data_dic['team_list'],
            'title': title('', font_size),
            'labels': {
                'useHTML': 1,
                'align': 'center'
            },
            # 'labels': {'style': {'fontSize': font_size}},
        },
        'yAxis': [{
            # pylint: disable=E0602
            'title':
            title('', font_size),
            'reversedStacks':
            0,
            'labels': {
                'enabled': 1,
                'style': {
                    'fontSize': font_size
                }
            },
            'min':
            0,
            'plotLines': [{
                'color': plotlines_color,
                'width': 2,
                'value': 100
            }],
        }],
        'series': [
            # pylint: disable=E0602
            {
                'name': _('Empty net changes'),
                'data': data_dic['goalie_other_pull_list'],
                'color': chart_color2
            },
            {
                'name': _('Empty net goals'),
                'data': data_dic['goals_en_list'],
                'color': chart_color3
            },
        ]
    }

    return chart_options
コード例 #12
0
ファイル: pppkchart.py プロジェクト: grindsa/hockey_graphs
def goaliepullchart_get(logger, ctitle, csubtitle, ismobile, data_dic):
    # pylint: disable=E0602, R0914
    """ create time-on-ice chart """
    logger.debug('gametoichart_create()')

    variable_dic = variables_get(ismobile)

    chart_options = {
        'chart': {
            'type': 'column',
            'height': '80%',
            'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend':
        legend(),
        'responsive':
        responsive_y1_nolabel(),
        'tooltip': {
            'sharted':
            1,
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span><b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.goalie_own_pull}</span><br><span style="font-size: %s">%s: {point.goals_wogoalie_for}</span><br/><span style="font-size: %s">%s: {point.goals_en_against}</span><br/>'
            % (font_size, _('Goalie pulls'), font_size,
               _('Goals after pulling goalie'), font_size,
               _('Empty net goals taken'))
        },
        'plotOptions': {
            'series': {
                'states': {
                    'inactive': {
                        'opacity': 1
                    }
                },
                'stacking': 'normal',
                'dataLabels': {
                    'enabled': 1,
                    'inside': 1,
                    'style': {
                        'fontSize': font_size,
                        'textOutline': 0,
                        'color': '#ffffff',
                        'fontWeight': 0
                    },
                    'format': '{point.label}'
                }
            }
        },
        'xAxis': {
            'categories': data_dic['team_list'],
            'title': title('', font_size),
            'labels': {
                'useHTML': 1,
                'align': 'center'
            },
            # 'labels': {'style': {'fontSize': font_size}},
        },
        'yAxis': {
            # pylint: disable=E0602
            'title': title('', font_size),
            'reversedStacks': 0,
            'tickInterval': 1,
            'labels': {
                'enabled': 0,
                'style': {
                    'fontSize': font_size
                }
            },
            'plotLines': [{
                'color': plotlines_color,
                'width': 2,
                'value': 100
            }],
        },
        'series': [
            # pylint: disable=E0602
            {
                'name': _('Goals after pulling goalie'),
                'marker': {
                    'symbol': 'square'
                },
                'data': data_dic['goals_wogoalie_for_list'],
                'color': chart_color3
            },
            {
                'name': _('Emptynet goals taken'),
                'marker': {
                    'symbol': 'square'
                },
                'data': data_dic['goals_en_against_list'],
                'color': chart_color1
            },
        ]
    }

    return chart_options
コード例 #13
0
ファイル: pppkchart.py プロジェクト: grindsa/hockey_graphs
def discipline_chart_get(logger, ctitle, csubtitle, ismobile, pppk_data):
    # pylint: disable=E0602
    """ pdo breakdown """
    logger.debug('discipline_chart_get()')

    variable_dic = variables_get(ismobile)

    # dirty hack
    if pppk_data['x_min'] == 0:
        pppk_data['x_min'] = 1
    if pppk_data['y_min'] == 0:
        pppk_data['y_min'] = 1
    if pppk_data['x_max'] == 100:
        pppk_data['x_max'] = 99
    if pppk_data['y_max'] == 100:
        pppk_data['y_max'] = 99

    minmax_dic = {
        'x_min': pppk_data['x_min'] - 0.2,
        'y_min': pppk_data['y_min'] - 0.2,
        'x_max': pppk_data['x_max'] + 0.2,
        'y_max': pppk_data['y_max'] + 0.2
    }

    chart_options = {
        'chart': {
            'type': 'scatter',
            'height': '110%',
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend': {
            'enabled': 1
        },
        'responsive':
        responsive_y1(),
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span><b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.penaltyminutes_drawn}min</span><br><span style="font-size: %s">%s: {point.penaltyminutes_taken}min</span><br/>'
            % (font_size, _('Penaltyminutes drawn'), font_size,
               _('Penaltyminutes taken'))
        },
        'xAxis': {
            'title':
            title(_('Penaltyminutes drawn (avg per game)'), font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'min':
            minmax_dic['x_min'],
            'max':
            minmax_dic['x_max'],
            'tickInterval':
            0.5,
            'showFirstLabel':
            1,
            'showLastLabel':
            1,
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                pppk_data['x_avg'] - pppk_data['x_deviation'] / 2,
                'to':
                pppk_data['x_avg'] + pppk_data['x_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': pppk_data['x_avg']
            }],
        },
        'yAxis': {
            'title':
            title(_('Penaltyminutes taken (avg per game)'), font_size),
            'maxPadding':
            0.1,
            'min':
            minmax_dic['y_min'],
            'max':
            minmax_dic['y_max'],
            'tickInterval':
            0.5,
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                pppk_data['y_avg'] - pppk_data['x_deviation'] / 2,
                'to':
                pppk_data['y_avg'] + pppk_data['x_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': pppk_data['y_avg']
            }],
        },
        'series': [{
            'zIndex': 1,
            'name': _('Standard Deviation'),
            'color': plotlines_color,
            'marker': {
                'symbol': 'square'
            },
            'data': pppk_data['data']
        }],
        'annotations':
        corner_annotations(ismobile, minmax_dic, _('Undisciplined'),
                           _('Friendly'), _('Chippy'), _('Disciplined'), 1)
    }
    return chart_options
コード例 #14
0
def xgfa_chart_get(logger, ctitle, csubtitle, ismobile, xgfa_data):
    # pylint: disable=E0602
    """ pdo breakdown """
    logger.debug('pdo_breakdown_chart()')

    variable_dic = variables_get(ismobile)

    # dirty hack
    if xgfa_data['x_min'] == 0:
        xgfa_data['x_min'] = 1
    if xgfa_data['y_min'] == 0:
        xgfa_data['y_min'] = 1

    minmax_dic = {
        'x_min': xgfa_data['x_min'] - 0.2,
        'y_min': xgfa_data['y_min'] - 0.2,
        'x_max': xgfa_data['x_max'] + 0.2,
        'y_max': xgfa_data['y_max'] + 0.2
    }

    chart_options = {
        'chart': {
            'type': 'scatter',
            'height': '100%',
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend': {
            'enabled': 1
        },
        'responsive':
        responsive_y1(),
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span><b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.x}</span><br><span style="font-size: %s">%s: {point.y}</span><br/>'
            % (font_size, _('xGF60'), font_size, _('xGA60'))
        },
        'xAxis': {
            'title':
            title(_('Expected Goals "For" per 60min (xGF60)'), font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'min':
            minmax_dic['x_min'],
            'max':
            minmax_dic['x_max'],
            'tickInterval':
            0.25,
            'showFirstLabel':
            1,
            'showLastLabel':
            1,
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                xgfa_data['x_avg'] - xgfa_data['x_deviation'] / 2,
                'to':
                xgfa_data['x_avg'] + xgfa_data['x_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': xgfa_data['x_avg']
            }],
        },
        'yAxis': {
            'title':
            title(_('Expected Goals "Against" per 60min (xGA60)'), font_size),
            'maxPadding':
            0.1,
            'min':
            minmax_dic['y_min'],
            'max':
            minmax_dic['y_max'],
            'tickInterval':
            0.25,
            'reversed':
            1,
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                xgfa_data['y_avg'] - xgfa_data['y_deviation'] / 2,
                'to':
                xgfa_data['y_avg'] + xgfa_data['y_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': xgfa_data['y_avg']
            }],
        },
        'series': [{
            'zIndex': 1,
            'name': _('Standard Deviation'),
            'color': plotlines_color,
            'marker': {
                'symbol': 'square'
            },
            'data': xgfa_data['data']
        }],
        'annotations':
        corner_annotations(ismobile, minmax_dic, _('Headless'), _('Boring'),
                           _('Exciting'), _('Coolly')),
    }
    return chart_options
コード例 #15
0
ファイル: shiftcharts.py プロジェクト: grindsa/hockey_graphs
def shiftsperplayerchart_create(logger, ctitle, csubtitle, ismobile, data_dic):
    # pylint: disable=E0602, R0914
    """ create shift per player chart """
    logger.debug('shiftsperplayerchart_create()')

    variable_dic = variables_get(ismobile)

    chart_options = {
        'ctype':
        'gantt',
        'chart': {
            'height': '110%',
            'alignTicks': 0,
            'style': chartstyle()
        },
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend': {
            'enabled': 0
        },
        'exporting':
        exporting(filename=ctitle),
        'responsive':
        responsive_y1(),
        'plotOptions': {
            'series': {
                'states': {
                    'inactive': {
                        'opacity': 1
                    }
                }
            }
        },
        'tooltip': {
            'useHTML': 0,
            'headerFormat': '',
            'pointFormat':
            '<b>{point.playername}</b><br>#{point.cnt} - {point.type}: {point.start_human}m - {point.end_human}m',
            'followPointer': 1,
        },
        'xAxis': [{
            'title': title(_('Game Time'), variable_dic['font_size']),
            'labels': {
                'align': 'center',
                'style': {
                    'fontSize': variable_dic['font_size']
                }
            },
            'tickInterval': 300000,
            'type': 'datetime',
            'tickWidth': 1,
            'grid': {
                'enabled': 0
            },
            'opposite': 0,
        }, {
            'title':
            title(_('Goals'), variable_dic['font_size'], offset=15),
            'tickPositions': [],
            'plotLines':
            data_dic['x2_plotlines_list'],
            'plotBands':
            data_dic['plotbands_list'],
            'tickWidth':
            0,
            'grid': {
                'enabled': 0
            },
            'opposite':
            1
        }],
        'yAxis': {
            'title': title('', font_size),
            'categories': data_dic['playername_list'],
            'labels': {
                'useHTML': 1,
                'align': 'right',
                'style': {
                    'fontSize': variable_dic['font_size']
                }
            },
            'grid': {
                'enabled': 0
            },
            'plotLines': data_dic['y_plotlines_list']
        },
        'series': [
            {
                'name': ('Even Strength'),
                'data': data_dic['shifts_list'],
                'color': '#404040',
                'marker': {
                    'symbol': 'square'
                }
            },
        ]
    }
    return chart_options
コード例 #16
0
def gfxgf_chart_get(logger, ctitle, csubtitle, ismobile, gfxgf_data):
    # pylint: disable=E0602
    """ pdo breakdown """
    logger.debug('pdo_breakdown_chart()')

    variable_dic = variables_get(ismobile)

    # dirty hack
    if gfxgf_data['x_min'] == 0:
        gfxgf_data['x_min'] = 1
    if gfxgf_data['y_min'] == 0:
        gfxgf_data['y_min'] = 1
    if gfxgf_data['x_max'] == 100:
        gfxgf_data['x_max'] = 99
    if gfxgf_data['y_max'] == 100:
        gfxgf_data['y_max'] = 99

    minmax_dic = {
        'x_min': int(round(gfxgf_data['x_min'], 0)) - 5,
        'y_min': int(round(gfxgf_data['y_min'], 0)) - 2.5,
        'x_max': int(round(gfxgf_data['x_max'], 0)) + 5,
        'y_max': int(round(gfxgf_data['y_max'], 0)) + 5,
    }

    chart_options = {
        'chart': {
            'type': 'scatter',
            'height': '110%',
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend': {
            'enabled': 1
        },
        'responsive':
        responsive_y1(),
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span><b>{point.team_name}</b></span></br><span style="font-size: %s">%s: {point.x}</span><br><span style="font-size: %s">%s: {point.y}</span><br/>'
            % (font_size, _('GF%'), font_size, _('xGF%'))
        },
        'xAxis': {
            'title':
            title(_('Goals percentage on 5v5 (Gf%)'), font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'min':
            minmax_dic['x_min'],
            'max':
            minmax_dic['x_max'],
            #'tickInterval': 2,
            'showFirstLabel':
            1,
            'showLastLabel':
            1,
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                gfxgf_data['x_avg'] - gfxgf_data['x_deviation'] / 2,
                'to':
                gfxgf_data['x_avg'] + gfxgf_data['x_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': gfxgf_data['x_avg']
            }],
        },
        'yAxis': {
            'title':
            title(_('expected Goals percentage on 5v5 (xGf%)'), font_size),
            'maxPadding':
            0.1,
            'min':
            minmax_dic['y_min'],
            'max':
            minmax_dic['y_max'],
            #'tickInterval': 2,
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'gridLineWidth':
            1,
            'plotBands': [{
                'from':
                gfxgf_data['y_avg'] - gfxgf_data['y_deviation'] / 2,
                'to':
                gfxgf_data['y_avg'] + gfxgf_data['y_deviation'] / 2,
                'color':
                chart_color6
            }],
            'plotLines': [{
                'zIndex': 3,
                'color': plotlines_color,
                'width': 2,
                'value': gfxgf_data['y_avg']
            }],
        },
        'series': [{
            'zIndex': 1,
            'name': _('Standard Deviation'),
            'color': plotlines_color,
            'marker': {
                'symbol': 'square'
            },
            'data': gfxgf_data['data']
        }],
        'annotations':
        corner_annotations(ismobile, minmax_dic, _('Underperforming'),
                           _('Bad'), _('Good'), _('Overperforming')),
    }
    return chart_options
コード例 #17
0
ファイル: toicharts.py プロジェクト: grindsa/hockey_graphs
def gametoipppkchart_create(logger, ctitle, csubtitle, ismobile, toi_dic,
                            color_primary, color_secondary):
    # pylint: disable=E0602, R0914
    """ create time-on-ice chart """
    logger.debug('gametoipppkchart_create()')

    variable_dic = variables_get(ismobile)

    # create x axis with player names
    x_list = []
    pp_list = []
    pk_list = []

    # this one is to create the list of playernames
    for player_name in toi_dic:
        if player_name not in x_list:
            x_list.append(player_name)

    # add toi per player
    pp_max = 0
    pk_min = 0
    for player_name in sorted(x_list):
        if player_name in toi_dic:
            # y_dic[period].append('{0:02d}:{1:02d}'.format(*divmod(shifts_dic['ebb'][period][player_name], 60)))
            pp_value = round(toi_dic[player_name]['pp'] / 60, 3)
            pk_value = round(toi_dic[player_name]['pk'] / 60, 3) * -1
            # check min max values to adjust chart
            if pp_max <= pp_value:
                pp_max = pp_value
            if pk_value <= pk_min:
                pk_min = pk_value
            pp_list.append({
                'y':
                pp_value,
                'label':
                '{0:02d}:{1:02d}'.format(
                    *divmod(toi_dic[player_name]['pp'], 60))
            })
            pk_list.append({
                'y':
                pk_value,
                'label':
                '{0:02d}:{1:02d}'.format(
                    *divmod(toi_dic[player_name]['pk'], 60))
            })
        else:
            pp_list.append(0)
            pk_list.append(0)

    chart_options = {
        'chart': {
            'type': 'bar',
            'height': '100%',
            'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend':
        legend(additional_parameters={'reversed': 1}),
        'responsive':
        responsive_y1_nolabel(),
        'plotOptions': {
            'series': {
                'stacking': 'normal',
                'dataLabels': {
                    'enabled': 1,
                    'inside': 0,
                    'style': {
                        'fontSize': font_size,
                        'textOutline': 0,
                        'color': '#000000',
                        'fontWeight': 0
                    },
                    'format': '{point.label}'
                }
            }
        },
        'tooltip': {
            'shared':
            1,
            'useHTML':
            1,
            'headerFormat':
            '<span style="font-size: %s"><b>{point.x}</b></span><br/>' %
            font_size,
            'pointFormat':
            '<span style="color:{point.color}">\u25CF</span> <span style="font-size: %s">{series.name}: {point.label} %s</span><br/>'
            % (font_size, _('min'))
        },
        'xAxis': {
            'categories': sorted(x_list),
            'title': title('', font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'tickInterval': 1,
            'showFirstLabel': 1,
            'showLastLabel': 1,
        },
        'yAxis': {
            'title': title(_('Time on Ice in min'), font_size),
            'reversedStacks': 0,
            'tickInterval': 1,
            'maxPadding': 0.1,
            'min': pk_min - 1,
            'max': pp_max + 1,
            'labels': {
                'enabled': 0,
                'style': {
                    'fontSize': font_size
                },
            },
        },
        'series': [
            {
                'name': _('Time in Powerplay'),
                'data': pp_list,
                'color': color_primary
            },
            {
                'name': _('Time in Penalty killing'),
                'data': pk_list,
                'color': color_secondary
            },
        ]
    }
    return chart_options
コード例 #18
0
ファイル: toicharts.py プロジェクト: grindsa/hockey_graphs
def gametoichart_create(logger, ctitle, csubtitle, ismobile, toi_dic,
                        bar_color1, bar_color2, bar_color3, bar_color4):
    # pylint: disable=E0602
    """ create time-on-ice chart """
    logger.debug('gametoichart_create()')

    variable_dic = variables_get(ismobile)

    # create x axis with player names
    x_list = []
    y_dic = {1: [], 2: [], 3: [], 4: []}

    # we need two iterations of the dictionary
    # first one is to create the list of playernames
    for period in toi_dic:
        for player_name in toi_dic[period]:
            if player_name not in x_list:
                x_list.append(player_name)

    # 2nd one to add toi per player
    for period in toi_dic:
        for player_name in sorted(x_list):
            if player_name in toi_dic[period]:
                # y_dic[period].append('{0:02d}:{1:02d}'.format(*divmod(shifts_dic['ebb'][period][player_name], 60)))
                y_dic[period].append({
                    'y':
                    round(toi_dic[period][player_name] / 60, 3),
                    'label':
                    '{0:02d}:{1:02d}'.format(
                        *divmod(toi_dic[period][player_name], 60))
                })
            else:
                y_dic[period].append(0)

    chart_options = {
        'chart': {
            'type': 'bar',
            'height': '120%',
            'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend':
        legend(),
        'responsive':
        responsive_y1(),
        'plotOptions': {
            'series': {
                'stacking': 'normal'
            }
        },
        'tooltip': {
            'shared':
            1,
            'useHTML':
            1,
            'headerFormat':
            '<span style="font-size: %s"><b>{point.x}</b></span><br/>' %
            font_size,
            'pointFormat':
            '<span style="color:{point.color}">\u25CF</span> <span style="font-size: %s">{series.name}: {point.label} %s</span><br/>'
            % (font_size, _('min'))
        },
        'xAxis': {
            'categories': sorted(x_list),
            'title': title('', font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
            'tickInterval': 1,
            'showFirstLabel': 1,
            'showLastLabel': 1,
        },
        'yAxis': {
            'title': title(_('Time on Ice'), font_size),
            'reversedStacks': 0,
            'tickInterval': 1,
            'maxPadding': 0.1,
            'labels': {
                'style': {
                    'fontSize': font_size
                },
            },
        },
        'series': [{
            'name': _('1st Period'),
            'data': y_dic[1],
            'color': bar_color1
        }, {
            'name': _('2nd Period'),
            'data': y_dic[2],
            'color': bar_color2
        }, {
            'name': _('3rd Period'),
            'data': y_dic[3],
            'color': bar_color3
        }, {
            'name': _('OT'),
            'data': y_dic[4],
            'color': bar_color4
        }]
    }
    return chart_options
コード例 #19
0
ファイル: pdo.py プロジェクト: grindsa/hockey_graphs
def breakdown_updates_get(logger,
                          data_dic,
                          string_1=None,
                          string_2=None,
                          string_3=None,
                          string_4=None,
                          ismobile=False):
    # pylint: disable=E0602
    """ build structure for pdo breakdown chart """
    logger.debug('breakdown_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        minmax_dic = {
            'x_min': round(data_dic[ele]['x_min'] - 1, 0),
            'y_min': round(data_dic[ele]['y_min'] - 1, 0),
            'x_max': round(data_dic[ele]['x_max'] + 1, 0),
            'y_max': round(data_dic[ele]['y_max'] + 1, 0)
        }
        updates_dic[ele] = {
            'text': ele,
            'chartoptions': {
                'series': [{
                    'name': _('Standard Deviation'),
                    'color': plotlines_color,
                    'marker': {
                        'symbol': 'square'
                    },
                    'data': data_dic[ele]['data']
                }],
                'xAxis': {
                    'title':
                    title(_('Shooting percentage (Sh%)'), font_size),
                    'min':
                    minmax_dic['x_min'],
                    'max':
                    minmax_dic['x_max'],
                    'tickInterval':
                    1,
                    'gridLineWidth':
                    1,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['x_avg'] -
                        data_dic[ele]['x_deviation'] / 2,
                        'to':
                        data_dic[ele]['x_avg'] +
                        data_dic[ele]['x_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 2,
                        'value': data_dic[ele]['x_avg']
                    }],
                },
                'yAxis': {
                    'title':
                    title(_('Save percentage (Sv%)'), font_size),
                    'min':
                    minmax_dic['y_min'],
                    'max':
                    minmax_dic['y_max'],
                    'tickInterval':
                    1,
                    'gridLineWidth':
                    1,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['y_avg'] -
                        data_dic[ele]['y_deviation'] / 2,
                        'to':
                        data_dic[ele]['y_avg'] +
                        data_dic[ele]['y_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 3,
                        'value': data_dic[ele]['y_avg']
                    }],
                },
            }
        }
        if string_1 and string_2 and string_3 and string_4:
            updates_dic[ele]['chartoptions'][
                'annotations'] = corner_annotations(ismobile, minmax_dic,
                                                    string_1, string_2,
                                                    string_3, string_4)

    return updates_dic
コード例 #20
0
def discipline_updates_get(logger,
                           data_dic,
                           string_1=None,
                           string_2=None,
                           string_3=None,
                           string_4=None,
                           ismobile=False):
    # pylint: disable=E0602
    """ build structure for pdo breakdown chart """
    logger.debug('discipline_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        minmax_dic = {
            'x_min': data_dic[ele]['x_min'] - 0.2,
            'y_min': data_dic[ele]['y_min'] - 0.2,
            'x_max': data_dic[ele]['x_max'] + 0.2,
            'y_max': data_dic[ele]['y_max'] + 0.2
        }
        updates_dic[ele] = {
            'text': ele,
            'chartoptions': {
                'series': [{
                    'name': _('Standard Deviation'),
                    'color': plotlines_color,
                    'marker': {
                        'symbol': 'square'
                    },
                    'data': data_dic[ele]['data']
                }],
                'xAxis': {
                    'title':
                    title(_('Penaltyminutes drawn (avg per game)'), font_size),
                    'min':
                    minmax_dic['x_min'],
                    'max':
                    minmax_dic['x_max'],
                    'tickInterval':
                    0.5,
                    'gridLineWidth':
                    1,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['x_avg'] -
                        data_dic[ele]['x_deviation'] / 2,
                        'to':
                        data_dic[ele]['x_avg'] +
                        data_dic[ele]['x_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 2,
                        'value': data_dic[ele]['x_avg']
                    }],
                },
                'yAxis': {
                    'title':
                    title(_('Penaltyminutes taken (avg per game)'), font_size),
                    'min':
                    minmax_dic['y_min'],
                    'max':
                    minmax_dic['y_max'],
                    'tickInterval':
                    0.5,
                    'gridLineWidth':
                    1,
                    # we use x_deviation on purpose to make data better comparable
                    'plotBands': [{
                        'from':
                        data_dic[ele]['y_avg'] -
                        data_dic[ele]['x_deviation'] / 2,
                        'to':
                        data_dic[ele]['y_avg'] +
                        data_dic[ele]['x_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 3,
                        'value': data_dic[ele]['y_avg']
                    }],
                },
            }
        }
        if string_1 and string_2 and string_3 and string_4:
            updates_dic[ele]['chartoptions'][
                'annotations'] = corner_annotations(ismobile, minmax_dic,
                                                    string_1, string_2,
                                                    string_3, string_4, 1)

    return updates_dic
コード例 #21
0
def dgf_chart_get(logger, ctitle, csubtitle, ismobile, data_dic):
    # pylint: disable=E0602
    """ pdo overview """
    logger.debug('pdo_overview_chart()')

    variable_dic = variables_get(ismobile)

    if ismobile:
        chart_height = '100%'
        legent_title_size = font_size_mobile
    else:
        chart_height = '80%'
        legent_title_size = font_size

    chart_options = {
        'chart': {
            'type': 'column',
            'height': chart_height,
            'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'legend':
        legend(1, {
            'title': {
                'text': 'GF%',
                'style': {
                    'fontSize': legent_title_size
                }
            }
        }),
        'responsive':
        responsive_y1(),
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span><b>{point.shortcut}</b></span></br><span style="font-size: %s">%s: {point.gf_pctg}</span><br><span style="font-size: %s">%s: {point.y}</span><br/>'
            % (font_size, _('GF%'), font_size, _('dGF%'))
        },
        'plotOptions': {
            'series': {
                'dataLabels': {
                    'enabled': 1,
                    'useHTML': 0,
                    'style': {
                        'fontSize': font_size,
                        'textOutline': 0,
                        'color': '#ffffff',
                        'fontWeight': 0
                    }
                }
            }
        },
        'xAxis': {
            'categories': data_dic['data']['team_list'],
            'title': title('', font_size),
            'labels': {
                'useHTML': 1,
                'align': 'center'
            },
        },
        'colorAxis':
        color_axis(showinlegend=1, minimum=data_dic['gf_5v5_pctg_min']),
        'yAxis': {
            # pylint: disable=E0602
            'title': title(_('Difference of GF% and xGF% (dGF%)'), font_size),
            'labels': {
                'style': {
                    'fontSize': font_size
                }
            },
            'plotLines': [{
                'color': plotlines_color,
                'width': 2,
                'value': 100
            }],
        },
        'series': [
            # pylint: disable=E0602
            {
                'name': _('dGF%'),
                'marker': {
                    'symbol': 'square'
                },
                'data': data_dic['data']['dgf_list']
            },
        ]
    }

    return chart_options
コード例 #22
0
ファイル: xg.py プロジェクト: grindsa/hockey_graphs
def gfxgf_updates_get(logger,
                      data_dic,
                      string_1=None,
                      string_2=None,
                      string_3=None,
                      string_4=None,
                      ismobile=False):
    # pylint: disable=E0602
    """ build structure for xgfa chart """
    logger.debug('discipline_updates_get()')

    updates_dic = {}
    for ele in data_dic:
        minmax_dic = {
            'x_min': data_dic[ele]['x_min'] - 5,
            'y_min': data_dic[ele]['y_min'] - 2.5,
            'x_max': data_dic[ele]['x_max'] + 5,
            'y_max': data_dic[ele]['y_max'] + 5
        }
        updates_dic[ele] = {
            'text': ele,
            'chartoptions': {
                'series': [{
                    'name': _('Standard Deviation'),
                    'color': plotlines_color,
                    'marker': {
                        'symbol': 'square'
                    },
                    'data': data_dic[ele]['data']
                }],
                'xAxis': {
                    'title':
                    title(_('Expected Goals "For" per 60min (xGF60)'),
                          font_size),
                    'min':
                    minmax_dic['x_min'],
                    'max':
                    minmax_dic['x_max'],
                    'gridLineWidth':
                    1,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['x_avg'] -
                        data_dic[ele]['x_deviation'] / 2,
                        'to':
                        data_dic[ele]['x_avg'] +
                        data_dic[ele]['x_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 2,
                        'value': data_dic[ele]['x_avg']
                    }],
                },
                'yAxis': {
                    'title':
                    title(_('Expected Goals "Against" per 60min (xGA60)'),
                          font_size),
                    'min':
                    minmax_dic['y_min'],
                    'max':
                    minmax_dic['y_max'],
                    'gridLineWidth':
                    1,
                    'reversed':
                    1,
                    # we use x_deviation on purpose to make data better comparable
                    'plotBands': [{
                        'from':
                        data_dic[ele]['y_avg'] -
                        data_dic[ele]['x_deviation'] / 2,
                        'to':
                        data_dic[ele]['y_avg'] +
                        data_dic[ele]['x_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 3,
                        'value': data_dic[ele]['y_avg']
                    }],
                },
            }
        }
        if string_1 and string_2 and string_3 and string_4:
            updates_dic[ele]['chartoptions'][
                'annotations'] = corner_annotations(ismobile, minmax_dic,
                                                    string_1, string_2,
                                                    string_3, string_4, 1)

    return updates_dic
コード例 #23
0
def gamematchupchart_create(logger, ctitle, csubtitle, ismobile, lineup_dic, matchup_matrix, plotline_dic, matchinfo_dic):
    """ create matchup heatmeap """
    # pylint: disable=E0602, R0914
    logger.debug('gamematchupchart_create()')

    variable_dic = variables_get(ismobile)

    data_list = []
    for hpid in matchup_matrix:
        for vpid in matchup_matrix[hpid]:
            # data_list.append([hpid, vpid, round(matchup_matrix[hpid][vpid]/60, 0)])
            tmp_dic = {
                'x': hpid, 'y': vpid,
                'value': round(matchup_matrix[hpid][vpid]['seconds']/60, 3),
                'minsec': '{0:02d}:{1:02d}'.format(*divmod(matchup_matrix[hpid][vpid]['seconds'], 60)),
                'home_name': '{0} {1}'.format(lineup_dic['home_team'][hpid]['name'], lineup_dic['home_team'][hpid]['surname']),
                'visitor_name': '{0} {1}'.format(lineup_dic['visitor_team'][vpid]['name'], lineup_dic['visitor_team'][vpid]['surname']),
                'home_shots': matchup_matrix[hpid][vpid]['home_shots'],
                'visitor_shots': matchup_matrix[hpid][vpid]['visitor_shots'],
            }
            # deside how to set label
            if matchup_matrix[hpid][vpid]['home_shots'] - matchup_matrix[hpid][vpid]['visitor_shots'] > 0:
                # arrow up
                tmp_dic['delta'] = '{0}{1}'.format('\u2BC5', matchup_matrix[hpid][vpid]['home_shots'] - matchup_matrix[hpid][vpid]['visitor_shots'])
                tmp_dic['dataLabels'] = {'format': '{0}{1}'.format('\u2BC5', matchup_matrix[hpid][vpid]['home_shots'] - matchup_matrix[hpid][vpid]['visitor_shots'])}
            elif  matchup_matrix[hpid][vpid]['home_shots'] - matchup_matrix[hpid][vpid]['visitor_shots'] == 0:
                # no arrow
                tmp_dic['delta'] = '{0}'.format(matchup_matrix[hpid][vpid]['home_shots'] - matchup_matrix[hpid][vpid]['visitor_shots'])
                tmp_dic['dataLabels'] = {'format': '{0}'.format(matchup_matrix[hpid][vpid]['home_shots'] - matchup_matrix[hpid][vpid]['visitor_shots'])}
            else:
                # left arrow
                tmp_dic['delta'] = '{0}{1}'.format('\u2BC7', matchup_matrix[hpid][vpid]['visitor_shots'] - matchup_matrix[hpid][vpid]['home_shots'])
                tmp_dic['dataLabels'] = {'format': '{0}{1}'.format('\u2BC7', matchup_matrix[hpid][vpid]['visitor_shots'] - matchup_matrix[hpid][vpid]['home_shots'])}
            data_list.append(tmp_dic)

    x_list = []
    x_list_mobile = []
    for player in lineup_dic['home_team']:
        x_list.append('{0} {1}'.format(lineup_dic['home_team'][player]['name'], lineup_dic['home_team'][player]['surname']))
        x_list_mobile.append('{0}. {1}'.format(lineup_dic['home_team'][player]['name'][0], lineup_dic['home_team'][player]['surname']))


    y_list = []
    y_list_mobile = []
    for player in lineup_dic['visitor_team']:
        y_list.append('{0} {1}'.format(lineup_dic['visitor_team'][player]['name'], lineup_dic['visitor_team'][player]['surname']))
        y_list_mobile.append('{0}. {1}'.format(lineup_dic['visitor_team'][player]['name'][0], lineup_dic['visitor_team'][player]['surname']))

    # x_plotlines
    x_plotlines = []
    for plot in plotline_dic['home_team']:
        x_plotlines.append({'color': '#ffffff', 'width': 4, 'value': plot - .5, 'zIndex': 4})

    # y_plotlines
    y_plotlines = []
    for plot in plotline_dic['visitor_team']:
        y_plotlines.append({'color': '#ffffff', 'width': 4, 'value': plot - .5, 'zIndex': 4})

    chart_options = {

        'chart': {
            'type': 'heatmap',
            'height': variable_dic['shotmap_height_pctg'],
            'style': chartstyle()
        },

        'exporting': exporting(filename=ctitle, allowhtml=0),
        'title': title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle': subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits': credit(),

        'tooltip': {
            'useHTML': 0,
            'headerFormat': None,
            'pointFormat': '<span><b>{point.home_name} vs, {point.visitor_name}</b></span><br/> <span style="font-size: %(fontsize)s"> {series.name}: {point.minsec} %(min)s</span><br /><span style="font-size: %(fontsize)s"><b>%(headline)s:</b><br /><span style="font-size: %(fontsize)s"> %(homeshots)s: {point.home_shots}</span><br/> <span style="font-size: %(fontsize)s"> %(visitorshots)s: {point.visitor_shots}</span><br/><span style="font-size: %(fontsize)s"> delta: {point.delta}<br />' % {'fontsize': font_size, 'min': 'min', 'headline': _('Shots while players on Ice'), 'homeshots': matchinfo_dic['home_team__shortcut'], 'visitorshots': matchinfo_dic['visitor_team__shortcut']},
        },

        'xAxis': {
            'categories': x_list,
            'opposite':1,
            'plotLines': x_plotlines,
            'labels': {'step': 1, 'rotation': -45}
        },

        'yAxis': {
            'categories': y_list,
            'title': '',
            'reversed': True,
            'plotLines': y_plotlines,
            'labels': {'step': 1}
        },

        'legend': {
            'title': {'text': _('Time on Ice'), 'style': {'fontStyle': 'lighter','fontSize': font_size}},
            'align': 'center',
            'layout': 'horizontal',
            'verticalAlign': 'bottom',
            'itemStyle': {'color': text_color, 'fontWeight': 'lighter', 'fontSize': font_size},
        },

        'colorAxis': {
            'min': 0,
            'minColor': '#FFFFFF',
            'maxColor': chart_color1,
            'labels': {'style': {'color': text_color, 'fontSize': font_size}},
        },

        'series': [{
            'name': _('Time on Ice'),
            'borderWidth': 1,
            'data': data_list,
            'dataLabels': {
                'enabled': 1,
                'useHTML': 0,
                # 'color': text_color,
                'style': {'fontSize': '8px', 'textOutline': 0, 'color': text_color}
            }
        }],

        'responsive': {
            'rules': [{
                'condition': {'maxWidth': 500},
                'chartOptions': {
                    'legend': {'title': {'text': _('Time on Ice'), 'style': {'fontStyle': 'lighter','fontSize': font_size_mobile}}},
                    'xAxis': {'categories': x_list_mobile, 'labels': {'style': {'fontSize': font_size_mobile}}},
                    'yAxis': {'categories': y_list_mobile, 'labels': {'style': {'fontSize': font_size_mobile}}},
                    'colorAxis': {'labels': {'style': {'color': text_color, 'fontSize': font_size_mobile}}},
                }
            }]
        }
    }
    return chart_options
コード例 #24
0
def chatterchart_create(logger, ctitle, csubtitle, ismobile, events_dic,
                        plotband_list):
    """ create chatter chart """
    logger.debug('chatterchart_create()')

    variable_dic = variables_get(ismobile)

    data_list = []
    x_list = []

    cnt = 0
    for _uts, event in sorted(events_dic.items()):

        # we need to count the amount of tweets to calculate the chartsize
        cnt += 1

        # on the fly timestamp for x-axis
        timestamp = uts_to_date_utc(date_to_uts_utc(event['created_at']),
                                    '%H:%M')

        if 'text_raw' in event:
            timestamp = uts_to_date_utc(
                int(date_to_uts_utc(event['created_at']) + 3600), '%H:%M')
            # this is a regular event
            text_shorten = textwrap.shorten(
                event['text_raw'], variable_dic['timeline_wrap_length'])
            data_list.append({
                'x': cnt,
                'name': timestamp,
                'aname': '@{0}'.format(event['name_alternate']),
                'scolor': twitter_color,
                'label': text_shorten,
                'description': event['text_raw'],
                'dataLabels': {
                    'style': {
                        'fontSize': variable_dic['timeline_font_size']
                    }
                }
            })
        else:
            # this is a goal
            data_list.append({
                'x': cnt,
                'name': timestamp,
                'aname': '#bot1337',
                'scolor': chart_color3,
                'color': event['color'],
                'label': event['name_alternate'],
                'dataLabels': {
                    'color': event['color'],
                    'style': {
                        'fontSize': variable_dic['timeline_font_size'],
                        'fontWeight': 'bold'
                    }
                }
            })

        x_list.append({'x': cnt, 'name': timestamp})

    # charthight depends on number of tweets - need to be calculated
    chart_height = variable_dic['ticker_startval'] + (
        cnt * variable_dic['ticker_multiplier'])

    chart_options = {
        'chart': {
            'type': 'timeline',
            'height': '{0}%'.format(chart_height),
            'inverted': 1,
            'zoomType': 'x',
            #'alignTicks': 0,
            'style': chartstyle()
        },
        'exporting':
        exporting(filename=ctitle),
        'title':
        title(ctitle, variable_dic['title_size'], decoration=True),
        'subtitle':
        subtitle(csubtitle, variable_dic['subtitle_size']),
        'credits':
        credit(),
        'plotOptions': {
            'timeline': {
                'dataLabels': {
                    'align': 'left',
                    'distance': variable_dic['timeline_distance'],
                    'alternate': 0
                }
            }
        },
        'tooltip': {
            'useHTML':
            1,
            'headerFormat':
            '',
            'pointFormat':
            '<span style="color: {point.scolor}"><b>{point.aname}</b></span><br>{point.description}',
        },
        'xAxis': {
            'categories': x_list,
            'visible': 1,
            'tickWidth': 0,
            'tickInterval': 3,
            'showFirstLabel': 1,
            'showLastLabel': 1,
            'lineWidth': 0,
            'labels': {
                'enabled': 1,
                'style': {
                    'fontSize': variable_dic['timeline_font_size']
                }
            },
            'plotBands': plotband_list,
        },
        'yAxis': {
            'gridLineWidth': 3,
            'title': '',
            'startOnTick': 0,
            'endOnTick': 0,
            'labels': {
                'enabled': 0
            },
            'width': 50
        },
        'colors': [chart_color6],
        'series': [{
            'dataLabels': {
                'allowOverlap': 1,
                'format': '{point.label}',
                'borderWidth': 0
            },
            'data': data_list
        }]
    }
    return chart_options
コード例 #25
0
def shotrates_updates_get(logger, data_dic):
    logger.debug('shotrates_updates_get()')

    updates_dic = {}

    for ele in data_dic:

        minmax_dic = {
            'x_min': round(data_dic[ele]['x_min'] - 1, 0),
            'y_min': round(data_dic[ele]['y_min'] - 1, 0),
            'x_max': round(data_dic[ele]['x_max'] + 1, 0),
            'y_max': round(data_dic[ele]['y_max'] + 1, 0)
        }

        updates_dic[ele] = {
            'text': ele,
            'chartoptions': {
                'series': [{
                    # pylint: disable=E0602
                    'name': _('Standard Deviation'),
                    'color': plotlines_color,
                    'marker': {
                        'symbol': 'square'
                    },
                    'data': data_dic[ele]['data']
                }],
                'xAxis': {
                    # pylint: disable=E0602
                    'title':
                    title(_('Corsi For per 60 minutes at 5v5 (Cf/60)'),
                          font_size),
                    'min':
                    minmax_dic['x_min'],
                    'max':
                    minmax_dic['x_max'],
                    'tickInterval':
                    1,
                    'gridLineWidth':
                    1,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['x_avg'] -
                        data_dic[ele]['x_deviation'] / 2,
                        'to':
                        data_dic[ele]['x_avg'] +
                        data_dic[ele]['x_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 2,
                        'value': data_dic[ele]['x_avg']
                    }],
                },
                'yAxis': {
                    # pylint: disable=E0602
                    'title':
                    title(_('Corsi Against per 60 minutes at 5v5 (Ca/60)'),
                          font_size),
                    'min':
                    minmax_dic['y_min'],
                    'max':
                    minmax_dic['y_max'],
                    'tickInterval':
                    1,
                    'gridLineWidth':
                    1,
                    'plotBands': [{
                        'from':
                        data_dic[ele]['y_avg'] -
                        data_dic[ele]['y_deviation'] / 2,
                        'to':
                        data_dic[ele]['y_avg'] +
                        data_dic[ele]['y_deviation'] / 2,
                        'color':
                        chart_color6
                    }],
                    'plotLines': [{
                        'zIndex': 3,
                        'color': plotlines_color,
                        'width': 3,
                        'value': data_dic[ele]['y_avg']
                    }],
                },
                # pylint: disable=E0602
                'annotations':
                corner_annotations(None, minmax_dic, _('Bad'), _('Dull'),
                                   _('Fun'), _('Good')),
            }
        }

    return updates_dic