From 310c2aa28d5e3aea314d1594113f431f2339e6fc Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 16 Jan 2016 23:41:46 -0600 Subject: [PATCH] markov: fake a __stop if a k1,k2 has no v this shouldn't have happened, but i'm guessing some previous crash put some buggy data into my database, so let's just be careful and do this. a k1,k2 could have had any value for v, but not knowing what else to do in this corner case, we'll just use a stop and let the caller decide if they want to keep going --- dr_botzo/markov/lib.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dr_botzo/markov/lib.py b/dr_botzo/markov/lib.py index c0e5c80..a03bab6 100644 --- a/dr_botzo/markov/lib.py +++ b/dr_botzo/markov/lib.py @@ -114,6 +114,10 @@ def get_or_create_target_context(target_name): def get_word_out_of_states(states, backwards=False): """Pick one random word out of the given states.""" + # work around possible broken data, where a k1,k2 should have a value but doesn't + if len(states) == 0: + states = MarkovState.objects.filter(v=MarkovState._stop) + new_word = '' running = 0 count_sum = states.aggregate(Sum('count'))['count__sum']