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

View file

@ -633,7 +633,7 @@ class Diversion(object):
}] }]
""" """
self.counter +=1 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) finishMessageIds = story.getFinishesForMsg(startMsg)
finalTimeoutDuration = timeoutDuration finalTimeoutDuration = timeoutDuration
finalContainsDurations = replyContainsDurations finalContainsDurations = replyContainsDurations
@ -651,6 +651,7 @@ class Diversion(object):
if condition.type == 'replyContains': if condition.type == 'replyContains':
finalContainsDurations = json.loads(condition.originalJsonString)['vars']['delays'] finalContainsDurations = json.loads(condition.originalJsonString)['vars']['delays']
story.logger.debug(f"Finishes for {startMsg.id}: {finishMessageIds}")
i = 0 i = 0
# story.logger.warn(f"FINISHES: {finishMessageIds}") # story.logger.warn(f"FINISHES: {finishMessageIds}")
for msgId in finishMessageIds: for msgId in finishMessageIds:
@ -696,10 +697,9 @@ class Diversion(object):
story.add(condition2) story.add(condition2)
direction.isDiversionReturn = True # will clear the currentDiversion on story 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(condition)
story.add(direction) 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 variables: {self.variables}')
self.logger.info(f'has {len(self.strands)} strands: {self.strands}') self.logger.info(f'has {len(self.strands)} strands: {self.strands}')
# self.logger.info(f"Directions: {self.directionsPerMsg}")
self.calculateFinishesForStrands() self.calculateFinishesForStrands()
def reset(self): def reset(self):
@ -1670,7 +1671,15 @@ class Story(object):
self.hugvey.google.stop() self.hugvey.google.stop()
def calculateFinishesForMsg(self, msgId, depth = 0, checked = []): 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: if msgId in checked:
# self.logger.log(LOG_BS, f"Finish for {msgId} already checked")
return [] return []
checked.append(msgId) checked.append(msgId)
@ -1679,7 +1688,7 @@ class Story(object):
# is finish # is finish
return [msgId] return [msgId]
if depth == 500: if depth == 400:
self.logger.warn(f"Very deep hidden message to calculate finish for: msgId {msgId}") self.logger.warn(f"Very deep hidden message to calculate finish for: msgId {msgId}")
# return [] # return []
@ -1700,7 +1709,7 @@ class Story(object):
continue continue
self.logger.log(LOG_BS, f"Get finishes for {startMsgId}") 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}") self.logger.log(LOG_BS, f"Finishes: {self.strands}")
@ -1713,11 +1722,11 @@ class Story(object):
returns message ids 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: if msg.id in self.strands:
return self.strands[msg.id] return self.strands[msg.id]
return self.calculateFinishesForMsg(msg.id) return self.calculateFinishesForMsg(msg.id, checked=[])
def getDefaultDirectionForMsg(self, msg): def getDefaultDirectionForMsg(self, msg):
""" """