From 6df6ed385368d29ea935b624abbfcd16703a7781 Mon Sep 17 00:00:00 2001 From: JanEickholt Date: Tue, 1 Aug 2023 04:35:34 +0200 Subject: [PATCH 1/4] implemented #126 --- main.py | 59 ++++++++++++++++++++++++++++++++++----------------- src/colors.py | 4 +++- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index 80d7ff48..e3d950d9 100644 --- a/main.py +++ b/main.py @@ -268,9 +268,11 @@ def program_exit(status: int): # so we don't need to import the entire sys modu for p in Players: if p["Subject"] == Requests.puuid: allyTeam = p["TeamID"] + break for player in Players: status.update(f"Loading players... [{playersLoaded}/{len(Players)}]") playersLoaded += 1 + last_seen = 0 if player["Subject"] in stats_data.keys(): if player["Subject"] != Requests.puuid and player["Subject"] not in partyMembersList: @@ -286,28 +288,41 @@ def program_exit(status: int): # so we don't need to import the entire sys modu m_set = () for m in stats_data[player["Subject"]]: if m["match_id"] != coregame.match_id and m["match_id"] not in m_set: + if m["epoch"] > last_seen: + # get the last match they played with or against you + last_seen = m["epoch"] + # saves if they were on your team or not, defaults to true for old data + teammate = m.get("team", True) times += 1 m_set += (m["match_id"],) + + if teammate: + team = "with" + else: + team = "against" + if player["PlayerIdentity"]["Incognito"] == False: already_played_with.append( - { - "times": times, - "name": curr_player_stat["name"], - "agent": curr_player_stat["agent"], - "time_diff": time.time() - curr_player_stat["epoch"] - }) + { + "times": times, + "name": curr_player_stat["name"], + "agent": curr_player_stat["agent"], + "time_diff": time.time() - curr_player_stat["epoch"], + "team": team + }) else: if player["TeamID"] == allyTeam: team_string = "your" else: team_string = "enemy" already_played_with.append( - { - "times": times, - "name": agent_dict[player["CharacterID"].lower()] + " on " + team_string + " team", - "agent": curr_player_stat["agent"], - "time_diff": time.time() - curr_player_stat["epoch"] - }) + { + "times": times, + "name": agent_dict[player["CharacterID"].lower()] + " on " + team_string + " team", + "agent": curr_player_stat["agent"], + "time_diff": time.time() - curr_player_stat["epoch"], + "team": team + }) party_icon = '' @@ -346,12 +361,17 @@ def program_exit(status: int): # so we don't need to import the entire sys modu if player["PlayerIdentity"]["Incognito"]: Namecolor = colors.get_color_from_team(player["TeamID"], - names[player["Subject"]], - player["Subject"], Requests.puuid, agent=player["CharacterID"], party_members=partyMembersList) + names[player["Subject"]], + player["Subject"], Requests.puuid, + agent=player["CharacterID"], + party_members=partyMembersList, + already_seen=bool(last_seen)) else: Namecolor = colors.get_color_from_team(player["TeamID"], - names[player["Subject"]], - player["Subject"], Requests.puuid, party_members=partyMembersList) + names[player["Subject"]], + player["Subject"], Requests.puuid, + party_members=partyMembersList, + already_seen=bool(last_seen)) if lastTeam != player["TeamID"]: if lastTeamBoolean: table.add_empty_row() @@ -435,6 +455,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu "rr": rr, "match_id": coregame.match_id, "epoch": time.time(), + "team": player["TeamID"] == allyTeam } } ) @@ -695,7 +716,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu if game_state == "INGAME": if isRange: table.set_runtime_col_flag('Party', False) - table.set_runtime_col_flag('Agent',False) + table.set_runtime_col_flag('Agent', False) # We don't to show the RR column if the "aggregate_rank_rr" feature flag is True. table.set_runtime_col_flag('RR', cfg.table.get("rr") and not cfg.get_feature_flag("aggregate_rank_rr")) @@ -716,8 +737,8 @@ def program_exit(status: int): # so we don't need to import the entire sys modu if len(already_played_with) > 0: print("\n") for played in already_played_with: - print(f"Already played with {played['name']} (last {played['agent']}) {stats.convert_time(played['time_diff'])} ago. (Total played {played['times']} times)") - chatlog(f"Already played with {played['name']} (last {played['agent']}) {stats.convert_time(played['time_diff'])} ago. (Total played {played['times']} times)") + print(f"Already played {played['team']} {played['name']} (last {played['agent']}) {stats.convert_time(played['time_diff'])} ago. (Total played {played['times']} times)") + chatlog(f"Already played {played['team']} {played['name']} (last {played['agent']}) {stats.convert_time(played['time_diff'])} ago. (Total played {played['times']} times)") already_played_with = [] if cfg.cooldown == 0: input("Press enter to fetch again...") diff --git a/src/colors.py b/src/colors.py index 04a2a8bd..ee35dc3d 100644 --- a/src/colors.py +++ b/src/colors.py @@ -9,7 +9,7 @@ def __init__(self, hide_names, agent_dict, AGENTCOLORLIST): self.tier_dict = tierDict self.AGENTCOLORLIST = AGENTCOLORLIST - def get_color_from_team(self, team, name, playerPuuid, selfPuuid, agent=None, party_members=None): + def get_color_from_team(self, team, name, playerPuuid, selfPuuid, agent=None, party_members=None, already_seen=None): orig_name = name if agent is not None: if self.hide_names: @@ -29,6 +29,8 @@ def get_color_from_team(self, team, name, playerPuuid, selfPuuid, agent=None, pa Teamcolor = color(orig_name, fore=(76, 151, 237)) else: Teamcolor = '' + if already_seen: + Teamcolor = color(orig_name, fore=(10, 211, 8)) if playerPuuid == selfPuuid: Teamcolor = color(orig_name, fore=(221, 224, 41)) return Teamcolor From e1633fe978b07d3539762742d830388e973647e1 Mon Sep 17 00:00:00 2001 From: JanEickholt Date: Tue, 1 Aug 2023 11:12:44 +0200 Subject: [PATCH 2/4] removed redundant check thanks to the review comment by [zayKenyon]( https://github.com/zayKenyon/VALORANT-rank-yoinker/pull/163#discussion_r1280071844) --- main.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index e3d950d9..366dd9b2 100644 --- a/main.py +++ b/main.py @@ -272,7 +272,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu for player in Players: status.update(f"Loading players... [{playersLoaded}/{len(Players)}]") playersLoaded += 1 - last_seen = 0 + times = 0 if player["Subject"] in stats_data.keys(): if player["Subject"] != Requests.puuid and player["Subject"] not in partyMembersList: @@ -284,15 +284,11 @@ def program_exit(status: int): # so we don't need to import the entire sys modu curr_player_stat = stats_data[player["Subject"]][-i] if curr_player_stat["match_id"] != coregame.match_id: #checking for party memebers and self players - times = 0 m_set = () for m in stats_data[player["Subject"]]: if m["match_id"] != coregame.match_id and m["match_id"] not in m_set: - if m["epoch"] > last_seen: - # get the last match they played with or against you - last_seen = m["epoch"] - # saves if they were on your team or not, defaults to true for old data - teammate = m.get("team", True) + # saves if they were on your team or not, defaults to true for old data + teammate = m.get("team", True) times += 1 m_set += (m["match_id"],) @@ -365,13 +361,13 @@ def program_exit(status: int): # so we don't need to import the entire sys modu player["Subject"], Requests.puuid, agent=player["CharacterID"], party_members=partyMembersList, - already_seen=bool(last_seen)) + already_seen=bool(times)) else: Namecolor = colors.get_color_from_team(player["TeamID"], names[player["Subject"]], player["Subject"], Requests.puuid, party_members=partyMembersList, - already_seen=bool(last_seen)) + already_seen=bool(times)) if lastTeam != player["TeamID"]: if lastTeamBoolean: table.add_empty_row() From 77ff8a5a67d5d0be97267b2d03f720efe7aec797 Mon Sep 17 00:00:00 2001 From: JanEickholt Date: Tue, 1 Aug 2023 11:38:45 +0200 Subject: [PATCH 3/4] bugfix, works with hidden names now --- src/colors.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/colors.py b/src/colors.py index ee35dc3d..7ecc5d10 100644 --- a/src/colors.py +++ b/src/colors.py @@ -17,20 +17,16 @@ def get_color_from_team(self, team, name, playerPuuid, selfPuuid, agent=None, pa name = self.agent_dict[agent.lower()] else: name = "Player" + if playerPuuid in party_members: + name = orig_name if team == 'Red': - if playerPuuid not in party_members: - Teamcolor = color(name, fore=(238, 77, 77)) - else: - Teamcolor = color(orig_name, fore=(238, 77, 77)) + Teamcolor = color(name, fore=(238, 77, 77)) elif team == 'Blue': - if playerPuuid not in party_members: - Teamcolor = color(name, fore=(76, 151, 237)) - else: - Teamcolor = color(orig_name, fore=(76, 151, 237)) + Teamcolor = color(name, fore=(76, 151, 237)) else: Teamcolor = '' if already_seen: - Teamcolor = color(orig_name, fore=(10, 211, 8)) + Teamcolor = color(name, fore=(10, 211, 8)) if playerPuuid == selfPuuid: Teamcolor = color(orig_name, fore=(221, 224, 41)) return Teamcolor From b37e3ab0d02e4b9b6a59c7e20b7ede75bf85b9bf Mon Sep 17 00:00:00 2001 From: Jan Eickholt <98643940+JanEickholt@users.noreply.github.com> Date: Wed, 2 Aug 2023 01:37:34 +0200 Subject: [PATCH 4/4] Apply suggestions from code review changed bool(int) to a more readable expression Co-authored-by: zay <87788699+zayKenyon@users.noreply.github.com> --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 366dd9b2..692d791b 100644 --- a/main.py +++ b/main.py @@ -361,13 +361,13 @@ def program_exit(status: int): # so we don't need to import the entire sys modu player["Subject"], Requests.puuid, agent=player["CharacterID"], party_members=partyMembersList, - already_seen=bool(times)) + already_seen=True if times > 0 else False) else: Namecolor = colors.get_color_from_team(player["TeamID"], names[player["Subject"]], player["Subject"], Requests.puuid, party_members=partyMembersList, - already_seen=bool(times)) + already_seen=True if times > 0 else False) if lastTeam != player["TeamID"]: if lastTeamBoolean: table.add_empty_row()