mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-08 23:48:33 +01:00
[git fast commit] 02. Feb 2019 - 21:23:47
This commit is contained in:
@@ -3,7 +3,7 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
import insurgencyParsing as iparse
|
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)
|
f = open(filename)
|
||||||
if start_at_end:
|
if start_at_end:
|
||||||
@@ -22,7 +22,10 @@ def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=ipar
|
|||||||
|
|
||||||
f.close()
|
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:
|
for f in filenames:
|
||||||
threading.Thread(target=readfile,args=\
|
if oneThread:
|
||||||
(f, start_at_end, nofollow, parsingBackend)).start()
|
readfile(f, start_at_end, nofollow, parsingBackend)
|
||||||
|
else:
|
||||||
|
threading.Thread(target=readfile,args=\
|
||||||
|
(f, start_at_end, nofollow, parsingBackend,)).start()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from insurgencyEventSeries import EventSeries
|
|||||||
import Player
|
import Player
|
||||||
import Round
|
import Round
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
def is_round_end(line):
|
def is_round_end(line):
|
||||||
return "0x42,round_end_active" in line
|
return "0x42,round_end_active" in line
|
||||||
@@ -19,7 +20,7 @@ def get_key(dic,key):
|
|||||||
tmp = list(dic)
|
tmp = list(dic)
|
||||||
return tmp[tmp.index(key)]
|
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
|
last_round_end = None
|
||||||
seek_start = True
|
seek_start = True
|
||||||
round_lines = []
|
round_lines = []
|
||||||
@@ -29,7 +30,7 @@ def parse(f, exit_of_eof=True, start_at_end=False):
|
|||||||
line = f.readline()
|
line = f.readline()
|
||||||
|
|
||||||
# if no line or incomplete line, sleep and try again #
|
# 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:
|
if exit_on_eof:
|
||||||
return
|
return
|
||||||
time.sleep(5000)
|
time.sleep(5000)
|
||||||
@@ -50,12 +51,9 @@ def parse(f, exit_of_eof=True, start_at_end=False):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
evalRound = False
|
evalRound = False
|
||||||
# and line and stop if it was round end #
|
# ad line and stop if it was round end #
|
||||||
round_lines += [line]
|
round_lines += [line]
|
||||||
if last_line_was_winner and not is_round_end(line):
|
if is_round_end(line):
|
||||||
f.seek(f.tell()-1,0)
|
|
||||||
evalRound = True
|
|
||||||
elif is_round_end(line):
|
|
||||||
last_round_end = line
|
last_round_end = line
|
||||||
evalRound = True
|
evalRound = True
|
||||||
elif is_winner_event(line):
|
elif is_winner_event(line):
|
||||||
@@ -65,6 +63,7 @@ def parse(f, exit_of_eof=True, start_at_end=False):
|
|||||||
if evalRound:
|
if evalRound:
|
||||||
nextRound = parseRoundFromLines(round_lines)
|
nextRound = parseRoundFromLines(round_lines)
|
||||||
round_lines = []
|
round_lines = []
|
||||||
|
evalRound = False
|
||||||
if nextRound:
|
if nextRound:
|
||||||
try:
|
try:
|
||||||
TS.evaluate_round(nextRound)
|
TS.evaluate_round(nextRound)
|
||||||
@@ -157,13 +156,16 @@ def parse_line_to_event(l):
|
|||||||
etype = tmp.split(",")[0].split("|")[0]
|
etype = tmp.split(",")[0].split("|")[0]
|
||||||
try:
|
try:
|
||||||
if ": L " in l.split("0x42")[0]:
|
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:
|
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:
|
except ValueError:
|
||||||
print(" ---- NO TIME ---- | WARNING: Failed to parse time for event, SKIP")
|
print(" ---- NO TIME ---- | WARNING: Failed to parse time for event, SKIP")
|
||||||
return None
|
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);
|
SB.save_event(event);
|
||||||
return event
|
return event
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import sys
|
|||||||
import NetworkParser
|
import NetworkParser
|
||||||
import FileReader
|
import FileReader
|
||||||
import argparse
|
import argparse
|
||||||
|
import StorrageBackend
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Insurgency rating python backend server')
|
parser = argparse.ArgumentParser(description='Insurgency rating python backend server')
|
||||||
parser.add_argument('files', metavar='FILE', type=str, nargs='+',\
|
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',\
|
parser.add_argument('--no-follow','-nf',dest='nofollow', action='store_const',\
|
||||||
const=True, default=False, \
|
const=True, default=False, \
|
||||||
help="wait for changes on the files (does not imply start-at-end)")
|
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, \
|
const=True, default=False, \
|
||||||
help="run everything in main thread (implies no-follow)")
|
help="run everything in main thread (implies no-follow)")
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
FileReader.readfiles( args.files ,\
|
FileReader.readfiles( args.files ,\
|
||||||
args.start_at_end,\
|
start_at_end=args.start_at_end,\
|
||||||
args.nofollow )
|
nofollow=args.nofollow,
|
||||||
|
oneThread=args.oneThread)
|
||||||
|
if args.oneThread:
|
||||||
|
for l in StorrageBackend.dumpRatings().split("\n"):
|
||||||
|
print(l)
|
||||||
if not args.parse_only:
|
if not args.parse_only:
|
||||||
Query.listen()
|
Query.listen()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user