Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
fix: Added reverse to intent compare and some more explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeff07 committed Dec 16, 2021
1 parent 1df418e commit fe26b3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion examples/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,15 @@
"""
print()

compare = ipf.intent.compare_snapshot('$lastLocked')
compare = ipf.intent.compare_snapshot('$lastLocked', reverse=False)
print(tabulate(compare, headers="keys"))
"""
Current: The snapshot loaded into the intent class:
ipf.intent.load_intent('$last')
Other: The snapshot in the comparison:
ipf.intent.compare_snapshot('$prev', reverse=True)
Reverse (Default: False): Will flip current and other. Use when class is newest date and compare is an older date.
name id check current other diff
-------------------------------------------- ---------- ------- --------- ------- ------
CDP/LLDP unidirectional 320633253 total 21 25 4
Expand Down
4 changes: 2 additions & 2 deletions ipfabric/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def get_results(self, intent: IntentCheck, color: Union[str, int], snapshot_id:
return self.client.fetch_all(intent.api_endpoint, snapshot_id=snapshot_id, reports=intent.web_endpoint,
filters={intent.column: ['color', 'eq', color]})

def compare_snapshot(self, snapshot_id: str = None):
def compare_snapshot(self, snapshot_id: str = None, reverse: bool = False):
new_intents = {i.name: i for i in self.get_intent_checks(snapshot_id)}
comparison = list()
for name, intent in new_intents.items():
old = self.intent_by_name[name].result
compare = old.compare(intent.result)
compare = intent.result.compare(old) if reverse else old.compare(intent.result)
for desc, value in compare.items():
n = desc if desc != 'count' else 'total'
comparison.append({"name": name, "id": intent.intent_id, "check": n, **value})
Expand Down

0 comments on commit fe26b3f

Please sign in to comment.