Пример #1
0
def predict(info, isNeutral, rangqiu):
    # homeTeam / awayTeam should be 'leagueName, homeTeam, awayTeam'
    league, home, away = info.split(',')

    # Read data
    f = open('teams/1516' + league + '.csv').readlines()
    for each in f:
        if home in each:
            homeName, homeAtt, homeDef = each.strip().split(',')
        elif away in each:
            awayName, awayAtt, awayDef = each.strip().split(',')
        elif '$home' in each:
            homeFactor = each.strip().split('=')[1]

    homeAtt = string.atof(homeAtt)
    homeDef = string.atof(homeDef)
    awayAtt = string.atof(awayAtt)
    awayDef = string.atof(awayDef)
    if isNeutral:
        homeFactor = 0
    else:
        homeFactor = string.atof(homeFactor)

    # get probtable
    data = probTable(homeAtt, homeDef, awayAtt, awayDef, homeFactor)

    # calc prediction
    nestedData = []
    pointer = 8
    while pointer <= 64:
        nestedData.append(data[pointer - 8:pointer])
        pointer += 8
    maxIndex = data.index(max(data))
    idealHomeScore = maxIndex / 8
    idealAwayScore = maxIndex % 8
    winProb = 0
    drawProb = 0
    loseProb = 0
    for i in range(0, 8):
        for j in range(0, 8):
            if (i + rangqiu < j):
                loseProb += nestedData[i][j]
            elif (i + rangqiu == j):
                drawProb += nestedData[i][j]
            elif (i + rangqiu > j):
                winProb += nestedData[i][j]

    print 'Prediction of ' + home + ' vs ' + away
    if (rangqiu != 0):
        print 'With Rangqiu of ' + str(rangqiu)
    print 'Win: ' + str(round(winProb * 100, 2)) + '\t' + 'Draw: ' + str(
        round(drawProb * 100, 2)) + '\t' + 'Lose: ' + str(
            round(loseProb * 100, 2))
    print 'Recommended Score: ' + str(idealHomeScore) + ' - ' + str(
        idealAwayScore) + ', with Prob: ' + str(
            nestedData[idealHomeScore][idealAwayScore])
Пример #2
0
def predict(info, isNeutral, rangqiu):
    # homeTeam / awayTeam should be 'leagueName, homeTeam, awayTeam'
    league, home, away = info.split(',')

    # Read data
    f = open('teams/1516'+league + '.csv').readlines()
    for each in f:
        if home in each:
            homeName, homeAtt, homeDef = each.strip().split(',')
        elif away in each:
            awayName, awayAtt, awayDef = each.strip().split(',')
        elif '$home' in each:
            homeFactor = each.strip().split('=')[1]

    homeAtt = string.atof(homeAtt)
    homeDef = string.atof(homeDef)
    awayAtt = string.atof(awayAtt)
    awayDef = string.atof(awayDef)
    if isNeutral:
        homeFactor = 0
    else:
        homeFactor = string.atof(homeFactor)

    # get probtable
    data = probTable(homeAtt, homeDef, awayAtt, awayDef, homeFactor)

    # calc prediction
    nestedData = []
    pointer = 8
    while pointer <= 64:
        nestedData.append(data[pointer - 8:pointer])
        pointer += 8
    maxIndex = data.index(max(data))
    idealHomeScore = maxIndex / 8
    idealAwayScore = maxIndex % 8
    winProb = 0
    drawProb = 0
    loseProb = 0
    for i in range(0, 8):
        for j in range(0, 8):
            if (i + rangqiu < j):
                loseProb += nestedData[i][j]
            elif (i + rangqiu == j):
                drawProb += nestedData[i][j]
            elif (i + rangqiu > j):
                winProb += nestedData[i][j]


    print 'Prediction of ' + home + ' vs ' + away
    if (rangqiu != 0):
        print 'With Rangqiu of ' + str(rangqiu)
    print 'Win: ' + str(round(winProb*100, 2)) + '\t' + 'Draw: ' + str(round(drawProb*100, 2)) + '\t' + 'Lose: ' + str(round(loseProb*100, 2))
    print 'Recommended Score: ' + str(idealHomeScore) + ' - ' + str(idealAwayScore) + ', with Prob: ' + str(nestedData[idealHomeScore][idealAwayScore])
Пример #3
0
    # update the league
    for each in leagueDict:
        originData = leagueDict[each]
        newData = [originData[0] + aC, originData[1] + dC]
        leagueDict[each] = newData

    # record
    g = open('teams/1516' + league + '.csv', 'w')
    for each in leagueDict:
        tempString = each + ',' + str(leagueDict[each][0]) + ',' + str(
            leagueDict[each][1]) + '\n'
        g.write(tempString)

    g.write(home + '\n')

    g.close()


homeTeam, homeAtt, homeDef = 'Monaco', 0.501548040131, 0.413951616658
awayTeam, awayAtt, awayDef = 'Tottenham Hotspur', 0.220248413429, -0.413833298416

homeFactor = [0.2639907]
homeScore, awayScore = 1, 1

data = probTable(homeAtt, homeDef, awayAtt, awayDef, homeFactor[0])
a = match(data, homeScore, awayScore, [homeAtt, homeDef, awayAtt, awayDef])
print a
updateLeague('fra1', homeTeam, a[0])
updateLeague('eng1', awayTeam, a[1])
print 'done'
Пример #4
0
    aC = (string.atof(updateA[0]) - matchTeam[0])
    dC = (string.atof(updateA[1]) - matchTeam[1])

    # update the league
    for each in leagueDict:
        originData = leagueDict[each]
        newData = [originData[0] + aC, originData[1] + dC]
        leagueDict[each] = newData

    # record
    g = open('teams/1516' + league + '.csv', 'w')
    for each in leagueDict:
        tempString = each + ',' + str(leagueDict[each][0]) + ',' + str(leagueDict[each][1]) + '\n'
        g.write(tempString)

    g.write(home + '\n')

    g.close()

homeTeam, homeAtt, homeDef = 'Monaco',0.501548040131,0.413951616658
awayTeam, awayAtt, awayDef = 'Tottenham Hotspur',0.220248413429,-0.413833298416

homeFactor = [0.2639907]
homeScore, awayScore = 1,1

data = probTable(homeAtt,homeDef,awayAtt,awayDef,homeFactor[0])
a = match(data, homeScore, awayScore, [homeAtt,homeDef,awayAtt,awayDef])
print a
updateLeague('fra1', homeTeam, a[0])
updateLeague('eng1', awayTeam, a[1])
print 'done'