Example #1
0
    return (debug, season, match_list, addshifts, openmatches, pastmatches,
            interval, allmatches, xg_data, xg_weights)


if __name__ == '__main__':

    # get variables
    (DEBUG, SEASON_ID, MATCH_LIST, ADDSHIFTS, OPENMATCHES, PASTMATCHES,
     INTERVAL, ALLMATCHES, XG_DATA, XG_WEIGHTS) = arg_parse()

    # initialize logger
    LOGGER = logger_setup(DEBUG)

    # unix timestamp
    UTS = uts_now()

    if not SEASON_ID:
        # get season_id
        SEASON_ID = season_latest_get(LOGGER)

    if not MATCH_LIST:
        if ALLMATCHES:
            MATCH_LIST = []
        elif OPENMATCHES:
            # Get list of matches to be updated (selection current season, status finish_false, date lt_uts)
            MATCH_LIST = openmatch_list_get(LOGGER, SEASON_ID, UTS,
                                            ['match_id'])
        elif PASTMATCHES:
            MATCH_LIST = pastmatch_list_get(LOGGER, SEASON_ID, UTS,
                                            ['match_id'])
Example #2
0
    input_parameters = _inputparameters_get(LOGGER, PARAMETER_FILE, START_VAL, MAX_VAL, STEP)

    from pprint import pprint
    pprint(input_parameters)

    # get global shot and goal stats
    (g_shotstat_dic, g_goal_dic) = shotstats_get(LOGGER, MATCH_LIST)

    # load result dic from file to continue on a certain point
    if os.path.exists(RESULT_FILE):
        g_result_dic = json_load(RESULT_FILE)
    else:
        g_result_dic = {'home_correct': [], 'visitor_correct': [], 'winloss_correct': [], 'result_correct': []}

    # set startpoint for measurement
    uts_start = uts_now()

    # initialze counter
    G_CNT = 0
    for shots_pctg in np.arange(START_VAL, input_parameters['shots_pctg']['max'] + input_parameters['shots_pctg']['step'], input_parameters['shots_pctg']['step']):
        if shots_pctg < input_parameters['shots_pctg']['start']:
            continue
        else:
            input_parameters['shots_pctg']['start'] = START_VAL

        for handness_pctg in np.arange(START_VAL, input_parameters['handness_pctg']['max'] + input_parameters['handness_pctg']['step'], input_parameters['handness_pctg']['step']):
            if handness_pctg < input_parameters['handness_pctg']['start']:
                continue
            else:
                input_parameters['handness_pctg']['start'] = START_VAL
Example #3
0
    return (debug, season, tournament)


if __name__ == '__main__':

    # create pseudo-device for REST-API calls against mobile api
    DEVICE_ID = '00155d8aecc66666'

    # get commandline arguments
    (DEBUG, SEASON_ID, TOURNAMENT_ID) = arg_parse()

    # initialize logger
    LOGGER = logger_setup(DEBUG)

    UTS_NOW = uts_now()

    if not SEASON_ID:
        # get season_id
        SEASON_ID = season_latest_get(LOGGER)

    if not TOURNAMENT_ID:
        # get tournamentid based on season_id
        TOURNAMENT_ID = season_get(LOGGER, 'id', SEASON_ID, ['tournament'])

    # get team_list
    TEAM_DIC = list2dic(
        LOGGER, list(team_list_get(LOGGER, None, None,
                                   ['team_id', 'shortcut'])), 'shortcut')

    with DelAppHelper(DEVICE_ID, DEBUG) as del_app_helper:
