-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon_scores.py
38 lines (35 loc) · 1.38 KB
/
weapon_scores.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# tail -n +0 -f steamcmd_linux/csgo/csgo/weapon_scores.log | python3 weapon_scores.py
# TODO: Reimplement fast tail in Python and just take the file name as arg
import collections
import itertools
import os
import re
import shutil
scores = collections.Counter()
total_score = 0
def show_scores():
sz = shutil.get_terminal_size()
n = sz.lines - 2
sc = scores.most_common()
winners = [s for s in sc[:n] if s[1] > 0]
losers = [s for s in sc[-n:] if s[1] < 0]
width = sz.columns // 2
print("%-*s %s" % (width, "Top %d winners" % n, "Worst %d losers" % n))
for idx, (winner, winsc), (loser, losesc) in itertools.zip_longest(range(n), winners, losers, fillvalue=("", "")):
if winner: winner = "[%2.2f%%] %s" % (winsc / total_score * 100, winner)
if loser: loser = "[%2.2f%%] %s" % (-losesc / total_score * 100, loser)
print("%-*s %s" % (width, winner, loser))
while "moar data":
show_scores()
line = input()
# Zero-sum game: every point gained in one place is lost somewhere else
m = re.match("^(.+) (|team|self)damaged (.+) for ([0-9]+) \(([0-9]+)hp\)$", line)
if not m: continue
killer, mode, victim, score, hp = m.groups()
# TODO: Score team damage and self damage differently from normal damage-to-enemies
# For now, just ignore both.
if mode != "": continue
score = int(score)
total_score += score
scores[killer] += score
scores[victim] -= score