Check for missing conditions like in moscow

This commit is contained in:
Ruben van de Ven 2020-02-23 21:11:34 +03:00
parent 3832652dc9
commit dbafd3d80d
2 changed files with 74 additions and 7 deletions

View file

@ -121,7 +121,14 @@ class Toolbox:
logger.info("{} files missing".format(len(missingFiles)))
@classmethod
def find_direction_for_condition(cls, conditionId, story):
for i, item in enumerate(story):
if item['@type'] == 'Direction':
for dConditionId in item['conditions']:
if dConditionId == conditionId:
return item
def fix_story_file(self, lang_code):
if lang_code not in self.languages.keys():
logger.critical("Invalid langauge code")
@ -136,10 +143,11 @@ class Toolbox:
if len(beginnings) < 1:
logger.critical("No beginning set")
if len(beginnings) > 1:
logger.warn(f"{len(beginnings)} beginning messages configured. Set only one")
beginningIds = [i['@id'] for i in beginnings]
logger.warn(f"{len(beginnings)} beginning messages configured. Set only one of {beginningIds}")
itemsPerId = {item['@id']: item for item in story}
orphans = 0
for i, item in enumerate(story):
if item['@type'] == 'Direction':
if type(item['source']) == dict:
@ -152,11 +160,21 @@ class Toolbox:
logger.info(f"Direction pointed to {item['source']}")
logger.info(f"Will now point to {validMsg}")
item['source'] = item['source']['@id']
for conditionId in item['conditions']:
if conditionId not in itemsPerId:
logger.critical(f"Direction {item['@id']} refers to non-existing condition {conditionId}! (This will result in a crash when playing the message)")
if item['@type'] == 'Condition':
direction = self.find_direction_for_condition(item['@id'], story)
if not direction:
orphans +=1
# This should be fine, but I don't dare to do it yet...
# logger.info("Clear residu condition {item['@id']} ... this is not properly done by the editor.")
# del story[i]
continue
if item['type'] == 'messagePlayed':
msgId = item['vars']['msgId'].strip()
if msgId not in itemsPerId:
logger.critical(f"Message played condition for non-existing message {msgId}!")
logger.warning(f"Message played condition for non-existing message {msgId} when going from {direction['source']} to {direction['target']}! (this will ignore the condition)")
if item['type'] == 'replyContains':
if 'regex' in item['vars'] and len(item['vars']['regex'].rstrip()):
try:
@ -165,6 +183,8 @@ class Toolbox:
logger.critical(f"Invalid regex for condition {item['@id']}: {item['vars']['regex'].rstrip()}")
logger.exception(e)
logger.debug( f"Can clear {orphans} orphaned conditions (uncomment code in tools.py)")
with open(filename, 'w') as fp:
json.dump(story, fp, indent=2)
logger.info(f"Wrote to {filename}")
@ -274,4 +294,36 @@ class Toolbox:
json.dump(story, fp, indent=2)
logger.info(f"Wrote to {filename}")
def parse_cutelog(self, filename):
with open(filename,'r') as fp:
cutelog = json.load(fp);
hugvey_ids = list(range(1,30))
hugveys_stats = {}
for id in hugvey_ids:
print(f"HUGVEY {id}")
log = [i for i in cutelog if 'name' in i and i['name'].startswith(f'hugvey.{id}.')]
txts = [i for i in log if 'msg' in i and ((i['msg'].startswith('Text: ') and i['msg'] != "Text: ") or i['msg'].startswith('Current message') or i['msg'].startswith('ignore'))]
last = None
for txt in txts:
if last:
if txt['msg'].startswith('Current'):
print('--------------------', txt['created'])
elif txt['msg'].startswith('ignore'):
print('/////////////////////', txt['created'])
else:
print(txt['created'] - last['created'], txt['msg'], txt['levelname']
)
last = txt
else:
last = txt
tC = [i for i in log if 'msg' in i and (i['msg'].startswith("Condition is met"))]
tR = [i for i in log if 'msg' in i and (i['msg'].startswith("Received {'file"))]
tP = [i for i in log if 'msg' in i and (i['msg'].startswith("['play'"))]
for i, txt in enumerate(tP):
print(txt['created']-tC[i]['created'], txt['msg'], tC[i]['msg'], tR[i]['msg'])
print('===================')

View file

@ -40,11 +40,24 @@ if __name__ == '__main__':
metavar=("LANG_CODE", "CVS_FILE"),
nargs=2
)
argParser.add_argument(
'--parse-cutelog',
default=None,
help="Parse the speech of a cutelog logfile",
metavar="CUTELOG STORED FILE",
)
argParser.add_argument(
'--verbose',
'-v',
action='count', default=0
)
args = argParser.parse_args()
loglevel = logging.NOTSET if args.verbose > 1 else logging.DEBUG if args.verbose > 0 else logging.INFO
coloredlogs.install(
level=logging.DEBUG
level=loglevel
)
logger = logging.getLogger("toolbox")
@ -60,4 +73,6 @@ if __name__ == '__main__':
if args.csv:
tools.generate_story_csv(args.csv)
if args.import_csv:
tools.import_story_csv(*args.import_csv)
tools.import_story_csv(*args.import_csv)
if args.parse_cutelog:
tools.parse_cutelog(args.parse_cutelog)