Fix bug with finish calculation for diversion

This commit is contained in:
Ruben van de Ven 2019-06-11 15:10:46 +02:00
parent 87c7db2489
commit eb7449c4e8
1 changed files with 16 additions and 7 deletions

View File

@ -633,7 +633,7 @@ class Diversion(object):
}]
"""
self.counter +=1
# story.logger.warn(f"CREATING DIRECTIONS FOR {startMsg.id}")
story.logger.info(f"Creating return directions for {startMsg.id}")
finishMessageIds = story.getFinishesForMsg(startMsg)
finalTimeoutDuration = timeoutDuration
finalContainsDurations = replyContainsDurations
@ -651,6 +651,7 @@ class Diversion(object):
if condition.type == 'replyContains':
finalContainsDurations = json.loads(condition.originalJsonString)['vars']['delays']
story.logger.debug(f"Finishes for {startMsg.id}: {finishMessageIds}")
i = 0
# story.logger.warn(f"FINISHES: {finishMessageIds}")
for msgId in finishMessageIds:
@ -696,10 +697,9 @@ class Diversion(object):
story.add(condition2)
direction.isDiversionReturn = True # will clear the currentDiversion on story
story.logger.info(f"Created direction: {direction.id} {condition.id} with timeout {finalTimeoutDuration}s")
story.logger.info(f"Created direction: {direction.id} ({msg.id} -> {returnMsg.id}) {condition.id} with timeout {finalTimeoutDuration}s")
story.add(condition)
story.add(direction)
# story.logger.warn(f"ADDED DIRECTION {direction.id}")
@ -1206,6 +1206,7 @@ class Story(object):
self.logger.info(f'has variables: {self.variables}')
self.logger.info(f'has {len(self.strands)} strands: {self.strands}')
# self.logger.info(f"Directions: {self.directionsPerMsg}")
self.calculateFinishesForStrands()
def reset(self):
@ -1670,7 +1671,15 @@ class Story(object):
self.hugvey.google.stop()
def calculateFinishesForMsg(self, msgId, depth = 0, checked = []):
"""
BEWARE: checked = [] is evaluated at creation time of the method. Meaning that each call to this method
which doesn't explicitly specify the checked list, relies upon the list created at parse time. This means
subsequent call to the method make the list larger!! So the default should actually never be used. (found
out the hard way ;-) )
"""
# print(checked)
if msgId in checked:
# self.logger.log(LOG_BS, f"Finish for {msgId} already checked")
return []
checked.append(msgId)
@ -1679,7 +1688,7 @@ class Story(object):
# is finish
return [msgId]
if depth == 500:
if depth == 400:
self.logger.warn(f"Very deep hidden message to calculate finish for: msgId {msgId}")
# return []
@ -1700,7 +1709,7 @@ class Story(object):
continue
self.logger.log(LOG_BS, f"Get finishes for {startMsgId}")
self.strands[startMsgId] = self.calculateFinishesForMsg(startMsgId)
self.strands[startMsgId] = self.calculateFinishesForMsg(startMsgId, checked=[])
self.logger.log(LOG_BS, f"Finishes: {self.strands}")
@ -1713,11 +1722,11 @@ class Story(object):
returns message ids
"""
print(msg.id, self.strands)
self.logger.debug(f"Get finishes for {msg.id} from {self.strands}")
if msg.id in self.strands:
return self.strands[msg.id]
return self.calculateFinishesForMsg(msg.id)
return self.calculateFinishesForMsg(msg.id, checked=[])
def getDefaultDirectionForMsg(self, msg):
"""