[git fast commit] 02. Feb 2019 - 15:34:59

This commit is contained in:
Yannik Schmidt
2019-02-02 15:34:59 +01:00
parent 59e5816b06
commit c7fe5e8f17
7 changed files with 60 additions and 44 deletions

View File

@@ -1,11 +1,11 @@
import TrueSkillWrapper as TS
import time
import threading
import insurgencyParsing as iparse
def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=None):
def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=iparse, cpus=1):
f = open(filename)
if start_at_end:
f.seek(0,2)
@@ -14,15 +14,15 @@ def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=None
raise NotImplementedError("Multiprocessing not implemeted yet")
else:
if callable(parsingBackend):
parsingBackend(f)
parsingBackend(f, exit_on_eof, start_at_end)
else:
parsingBackend.parse(f)
parsingBackend.parse(f, exit_on_eof, start_at_end)
except TypeError:
raise RuntimeError("parsingBackend musst be callable or have .parse() callable")
f.close()
def readfiles(filenames, parsingBackend, start_at_end=True, nofollow=False):
def readfiles(filenames, start_at_end=True, nofollow=False, parsingBackend=iparse ):
for f in filenames:
threading.Thread(target=readfile,args=\
(f, start_at_end, nofollow, parsingBackend)).start()

View File

@@ -1,4 +1,5 @@
import datetime
import TrueSkillWrapper as TS
class Player:
def __init__(self, steamid, name, rating=None):

View File

@@ -39,8 +39,8 @@ def rate_teams_simple(winner_team,loser_team,weights):
print("WARNING: Groups were {} - {} INCOMPLETE, SKIP".format(len(groups[0]),len(groups[1])))
return False
rated = env.rate(groups,weights=weights)
Storrage.sync_to_database(rated[0],True)
Storrage.sync_to_database(rated[1],False)
StorrageBackend.sync_to_database(rated[0],True)
StorrageBackend.sync_to_database(rated[1],False)
clean_rounds += 1
return True
@@ -103,7 +103,7 @@ def player_debug(sid,rated,groups):
def balance(players, buddies=None):
if not players:
return ""
Storrage.sync_from_database(players)
StorrageBackend.sync_from_database(players)
for p in players:
print(p, p.rating)
arr = sorted(players, key=lambda x: x.rating.mu, reverse=True)
@@ -116,7 +116,7 @@ def balance(players, buddies=None):
def get_player_rating(p):
try:
p = Storrage.known_players[p]
p = StorrageBackend.known_players[p]
tmp = int(env.expose(p.rating))
return "Rating of '{}' : {} ({}% won)".format(p.name,tmp,p.winratio())
except KeyError:
@@ -124,9 +124,9 @@ def get_player_rating(p):
def get_player_rating(sid, name):
try:
p = Storrage.known_players[sid]
p = StorrageBackend.known_players[sid]
tmp = int(env.expose(p.rating))
return "Rating of '{}' : {} (Rank: {})".format(name, tmp, Storrage.get_player_rank(p))
return "Rating of '{}' : {} (Rank: {})".format(name, tmp, StorrageBackend.get_player_rank(p))
except KeyError:
return "Rating of '{}' : No Rating (yet).".format(name)

View File

@@ -1,11 +1,6 @@
import Player
from datetime import datetime, timedelta
NO_TEAM = 0
OBSERVERS = 1
SECURITY = 2
INSURGENT = 3
class Event:
def __init__(self,timestamp,_map=None):
self.map = _map

View File

@@ -1,3 +1,11 @@
import insurgencyEvent as Event
from datetime import timedelta
NO_TEAM = 0
OBSERVERS = 1
SECURITY = 2
INSURGENT = 3
class EventSeries(list):
def __init__(self):
self.winner_side_cache = None
@@ -8,7 +16,7 @@ class EventSeries(list):
def _cache_teams(self):
for e in self:
if type(e) == ActivePlayersEvent:
if type(e) == Event.ActivePlayersEvent:
# TODO deal with players that are missing without a teamchange or dc event #
for p in e.players:
if p not in self._team_from_id(p.team):
@@ -23,14 +31,14 @@ class EventSeries(list):
tmp_player.active = True
## set player.active to false for disconnect or teamchange, it will be set to true at the next event that player is seen in a team ##
elif type(e) == DisconnectEvent:
elif type(e) == Event.DisconnectEvent:
if e.player in self.security_cache and get_key(self.security_cache,e.player).active:
get_key(self.security_cache,e.player).active_time += e.timestamp - get_key(self.security_cache,e.player).timestamp
get_key(self.security_cache,e.player).active = False
elif e.player in self.insurgent_cache and get_key(self.insurgent_cache,e.player).active:
get_key(self.insurgent_cache,e.player).active_time += e.timestamp - get_key(self.insurgent_cache,e.player).timestamp
get_key(self.insurgent_cache,e.player).active = False
elif type(e) == TeamchangeEvent:
elif type(e) == Event.TeamchangeEvent:
if e.player in self._team_from_id(e.old_team):
get_key(self._team_from_id(e.old_team),e.player).active_time += e.timestamp-get_key(self._team_from_id(e.old_team),e.player).timestamp
get_key(self._team_from_id(e.old_team),e.player).active = False
@@ -39,7 +47,7 @@ class EventSeries(list):
time = "NO_TIME_FOUND"
for e in self:
time = e.timestamp#.strftime("%d-%m-%Y %H:%M:%S")
if type(e) == WinnerInformationEvent:
if type(e) == Event.WinnerInformationEvent:
if self.winner_side_cache != None:
raise Warning("%s | Info: More than one Winner in series, skipping Round."%time)
self.winner_side_cache = int(e.winner)
@@ -89,6 +97,10 @@ class EventSeries(list):
def get_map(self):
if self.map_cache == None:
for e in self:
if type(e) == MapInformationEvent:
if type(e) == Event.MapInformationEvent:
self.map_cache = e.map
return self.map_cache
def get_key(dic,key):
tmp = list(dic)
return tmp[tmp.index(key)]

View File

@@ -1,5 +1,13 @@
from InsurgencyEventSeries import EventSeries
import InsurgencyEvent as Event
# insurgency specific
import insurgencyEvent as Event
import StorrageBackend as SB
import TrueSkillWrapper as TS
from insurgencyEventSeries import EventSeries
# general
import Player
import Round
from datetime import datetime
def is_round_end(line):
return "0x42,round_end_active" in line
@@ -11,10 +19,11 @@ def get_key(dic,key):
tmp = list(dic)
return tmp[tmp.index(key)]
def group_rounds(f, exit_of_eof=True):
def parse(f, exit_of_eof=True, start_at_end=False):
last_round_end = None
seek_start = True
round_lines = []
last_line_was_winner = False
while True:
old_line_nr = f.tell()
line = f.readline()
@@ -43,19 +52,19 @@ def group_rounds(f, exit_of_eof=True):
# and line and stop if it was round end #
round_lines += [line]
if last_line_was_winner and not parsingBackend.is_round_end(line):
if last_line_was_winner and not is_round_end(line):
f.seek(f.tell()-1,0)
break
elif parsing.is_round_end(line):
elif is_round_end(line):
last_round_end = line
break
elif parsing.is_winner_event(line):
elif is_winner_event(line):
last_line_was_winner = True
# parse and evaluate round #
r=parsing.parse_round(round_lines)
r=parseRoundFromLines(round_lines)
if not r:
continue
return
try:
TS.evaluate_round(r)
except Warning as e:
@@ -65,10 +74,10 @@ def group_rounds(f, exit_of_eof=True):
def parseRoundFromLines(r):
# get an event series #
es = Event.EventSeries()
es = EventSeries()
for l in r:
if is_plugin_output(l):
e = Event.parse_line_to_event(l)
e = parse_line_to_event(l)
if e != None:
es += [e]
@@ -99,8 +108,8 @@ def parseRoundFromLines(r):
winners.pop(p)
# get ratings if there are any yet #
Storrage.sync_from_database(winners)
Storrage.sync_from_database(losers)
SB.sync_from_database(winners)
SB.sync_from_database(losers)
try:
es.get_duration()
@@ -120,21 +129,21 @@ def create_event(etype,line,timestamp):
if etype in TEAMCHANGE:
player = Player.DummyPlayer(line.split(",")[1])
old_team = line.split(",")[2]
return TeamchangeEvent(player,old_team,timestamp,line)
return Event.TeamchangeEvent(player,old_team,timestamp,line)
elif etype in ACTIVE_PLAYERS:
return ActivePlayersEvent(line,timestamp)
return Event.ActivePlayersEvent(line,timestamp)
elif etype in DISCONNECT:
player = Player.DummyPlayer(line.split(",")[1])
return DisconnectEvent(player,timestamp,line)
return Event.DisconnectEvent(player,timestamp,line)
elif etype in WINNER_INFO:
winner_side = line.split(",")[1]
return WinnerInformationEvent(winner_side,timestamp,line)
return Event.WinnerInformationEvent(winner_side,timestamp,line)
elif etype in MAP_INFO:
return MapInformationEvent(line.split(",")[1],timestamp,line)
return Event.MapInformationEvent(line.split(",")[1],timestamp,line)
elif etype in IGNORE:
pass
@@ -155,5 +164,5 @@ def parse_line_to_event(l):
return None
event = create_event(etype,tmp,timestamp)
Storrage.save_event(event);
SB.save_event(event);
return event

View File

@@ -18,8 +18,7 @@ if __name__ == "__main__":
args = parser.parse_args()
FileReader.readfiles( args.files ,\
args.start_at_end,\
args.nofollow,
)
args.nofollow )
if not args.parse_only:
Query.listen()
else: