[git fast commit] 02. Feb 2019 - 21:23:47

This commit is contained in:
Yannik Schmidt
2019-02-02 21:23:47 +01:00
parent ff99de216c
commit 5bbbc31f7b
3 changed files with 27 additions and 17 deletions

View File

@@ -3,7 +3,7 @@ import time
import threading
import insurgencyParsing as iparse
def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=iparse, cpus=1):
def readfile(filename, start_at_end, exit_on_eof, parsingBackend, cpus=1):
f = open(filename)
if start_at_end:
@@ -22,7 +22,10 @@ def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=ipar
f.close()
def readfiles(filenames, start_at_end=True, nofollow=False, parsingBackend=iparse ):
def readfiles(filenames, start_at_end=False, nofollow=False,parsingBackend=iparse, oneThread=False):
for f in filenames:
threading.Thread(target=readfile,args=\
(f, start_at_end, nofollow, parsingBackend)).start()
if oneThread:
readfile(f, start_at_end, nofollow, parsingBackend)
else:
threading.Thread(target=readfile,args=\
(f, start_at_end, nofollow, parsingBackend,)).start()

View File

@@ -8,6 +8,7 @@ from insurgencyEventSeries import EventSeries
import Player
import Round
from datetime import datetime
import time
def is_round_end(line):
return "0x42,round_end_active" in line
@@ -19,7 +20,7 @@ def get_key(dic,key):
tmp = list(dic)
return tmp[tmp.index(key)]
def parse(f, exit_of_eof=True, start_at_end=False):
def parse(f, exit_on_eof=True, start_at_end=False):
last_round_end = None
seek_start = True
round_lines = []
@@ -29,7 +30,7 @@ def parse(f, exit_of_eof=True, start_at_end=False):
line = f.readline()
# if no line or incomplete line, sleep and try again #
if not line:
if not line or not line.strip("\n"):
if exit_on_eof:
return
time.sleep(5000)
@@ -50,12 +51,9 @@ def parse(f, exit_of_eof=True, start_at_end=False):
continue
evalRound = False
# and line and stop if it was round end #
# ad line and stop if it was round end #
round_lines += [line]
if last_line_was_winner and not is_round_end(line):
f.seek(f.tell()-1,0)
evalRound = True
elif is_round_end(line):
if is_round_end(line):
last_round_end = line
evalRound = True
elif is_winner_event(line):
@@ -65,6 +63,7 @@ def parse(f, exit_of_eof=True, start_at_end=False):
if evalRound:
nextRound = parseRoundFromLines(round_lines)
round_lines = []
evalRound = False
if nextRound:
try:
TS.evaluate_round(nextRound)
@@ -157,13 +156,16 @@ def parse_line_to_event(l):
etype = tmp.split(",")[0].split("|")[0]
try:
if ": L " in l.split("0x42")[0]:
timestamp = datetime.strptime(l.split(": L ")[1].split(": [")[0],"%m/%d/%Y - %H:%M:%S")
timestamp = datetime.strptime(l.split(": L ")[1].split(": [")[0],"%m/%d/%Y - %H:%M:%S")
else:
timestamp = datetime.strptime(l.split(": [ints_logging.smx]")[0],"L %m/%d/%Y - %H:%M:%S")
timestamp = datetime.strptime(l.split(": [ints_logging.smx]")[0],"L %m/%d/%Y - %H:%M:%S")
event = create_event(etype,tmp,timestamp)
except ValueError:
print(" ---- NO TIME ---- | WARNING: Failed to parse time for event, SKIP")
return None
except Exception as e:
print("Failed to parse Event in line, skipping: {}".format(str(e)))
return None
event = create_event(etype,tmp,timestamp)
SB.save_event(event);
return event

View File

@@ -3,6 +3,7 @@ import sys
import NetworkParser
import FileReader
import argparse
import StorrageBackend
parser = argparse.ArgumentParser(description='Insurgency rating python backend server')
parser.add_argument('files', metavar='FILE', type=str, nargs='+',\
@@ -15,14 +16,18 @@ parser.add_argument('--start-at-end','-se',dest='start_at_end', action='store_co
parser.add_argument('--no-follow','-nf',dest='nofollow', action='store_const',\
const=True, default=False, \
help="wait for changes on the files (does not imply start-at-end)")
parser.add_argument('--one-thread', dest='one-thread', action='store_const',\
parser.add_argument('--one-thread', dest='oneThread', action='store_const',\
const=True, default=False, \
help="run everything in main thread (implies no-follow)")
if __name__ == "__main__":
args = parser.parse_args()
FileReader.readfiles( args.files ,\
args.start_at_end,\
args.nofollow )
start_at_end=args.start_at_end,\
nofollow=args.nofollow,
oneThread=args.oneThread)
if args.oneThread:
for l in StorrageBackend.dumpRatings().split("\n"):
print(l)
if not args.parse_only:
Query.listen()
else: