mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-09 07:58:32 +01:00
[git fast commit] 29. Jan 2019 - 20:22:02
This commit is contained in:
@@ -3,69 +3,26 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
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=None):
|
||||||
last_round_end = None
|
|
||||||
f = open(filename)
|
f = open(filename)
|
||||||
count = 0
|
|
||||||
|
|
||||||
if start_at_end:
|
if start_at_end:
|
||||||
f.seek(0,2)
|
f.seek(0,2)
|
||||||
|
|
||||||
# outer loop, continue reading rounds #
|
try:
|
||||||
while True:
|
if cpus > 1:
|
||||||
# reset #
|
raise NotImplementedError("Multiprocessing not implemeted yet")
|
||||||
round_lines = []
|
else:
|
||||||
last_line_was_winner = False
|
if callable(parsingBackend):
|
||||||
|
parsingBackend(f)
|
||||||
## try to read in a full round ##
|
else:
|
||||||
seek_start = True
|
parsingBackend.parse(f)
|
||||||
while True:
|
except TypeError:
|
||||||
old_line_nr = f.tell()
|
raise RuntimeError("parsingBackend musst be callable or have .parse() callable")
|
||||||
line = f.readline()
|
|
||||||
|
|
||||||
# if no line or incomplete line, sleep and try again #
|
|
||||||
if not line:
|
|
||||||
if exit_on_eof:
|
|
||||||
return
|
|
||||||
time.sleep(5000)
|
|
||||||
continue
|
|
||||||
elif not line.endswith("\n"):
|
|
||||||
f.seek(old_line_nr)
|
|
||||||
time.sleep(5000)
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
if seek_start and not "round_start_active" in line and line:
|
|
||||||
continue
|
|
||||||
elif "round_start_active" in line:
|
|
||||||
seek_start = False
|
|
||||||
elif "plugin unloaded" in line:
|
|
||||||
round_lines = []
|
|
||||||
seek_start = True
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
# and line and stop if it was round end #
|
|
||||||
round_lines += [line]
|
|
||||||
if last_line_was_winner and not parsing.is_round_end(line):
|
|
||||||
f.seek(f.tell()-1,0)
|
|
||||||
break
|
|
||||||
elif parsing.is_round_end(line):
|
|
||||||
last_round_end = line
|
|
||||||
break
|
|
||||||
elif parsing.is_winner_event(line):
|
|
||||||
last_line_was_winner = True
|
|
||||||
|
|
||||||
# parse and evaluate round #
|
|
||||||
r=parsing.parse_round(round_lines)
|
|
||||||
if not r:
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
TS.evaluate_round(r)
|
|
||||||
except Warning as e:
|
|
||||||
pass
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def readfiles(filenames,start_at_end=True,nofollow=False):
|
def readfiles(filenames, parsingBackend, start_at_end=True, nofollow=False):
|
||||||
for f in filenames:
|
for f in filenames:
|
||||||
threading.Thread(target=readfile,args=(f,start_at_end,nofollow,)).start()
|
threading.Thread(target=readfile,args=\
|
||||||
|
(f, start_at_end, nofollow, parsingBackend)).start()
|
||||||
|
|||||||
@@ -8,8 +8,59 @@ def is_plugin_output(line):
|
|||||||
def is_winner_event(line):
|
def is_winner_event(line):
|
||||||
return "0x42,winner" in line
|
return "0x42,winner" in line
|
||||||
def get_key(dic,key):
|
def get_key(dic,key):
|
||||||
tmp = list(dic)
|
tmp = list(dic)
|
||||||
return tmp[tmp.index(key)]
|
return tmp[tmp.index(key)]
|
||||||
|
|
||||||
|
|
||||||
|
def group_rounds(f, exit_of_eof=True):
|
||||||
|
last_round_end = None
|
||||||
|
seek_start = True
|
||||||
|
while True:
|
||||||
|
old_line_nr = f.tell()
|
||||||
|
line = f.readline()
|
||||||
|
|
||||||
|
# if no line or incomplete line, sleep and try again #
|
||||||
|
if not line:
|
||||||
|
if exit_on_eof:
|
||||||
|
return
|
||||||
|
time.sleep(5000)
|
||||||
|
continue
|
||||||
|
elif not line.endswith("\n"):
|
||||||
|
f.seek(old_line_nr)
|
||||||
|
time.sleep(5000)
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
if seek_start and not "round_start_active" in line and line:
|
||||||
|
continue
|
||||||
|
elif "round_start_active" in line:
|
||||||
|
seek_start = False
|
||||||
|
elif "plugin unloaded" in line:
|
||||||
|
round_lines = []
|
||||||
|
seek_start = True
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
# and line and stop if it was round end #
|
||||||
|
round_lines += [line]
|
||||||
|
if last_line_was_winner and not parsingBackend.is_round_end(line):
|
||||||
|
f.seek(f.tell()-1,0)
|
||||||
|
break
|
||||||
|
elif parsing.is_round_end(line):
|
||||||
|
last_round_end = line
|
||||||
|
break
|
||||||
|
elif parsing.is_winner_event(line):
|
||||||
|
last_line_was_winner = True
|
||||||
|
|
||||||
|
# parse and evaluate round #
|
||||||
|
r=parsing.parse_round(round_lines)
|
||||||
|
if not r:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
TS.evaluate_round(r)
|
||||||
|
except Warning as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def parseRoundFromLines(r):
|
def parseRoundFromLines(r):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user