コード例 #1
0
ファイル: ahit.py プロジェクト: twobackfromtheend/PyroPLANE
 def get_average_dribble_distance(hits):
     i = 0
     dribbleDistances = []
     dribbleHitNo = []
     while i < len(hits):
         # find full dribble
         hit = hits[i]
         dribbleHits = []
         if hit.dribble == 2:
             dribbleHits.append(hit)
             i += 1
             while hits[i].dribble:
                 dribbleHits.append(hit)
                 i += 1
             # add last dribble hit - it has .dribble=0
             dribbleHits.append(hits[i])
             
             dribbleDistance = misc.find_distance(dribbleHits[0].position,dribbleHits[-1].position)
             dribbleDistances.append(dribbleDistance)
             dribbleHitNo.append(len(dribbleHits))
         
         i += 1
     aveDribbleDistance = div(sum(dribbleDistances),len(dribbleDistances))
     aveDribbleHits = div(sum(dribbleHitNo),len(dribbleHitNo))
     
     return aveDribbleDistance,aveDribbleHits
コード例 #2
0
ファイル: ahit.py プロジェクト: twobackfromtheend/PyroPLANE
 def get_average_hit_distance(hits):
     distances = []
     for hit in hits:
         if hit.distance:
             distances.append(hit.distance)
     averageDistance = div(sum(distances),len(distances))
     
     return averageDistance
コード例 #3
0
ファイル: ahit.py プロジェクト: twobackfromtheend/PyroPLANE
 def get_average_shot_distance(hits):
     shotDistances = []
     for hit in hits:
         if hit.shot:
             shotDistances.append(hit.distanceToGoal)
     averageShotDistance = div(sum(shotDistances),len(shotDistances))
     
     return averageShotDistance
コード例 #4
0
    def analyse_player_positions_and_speed(self):
        positions = []
        speeds = []
        half = []
        third = []
        height = []
        ballHalf = []
        allPlayerPositions = {}
        allPlayerSpeeds = []
        # positions = []
        # ballPositions = []
        # speeds = []

        for player, ball in zip(self.playerObjects, self.ballObjects):
            playerPositions = {}  # frameNo:position. To sync with playerSpeeds
            ballPositions = {}
            playerSpeeds = {}
            for frameNo in player._framesToParse:
                playerPositions[frameNo] = player.positions[frameNo]
                ballPositions[frameNo] = ball.positions[frameNo]
                try:
                    playerSpeeds[frameNo] = APosition.get_speed(player.velocities[frameNo])
                except:
                    # print('Cannot find velocity for '+player.name+' at frame '+str(frameNo))
                    # print(list(x for x in list(player.velocities.keys()) if abs(x-frameNo)< 10))
                    # print(list(player.velocities.keys()))
                    # break
                    pass

            _positions, _speeds = APosition.get_positions_speed_analysis(
                playerPositions, playerSpeeds, player, ballPositions
            )

            x = []
            for value in playerPositions.values():
                x.append(value)
            allPlayerPositions[player] = x

            allPlayerSpeeds += list(playerSpeeds.values())

            positions.append(_positions)
            speeds.append(_speeds)

            # half.append(_half)
            # third.append(_third)
            # height.append(_height)
            # ballHalf.append(_ballHalf)

        # half = misc.merge_dicts(half)
        # third = misc.merge_dicts(third)
        # height = misc.merge_dicts(height)
        # ballHalf = misc.merge_dicts(ballHalf)

        speed = misc.merge_dicts(speeds)
        position = misc.merge_dicts(positions)

        total = 0
        for key in half:
            total += half[key]

        averagePosition, averagePositionV = APosition.get_average_position(allPlayerPositions)

        # position = dict(
        # half = half,
        # third = third,
        # height = height,
        # ball = ballHalf,
        # total = total,
        # average = averagePosition,
        # averageV = averagePositionV
        # )

        position["average"] = averagePosition
        position["averageV"] = averagePositionV
        position["total"] = sum(len(allPlayerPositions[x]) for x in allPlayerPositions)

        averageSpeed = div(sum(allPlayerSpeeds), len(allPlayerSpeeds))

        speed["average"] = averageSpeed
        print("Raw Position Data:")
        print(position)
        print("Raw Speed Data:")
        print("Total Speeds: " + str(len(allPlayerSpeeds)))
        y = {}
        for x in speed:
            if type(speed[x]) is list:
                y[x] = len(speed[x])
            elif type(speed[x]) is dict:
                y[x] = {}
                for q in speed[x]:
                    y[x][q] = len(speed[x][q])
            else:
                y[x] = speed[x]
        print(y)

        return position, speed
コード例 #5
0
    def output_all(player):
        hitsTotal = player.hits.get("total", 0)
        # print(player.hits)
        averageHitDistance = player.hits["aveHitDistance"]
        hitsAttacking = player.hits["half"].get(1, 0)
        shotsTotal = sum(player.hits["shot"][x] for x in player.hits["shot"] if x)
        averageShotDistance = round(player.hits["aveShotDistance"])

        goalsTotal = sum(player.hits["goal"][x] for x in player.hits["goal"] if x)
        assistedTotal = player.hits["goal"].get(2, 0)

        passesTotal = sum(player.hits["pass_"][x] for x in player.hits["pass_"] if x)
        assistsTotal = player.hits["pass_"].get(2, 0)
        secondAssistsTotal = player.hits["pass_"].get(3, 0)
        averagePassDistance = player.hits[
            "avePassDistance"
        ]  # sum(hit.distance for hit in player.hits if hit.pass_>=1)/passesTotal

        dribblesTotal = player.hits["dribble"].get(2, 0)
        averageDribbleDistance = player.hits[
            "aveDribbleDistance"
        ]  # sum(hit.distance for hit in player.hits if hit.dribble==1)/dribblesTotal
        averageDribbleHits = "{:.2}".format(float(player.hits["aveDribbleHits"]))

        savesTotal = player.hits["save"].get(1, 0)
        failedSavesTotal = player.hits["save"].get(-1, 0)

        # # get hit variables
        # for hit in player.hits:
        # if hit.half == 1:
        # hitsAttacking += 1
        # if hit.shot >= 1:
        # shotsTotal += 1
        # if hit.goal >= 1:
        # goalsTotal += 1
        # if hit.goal == 2:
        # assistedTotal += 1
        # if hit.pass_ >= 1:
        # passesTotal += 1
        # if hit.pass_ == 2:
        # assistsTotal += 1
        # elif hit.pass_ == 3:
        # secondAssistsTotal += 1
        # if hit.dribble == 2:
        # dribblesTotal += 1
        # if hit.save == 1:
        # savesTotal += 1
        # elif hit.save == -1:
        # failedSavesTotal += 1

        averagePosition = player.position["average"]
        averagePositionV = player.position["averageV"]

        output = player._name + "\n"
        output += "Total Hits: " + str(hitsTotal) + "\n"
        output += "Average Hit Distance: " + str(round(averageHitDistance)) + "\n"
        # hits
        # hitsDefending = sum(hit.half==0 for hit in player.hits)
        output += (
            "    Attacking Half: "
            + str(hitsAttacking)
            + " ("
            + "{:.1%}".format(div(hitsAttacking, hitsTotal))
            + ")    Defending Half: "
            + str(hitsTotal - hitsAttacking)
            + " ("
            + "{:.1%}".format(div((hitsTotal - hitsAttacking), hitsTotal))
            + ")\n"
        )
        # shots
        output += "Total Shots: " + str(shotsTotal) + " (" + "{:.1%}".format(div(shotsTotal, hitsTotal)) + ")\n"
        output += "    Average Shot Distance: " + str(round(averageShotDistance)) + "\n"
        output += "    Total Goals: " + str(goalsTotal) + " (" + "{:.1%}".format(div(goalsTotal, shotsTotal)) + ")\n"
        output += (
            "        Was Assisted: "
            + str(assistedTotal)
            + " ("
            + "{:.1%}".format(div(assistedTotal, goalsTotal))
            + ")\n"
        )
        # passes
        output += "Total Passes: " + str(passesTotal) + " (" + "{:.1%}".format(div(passesTotal, hitsTotal)) + ")\n"
        output += (
            "    Total Assists: " + str(assistsTotal) + " (" + "{:.1%}".format(div(assistsTotal, passesTotal)) + ")\n"
        )
        output += (
            "        Secondary Assists: "
            + str(secondAssistsTotal)
            + " ("
            + "{:.1%}".format(div(secondAssistsTotal, passesTotal))
            + ")\n"
        )
        output += "    Average Pass Distance: " + str(round(averagePassDistance)) + "\n"
        # dribbles
        output += (
            "Total Dribbles: " + str(dribblesTotal) + " (" + "{:.1%}".format(div(dribblesTotal, hitsTotal)) + ")\n"
        )
        output += "    Average Dribble Distance: " + str(round(averageDribbleDistance)) + "\n"
        output += "    Average Dribble Hits: " + str(averageDribbleHits) + "\n"
        # saves
        output += "Total Saves: " + str(savesTotal) + " (" + "{:.1%}".format(div(savesTotal, hitsTotal)) + ")\n"
        output += (
            "    Failed Saves: "
            + str(failedSavesTotal)
            + " ("
            + "{:.1%}".format(div(failedSavesTotal, hitsTotal))
            + ")\n"
        )

        # possession
        output += "\n"
        output += "Possession (by hit): " + "{:.1%}".format(player.possession["h"]) + "\n"
        output += "Possession (by position): " + "{:.1%}".format(player.possession["p"]) + "\n"

        # position
        positionsTotal = player.position["total"]
        inAttHalf = player.position["half"][1]
        inAttThird = player.position["third"][1]
        inMidThird = player.position["third"][0]
        inOwnThird = player.position["third"][-1]
        onGround = player.position["height"][0]
        underGoal = player.position["height"][1]
        aboveGoal = player.position["height"][2]

        frontOfBall = player.position["ball"]

        output += "\n"
        output += (
            "Average Position: "
            + str(list(int(x) for x in averagePosition))
            + "   v: "
            + str(list(list(int(y) for y in x) for x in averagePositionV))
            + "\n"
        )
        # print(player.position)

        output += (
            "In Attacking Half: "
            + "{:.1%}".format(div(inAttHalf, positionsTotal))
            + "    Defending Half: "
            + "{:.1%}".format(div((positionsTotal - inAttHalf), positionsTotal))
            + "\n"
        )

        output += (
            "In Attacking Third: "
            + "{:.1%}".format(div(inAttThird, positionsTotal))
            + "    Middle Third: "
            + "{:.1%}".format(div(inMidThird, positionsTotal))
            + "    Defending Third: "
            + "{:.1%}".format(div(inOwnThird, positionsTotal))
            + "\n"
        )

        output += (
            "On Ground: "
            + "{:.1%}".format(div(onGround, positionsTotal))
            + "    Under Goal: "
            + "{:.1%}".format(div(underGoal, positionsTotal))
            + "    Above Goal: "
            + "{:.1%}".format(div(aboveGoal, positionsTotal))
            + "\n"
        )
        output += (
            "In Front of Ball: "
            + "{:.1%}".format(div(frontOfBall[1], positionsTotal))
            + "    Behind Ball: "
            + "{:.1%}".format(div(frontOfBall[0], positionsTotal))
            + "\n"
        )

        # speed
        averageSpeed = player.speed["average"]
        speedAttacking = div(sum(player.speed["half"][1]), len(player.speed["half"][1]))
        speedDefending = div(sum(player.speed["half"][0]), len(player.speed["half"][0]))

        output += "\n"
        output += "Average Speed: " + str(round(averageSpeed)) + "\n"

        output += (
            "    In Attacking Half: "
            + str(round(speedAttacking))
            + "    In Defending Half: "
            + str(round(speedDefending))
        )

        output += "\n\n"

        return output