def extract_data(dat):
    """
    Function to extract data from api in particular
    separate players data from the match data
    perform basic filtering of removing invalid_matches
    invalid matches are those where all players ids are known
    and the result is known (i.e. not missing)
    also adds match_id to the players dataset
    """
    PLAYERS = []
    MATCHES = []
    for row in dat:
        VALID_MATCH = True
        PLAYERS_ROW = []
        match_id = row["match_id"]
        players = row["players"]
        for player in players:
            if player["profile_id"] is None or player["won"] is None:
                VALID_MATCH = False
            player["match_id"] = match_id
            PLAYERS_ROW.append(player)
        if VALID_MATCH:
            for i in PLAYERS_ROW:
                PLAYERS.append(i)
            MATCHES.append(row)
    return {"matches": MATCHES, "players": PLAYERS}