exclude replays from metrics

This commit is contained in:
Giulio 2022-04-05 15:18:12 +02:00
parent 89917a7824
commit 38d0244793
3 changed files with 16 additions and 9 deletions

View File

@ -277,7 +277,8 @@ class Game:
self.choose_characters() self.choose_characters()
if 'gold_rush' in self.expansions: if 'gold_rush' in self.expansions:
self.notify_gold_rush_shop() self.notify_gold_rush_shop()
Metrics.send_metric('start_game', points=[1], tags=([f"exp:{e}" for e in self.expansions] + [f"players:{self.initial_players}", f"competitive:{self.is_competitive}"])) if not self.is_replay:
Metrics.send_metric('start_game', points=[1], tags=([f"exp:{e}" for e in self.expansions] + [f"players:{self.initial_players}", f"competitive:{self.is_competitive}"]))
def distribute_roles(self): def distribute_roles(self):
available_roles: List[roles.Role] = [] available_roles: List[roles.Role] = []
@ -470,7 +471,8 @@ class Game:
if not self.someone_won: if not self.someone_won:
self.someone_won = True self.someone_won = True
self.sio.emit('chat_message', room=self.name, data=f'_won|{p.name}|{p.role.name}') self.sio.emit('chat_message', room=self.name, data=f'_won|{p.name}|{p.role.name}')
Metrics.send_metric('player_win', points=[1], tags=[f"char:{p.character.name}", f"role:{p.role.name}"]) if not self.is_replay:
Metrics.send_metric('player_win', points=[1], tags=[f"char:{p.character.name}", f"role:{p.role.name}"])
p.notify_self() p.notify_self()
if hasattr(self.sio, 'is_fake'): if hasattr(self.sio, 'is_fake'):
print('announces_winners(): Running for tests, you will have to call reset manually!') print('announces_winners(): Running for tests, you will have to call reset manually!')
@ -486,7 +488,8 @@ class Game:
def play_turn(self): def play_turn(self):
self.incremental_turn += 1 self.incremental_turn += 1
Metrics.send_metric('incremental_turn', points=[self.incremental_turn], tags=[f'game:{self.SEED}']) if not self.is_replay:
Metrics.send_metric('incremental_turn', points=[self.incremental_turn], tags=[f'game:{self.SEED}'])
if self.players[self.turn].is_dead: if self.players[self.turn].is_dead:
pl = sorted(self.get_dead_players(), key=lambda x:x.death_turn)[0] pl = sorted(self.get_dead_players(), key=lambda x:x.death_turn)[0]
if self.check_event(ce.DeadMan) and not self.did_resuscitate_deadman and pl == self.players[self.turn]: if self.check_event(ce.DeadMan) and not self.did_resuscitate_deadman and pl == self.players[self.turn]:
@ -630,7 +633,8 @@ class Game:
import bang.expansions.dodge_city.characters as chd import bang.expansions.dodge_city.characters as chd
print(f'{self.name}: the killer is {player.attacker}') print(f'{self.name}: the killer is {player.attacker}')
if player.character and player.role: if player.character and player.role:
Metrics.send_metric('player_death', points=[1], tags=[f"char:{player.character.name}", f"role:{player.role.name}"]) if not self.is_replay:
Metrics.send_metric('player_death', points=[1], tags=[f"char:{player.character.name}", f"role:{player.role.name}"])
if len([c for c in player.gold_rush_equipment if isinstance(c, grc.Ricercato)]) > 0 and player.attacker and player.attacker in self.players: if len([c for c in player.gold_rush_equipment if isinstance(c, grc.Ricercato)]) > 0 and player.attacker and player.attacker in self.players:
player.attacker.gold_nuggets += 1 player.attacker.gold_nuggets += 1
player.attacker.hand.append(self.deck.draw(True)) player.attacker.hand.append(self.deck.draw(True))

View File

@ -650,7 +650,8 @@ class Player:
self.hand.insert(hand_index, card) self.hand.insert(hand_index, card)
else: else:
did_play_card = True did_play_card = True
Metrics.send_metric('play_card', points=[1], tags=[f'success:{did_play_card}', f'card:{card.name}', f'bot:{self.is_bot}', f'exp:{card.expansion if "expansion" in card.__dict__ else "vanilla"}']) if not self.game.is_replay:
Metrics.send_metric('play_card', points=[1], tags=[f'success:{did_play_card}', f'card:{card.name}', f'bot:{self.is_bot}', f'exp:{card.expansion if "expansion" in card.__dict__ else "vanilla"}'])
print("did play card:", did_play_card) print("did play card:", did_play_card)
self.notify_self() self.notify_self()
if self.is_bot: if self.is_bot:

View File

@ -48,7 +48,7 @@ blacklist: List[str] = []
def advertise_lobbies(): def advertise_lobbies():
sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden]) sio.emit('lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if not g.started and len(g.players) < 10 and not g.is_hidden])
sio.emit('spectate_lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if g.started]) sio.emit('spectate_lobbies', room='lobby', data=[{'name': g.name, 'players': len(g.players), 'locked': g.password != ''} for g in games if g.started])
Metrics.send_metric('lobbies', points=[len(games)]) Metrics.send_metric('lobbies', points=[len([g for g in games if not g.is_replay])])
Metrics.send_metric('online_players', points=[online_players]) Metrics.send_metric('online_players', points=[online_players])
@sio.event @sio.event
@ -278,7 +278,8 @@ def start_game(sid):
def set_character(sid, name): def set_character(sid, name):
ses: Player = sio.get_session(sid) ses: Player = sio.get_session(sid)
ses.game.rpc_log.append(f'{ses.name};set_character;{name}') ses.game.rpc_log.append(f'{ses.name};set_character;{name}')
Metrics.send_metric('set_character', points=[1], tags=[f"char:{name}"]) if not ses.game.is_replay:
Metrics.send_metric('set_character', points=[1], tags=[f"char:{name}"])
ses.set_character(name) ses.set_character(name)
@sio.event @sio.event
@ -551,7 +552,8 @@ def chat_message(sid, msg, pl=None):
else: else:
color = sid.encode('utf-8').hex()[-3:] color = sid.encode('utf-8').hex()[-3:]
sio.emit('chat_message', room=ses.game.name, data={'color': f'#{color}','text':f'[{ses.name}]: {msg}'}) sio.emit('chat_message', room=ses.game.name, data={'color': f'#{color}','text':f'[{ses.name}]: {msg}'})
Metrics.send_metric('chat_message', points=[1], tags=[f'game:{ses.game.name.replace(" ","_")}']) if not ses.game.is_replay:
Metrics.send_metric('chat_message', points=[1], tags=[f'game:{ses.game.name.replace(" ","_")}'])
@ -606,7 +608,7 @@ def get_goldrushcards(sid):
def pool_metrics(): def pool_metrics():
sio.sleep(60) sio.sleep(60)
Metrics.send_metric('lobbies', points=[len(games)]) Metrics.send_metric('lobbies', points=[len([g for g in games if not g.is_replay])])
Metrics.send_metric('online_players', points=[online_players]) Metrics.send_metric('online_players', points=[online_players])
pool_metrics() pool_metrics()