Example #4
0
def matchdays_get(logger, request, fkey=None, fvalue=None, vlist=('match_id', 'season', 'date', 'date_uts', 'home_team__shortcut', 'home_team__team_name', 'home_team__logo', 'visitor_team__team_name', 'visitor_team__shortcut', 'visitor_team__logo', 'result')):
    """ matches grouped by days """
    logger.debug('matchdays_get({0}:{1})'.format(fkey, fvalue))

    if not fkey:
        (fkey, fvalue) = _seasonid_get(logger, request)

    # reuse of an existing function from match
    match_list = match_list_get(logger, fkey, fvalue, vlist)

    matchday_dic = {}
    matchday_uts_dic = {}
    lastmday_uts = 0
    firstmday_uts = 9999999999
    lastmday_human = ''
    firstmday_human = ''

    # we need the url to be added to the logo URL
    if request and request.META:
        base_url = url_build(request.META)
    else:
        base_url = ''

    # we need to group the list by matchdays
    for match in sorted(match_list, key=lambda i: i['date_uts'], reverse=False):
    # for match in match_list:
        dateobj = datestr_to_date(match['date'], '%Y-%m-%d')
        match_day = date_to_datestr(dateobj, '%d.%m.%Y')
        match_uts = date_to_uts_utc(match['date'], '%Y-%m-%d')

        # we need the completed matchday to set the display key to true
        if match['date_uts'] > lastmday_uts:
            if uts_now() >  match['date_uts']:
                lastmday_uts =  match['date_uts']
                lastmday_human = match['date']
        # we need the first machday for cornercase handling (begin of season with no matches yet)
        if match['date_uts'] <= firstmday_uts:
            firstmday_uts =  match['date_uts']
            firstmday_human = match['date']

        if match['date'] not in matchday_dic:
            matchday_dic[match['date']] = {
                'date': match_day,
                'uts': match_uts,
                'matches': [],
                'displayday': False
            }
            # we need this dictionary to lookup the previous and next matchdate
            matchday_uts_dic[match_uts] = match['date']

        # rename a few keys to make the output better understandable
        match['home_team_shortcut'] = match.pop('home_team__shortcut')
        match['home_team_name'] = match.pop('home_team__team_name')
        match['home_team_logo'] = '{0}{1}{2}'.format(base_url, settings.STATIC_URL, match.pop('home_team__logo'))
        match['visitor_team_shortcut'] = match.pop('visitor_team__shortcut')
        match['visitor_team_name'] = match.pop('visitor_team__team_name')
        match['visitor_team_logo'] = '{0}{1}{2}'.format(base_url, settings.STATIC_URL, match.pop('visitor_team__logo'))

        matchday_dic[match['date']]['matches'].append(match)

    if matchday_dic and lastmday_human:
        # set displayflag to last matchday (during season this should be the case)
        matchday_dic[lastmday_human]['displayday'] = True
    elif matchday_dic and firstmday_human:
        # set displayflag to first matchday (no matches in season yet)
        matchday_dic[firstmday_human]['displayday'] = True

    # add references to previous and next matchdate
    matchday_dic = matchdays_previous_next_add(logger, matchday_dic, matchday_uts_dic)

    logger.debug('match_list_get({0}:{1}) ended with {2}'.format(fkey, fvalue, bool(match_list)))
    return matchday_dic
