Commit 6d27242f authored by kaiyou's avatar kaiyou

Make the recurrence hook more generic

parent ab37c9e1
......@@ -18,20 +18,25 @@ def populate(context, args, key, table):
return (context, args)
def postcheck(context, result):
""" Basic post-check hooks
def recurrence(context, result, fields=["up"], dest="stable", dest_prev=None):
""" Compute the recurrence of a the value of given fields
"""
return merge_result(*recurrence(context, result))
def recurrence(context, result, field="recurrence", reference=["up"]):
""" Compute the recurrence of a check state in a field
"""
recurring = all(
context.get(key, None) is result.get(key, None)
for key in reference
recur = {}
prev = {}
if dest in context:
fields = fields + list(context[dest])
if type(context[dest]) is dict:
recur.update(context[dest])
for field in fields:
recur[field] = (
recur.get(field, 0) + 1
if context.get(field, None) == result.get(field, -1)
else 0
)
context[field] = (context.get(field, 0) + 1) if recurring else 0
prev[field] = context.get(field, None)
context[dest] = recur
if prev is not None:
context[dest_prev] = prev
return context, result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment