def __init__(self, line, pt):
     self.cycle = 0
     self.players = []
     self.ball = ball.Ball()
     self.kicker = player.Player()
     self.side_playing = "n"
     self.make(line, pt)
def run_logzip(log, player_types):
    os.chdir("../samples")
    new_log = open(str(counter()) + ".rca.gz", "wb")
    play_on = False
    # write types in file
    for pt in player_types:
        new_line = "pt " + str(pt.id) + " " + str(pt.kickAble_area) + "\n"
        new_log.write(gzip.compress(new_line.encode()))
    for line in log.split("\n"):
        if line.find("playmode") != -1:
            if line.find("play_on") != -1:
                play_on = True
                new_log.write(gzip.compress(b"*\n"))
            else:
                play_on = False
        # if not play_on:
        #     continue
        if line.find("show") == -1:
            continue
        #Seprate
        show_str = line[:line.find("(b)") - 2].strip("()")
        line = line[line.find("(b)") - 1:]
        ball_str = line[:line.find("(l ") - 2].strip("()")
        line = line[line.find("(l ") - 0:].strip("()")
        players_str = line.split(")) ((")
        #Cycle
        cycle = int(show_str.split(" ")[1].strip(")("))

        #Ball
        ball_str = ball_str.split(" ")
        ballobj = ball.Ball()
        ballobj.pos.set(ball_str[1], ball_str[2])
        ballobj.vel.set(ball_str[3], ball_str[4])

        #setPlayers
        players = []
        for player_str in players_str:
            player_str = player_str.split(" (")
            player_details = []
            for player_d in player_str:
                x = player_d.split(" ")
                xx = []
                for i in range(len(x)):
                    x[i] = x[i].strip(")(")
                    if (x[i][0] != 'f'):
                        xx.append(x[i])
                player_details.append(xx)
            plyr = player.Player()
            plyr.set(player_details, player_types)
            players.append(plyr)

        # Write in file
        # new_line = "R|"
        new_line = ""
        new_line += str(cycle) + "|"
        new_line += str(ballobj.pos.x) + " " + str(
            ballobj.pos.y
        ) + "|"  #+ " " + str(ballobj.vel.x) + " " + str(ballobj.vel.y) + "|"
        for plyr in players:
            new_line += plyr.side + " " + str(plyr.unum) + " " + str(
                plyr.playerType.id) + " "
            new_line += str(plyr.pos.x) + " " + str(
                plyr.pos.y
            ) + "|"  #" " + str(plyr.vel.x) + " " + str(plyr.vel.y) + " "
            new_line += str(plyr.body) + " " + str(plyr.head) + "|"
        new_line += "\n"
        new_log.write(gzip.compress(new_line.encode()))
        # print("samples:",cycle)
    os.chdir("../orginalLogs")
Exemplo n.º 3
0
def extractFeatur(log, player_types):
    os.chdir("../features")
    file_name = str(counter())
    new_log = open(file_name + ".rcb", "w")
    # write types in file
    for pt in player_types:
        new_log.write("pt " + str(pt.id) + " " + str(pt.kickAble_area) + "\n")
    lines = log.split("\n")

    last_kickAble_cycle = -10
    last_kickAble_unum = -1
    for line in lines:
        #Reading a cycle data
        if line.find("*") != -1:
            last_kickAble_unum = -1
            last_kickAble_cycle = -10
        if (line.find("R") == -1):
            continue
        details = line.split("|")
        cycle = int(details[1])
        ballobj = ball.Ball()
        ballobj.set_data(details[2])

        players = []
        for ply_str in details:
            if ply_str == '':
                continue
            if ply_str[0] != "r" and ply_str[0] != "l":
                continue
            playerobj = player.Player()
            playerobj.set_data(ply_str, player_types)
            players.append(playerobj)

        if not side(players, ballobj, "l"):
            if side(players, ballobj, "r"):
                last_kickAble_unum = -1
                last_kickAble_cycle = -10
            continue

        n = 0
        for i in range(len(players)):
            if players[i].is_kickAble(ballobj.pos) and players[i].side == "l":
                n = i
                break
        polars = []
        polars_n = []
        kicker = players[n]
        for plyr in players:
            teta = plyr.pos.teta(kicker.pos)
            r = plyr.pos.dist(kicker.pos)
            polar = pos.Polar(r, teta)
            polars.append(polar)
            next_pos = pos.plus(plyr.pos, plyr.vel)
            teta_n = next_pos.teta(kicker.pos)
            r_n = next_pos.dist(kicker.pos)
            polar_n = pos.Polar(r_n, teta_n)
            polars_n.append(polar_n)
        new_line = ""
        new_line += "R|" + str(cycle) + "|"
        #find polar pos and vel of ball
        teta_b = ballobj.pos.teta(kicker.pos)
        r_b = ballobj.pos.dist(kicker.pos)
        polar_b = pos.Polar(r_b, teta_b)
        next_ballpos = pos.Pos(ballobj.pos.x + ballobj.vel.x,
                               ballobj.pos.y + ballobj.vel.y)
        teta_vb = next_ballpos.teta(ballobj.pos)
        r_vb = ballobj.vel.r()
        polar_vb = pos.Polar(r_vb, teta_vb)
        new_line += str(polar_b.r) + " " + str(polar_b.teta) + " " + str(
            polar_vb.r) + " " + str(polar_vb.teta) + "|"
        for i_p in range(len(polars)):
            new_line += str(polars[i_p].r) + " " + str(polars[i_p].teta) + "|"
        #     new_line += str(polars_n[i_p].r) + " " + str(polars_n[i_p].teta) + "|"
        # for plyr in players:
        #     new_line += str(plyr.pos.x/52.5) + " " + str(plyr.pos.y/34) + "|"
        new_line += str(last_kickAble_unum) + " " + str(kicker.unum) + "|"
        if last_kickAble_unum != -1:
            new_log.write(new_line + "\n")
        last_kickAble_unum = kicker.unum
        # print("feature:",cycle)
    new_log.close()
    f_log = open(file_name + ".rcb", "r").read()
    new_log = open(file_name + ".rcb", "w")
    lines = f_log.split("\n")
    for i in range(len(lines) - 2):
        if lines[i].find("pt") != -1:
            continue
        line = lines[i].split("|")[:-1]
        next_line = lines[i + 1].split("|")[:-1]
        line[-1] = next_line[-1]
        newline = ""
        for w in line:
            newline += w + "|"
        new_log.write(newline + "\n")
    os.chdir("../samples")