Example #5
0
def weights_finetune(logger, uts_start, result_file, g_result_dic,
                     g_shotstat_dic, g_goal_dic, xgmodel_dic, rebound_interval,
                     break_interval, loop_dic):
    """ this is the main finetuner """
    g_cnt = 0
    for shots_pctg in np.arange(loop_dic['shots_pctg']['start'],
                                loop_dic['shots_pctg']['max'],
                                loop_dic['shots_pctg']['step']):
        for handness_pctg in np.arange(loop_dic['handness_pctg']['start'],
                                       loop_dic['handness_pctg']['max'],
                                       loop_dic['handness_pctg']['step']):
            for handness_shots_pctg in np.arange(
                    loop_dic['handness_shots_pctg']['start'],
                    loop_dic['handness_shots_pctg']['max'],
                    loop_dic['handness_shots_pctg']['step']):
                for rb_pctg in np.arange(loop_dic['rb_pctg']['start'],
                                         loop_dic['rb_pctg']['max'],
                                         loop_dic['rb_pctg']['step']):
                    for rb_shots_pctg in np.arange(
                            loop_dic['rb_shots_pctg']['start'],
                            loop_dic['rb_shots_pctg']['max'],
                            loop_dic['rb_shots_pctg']['step']):
                        for br_pctg in np.arange(loop_dic['br_pctg']['start'],
                                                 loop_dic['br_pctg']['max'],
                                                 loop_dic['br_pctg']['step']):
                            for br_shots_pctg in np.arange(
                                    loop_dic['br_shots_pctg']['start'],
                                    loop_dic['br_shots_pctg']['max'],
                                    loop_dic['br_shots_pctg']['step']):
                                g_cnt += 1
                                # print(round(shots_pctg, 1), round(handness_pctg, 1), round(handness_shots_pctg, 1), round(rb_pctg, 1), round(rb_shots_pctg, 1), round(br_pctg, 1), round(br_shots_pctg, 1))
                                quantifier_dic = {
                                    'home': {
                                        'shots_pctg':
                                        round(shots_pctg, 1),
                                        'handness_pctg':
                                        round(handness_pctg, 1),
                                        'handness_shots_pctg':
                                        round(handness_shots_pctg, 1),
                                        'rb_pctg':
                                        round(rb_pctg, 1),
                                        'rb_shots_pctg':
                                        round(rb_shots_pctg, 1),
                                        'br_pctg':
                                        round(br_pctg, 1),
                                        'br_shots_pctg':
                                        round(br_shots_pctg, 1),
                                    },
                                    'visitor': {
                                        'shots_pctg':
                                        round(shots_pctg, 1),
                                        'handness_pctg':
                                        round(handness_pctg, 1),
                                        'handness_shots_pctg':
                                        round(handness_shots_pctg, 1),
                                        'rb_pctg':
                                        round(rb_pctg, 1),
                                        'rb_shots_pctg':
                                        round(rb_shots_pctg, 1),
                                        'br_pctg':
                                        round(br_pctg, 1),
                                        'br_shots_pctg':
                                        round(br_shots_pctg, 1),
                                    }
                                }

                                match_cnt = 0
                                home_correct = 0
                                visitor_correct = 0
                                winloss_correct = 0
                                result_correct = 0

                                for match_id in g_shotstat_dic:
                                    match_cnt += 1

                                    playerxgf_dic = xgf_calculate(
                                        logger, g_shotstat_dic[match_id],
                                        quantifier_dic)
                                    xgf_dic = xgscore_get(
                                        logger, playerxgf_dic)
                                    # convert xg to make them comparable with 5v5 goals
                                    xgf_dic['home'] = int(
                                        round(xgf_dic['home'], 0))
                                    xgf_dic['visitor'] = int(
                                        round(xgf_dic['visitor'], 0))
                                    # print(xgf_dic['home'], xgf_dic['visitor'], g_goal_dic[match_id]['home'], g_goal_dic[match_id]['visitor'])

                                    # check homescore
                                    if xgf_dic['home'] == g_goal_dic[match_id][
                                            'home']:
                                        home_correct += 1
                                    # check visitor score
                                    if xgf_dic['visitor'] == g_goal_dic[
                                            match_id]['visitor']:
                                        visitor_correct += 1

                                    # check full score
                                    if xgf_dic['home'] == g_goal_dic[match_id][
                                            'home'] and xgf_dic[
                                                'visitor'] == g_goal_dic[
                                                    match_id]['visitor']:
                                        result_correct += 1

                                    # check for winloss
                                    if xgf_dic['home'] < xgf_dic[
                                            'visitor'] and g_goal_dic[
                                                match_id]['home'] < g_goal_dic[
                                                    match_id]['visitor']:
                                        winloss_correct += 1
                                    elif xgf_dic['home'] > xgf_dic[
                                            'visitor'] and g_goal_dic[
                                                match_id]['home'] > g_goal_dic[
                                                    match_id]['visitor']:
                                        winloss_correct += 1
                                    elif xgf_dic['home'] == xgf_dic[
                                            'visitor'] and g_goal_dic[
                                                match_id]['home'] == g_goal_dic[
                                                    match_id]['visitor']:
                                        winloss_correct += 1

                                tmp_dic = {
                                    'g_cnt': g_cnt,
                                    'match_cnt': match_cnt,
                                    'home_correct': home_correct,
                                    'visitor_correct': visitor_correct,
                                    'winloss_correct': winloss_correct,
                                    'result_correct': result_correct,
                                    'quantifier_dic': quantifier_dic
                                }
                                # store results in different trees
                                g_result_dic['home_correct'].append(tmp_dic)
                                g_result_dic['visitor_correct'].append(tmp_dic)
                                g_result_dic['winloss_correct'].append(tmp_dic)
                                g_result_dic['result_correct'].append(tmp_dic)

                print(
                    '{0}: {4}: dump shots_pctg: {1}, handness_pctg: {2}, handness_shots_pctg: {3}'
                    .format(uts_now() - uts_start, round(shots_pctg, 1),
                            round(handness_pctg, 1),
                            round(handness_shots_pctg, 1), g_cnt))
                # dump here
                g_result_dic = _dump_it(g_result_dic, result_file)

    return g_result_dic
Example #6
0
    # get model from database for file
    # XGMODEL_DIC = xgmodel_get(LOGGER)
    XGMODEL_DIC = json_load(MODEL_FILE)

    # load the dictinary created by weightener
    WEIGHT_DIC = json_load(WEIGHT_FILE)

    # get list of matches to investigate
    MATCH_LIST = match_list_get(LOGGER, 'season_id', 1, ['match_id'])

    # get global shot and goal stats
    (G_SHOTSTAT_DIC, G_GOAL_DIC) = _shotstats_get(LOGGER, MATCH_LIST)

    # set startpoint for measurement
    UTS_START = uts_now()
    G_RESULT_DIC = {
        'home_correct': [],
        'visitor_correct': [],
        'winloss_correct': [],
        'result_correct': []
    }

    # iteratee over dictionary and take the TOPxxx
    for section in WEIGHT_DIC.keys():
        LOGGER.info('start processing section: {0}'.format(section))
        for parameter_set in WEIGHT_DIC[section][:2]:
            quantifier_dic = parameter_set['quantifier_dic']
            # calculate ranges to loop through
            loop_dic = _loopranges_get(LOGGER, quantifier_dic, DEVIATION,
                                       STEP_SIZE)