Created
December 28, 2018 01:09
-
-
Save pocc/fe18e414c29dc0f6517077e96e6ac123 to your computer and use it in GitHub Desktop.
Recursive way to create troubleshooting trees, with examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding:utf-8 -*- | |
| """This program aims to provide tools to troubleshoot better | |
| NOTE: Default option is yes to continue troubleshooting. No is for steps if | |
| user has not done due diligence. | |
| Assuming that categories only need to be chosen at the beginning and from | |
| then on we can employ binary questions | |
| """ | |
| class NextStep: | |
| """ This class aims to provide tools to troubleshoot better. | |
| Object next_step | |
| statement (string): Is noun $x adjective $y? If no next steps, | |
| then this will be a sentence. | |
| result (bool): Yes/no answer to the question. | |
| yes_step (next_step): Call to another next_step object | |
| no_step (next_step): Call to another next_step object | |
| categories (list(next_step)): List of categories to choose from | |
| """ | |
| def __init__(self, statement, yes_step=None, no_step=None, | |
| categories=None, name=None): | |
| self.statement = statement | |
| self.no_step = no_step | |
| self.yes_step = yes_step | |
| self.categories = categories | |
| self.name = name | |
| def start(self): | |
| """Start with root troubleshooting step.""" | |
| print(40 * '-') | |
| if self.yes_step and self.no_step: | |
| self.yesno_question() | |
| elif self.categories: | |
| self.choose_category() | |
| else: # Reached the last troubleshooting step | |
| print(">>>", self.statement) | |
| def yesno_question(self): | |
| """Get the user's input and show resulting next troubleshooting step""" | |
| # Anything other than y is no | |
| result = input(self.statement + " (y/n)? ") | |
| if result == 'y': | |
| self.yes_step.start() | |
| else: | |
| self.no_step.start() | |
| def choose_category(self): | |
| """Choose from one of the categories""" | |
| print("~~~ Categories ~~~\n") | |
| for index, category in enumerate(self.categories): | |
| print('\t', index, ':', category.name) | |
| category_index = int(input('\nEnter your category as number: ')) | |
| self.categories[category_index].start() | |
| tshoot2 = NextStep("Then restart it.") | |
| tshoot3 = NextStep("Then try searching for the error code.") | |
| dhcp = NextStep("Have you tried restarting it", tshoot3, tshoot2, name='dhcp') | |
| vpn = NextStep("Have you tried restarting it", tshoot3, tshoot2, name='vpn') | |
| stp = NextStep("Have you tried restarting it", tshoot3, tshoot2, name='stp') | |
| vlan = NextStep("Have you tried restarting it", tshoot3, tshoot2, name='vlan') | |
| throughput = NextStep("Have you tried restarting it", tshoot3, tshoot2, | |
| name='throughput') | |
| roaming = NextStep("Have you tried restarting it", tshoot3, tshoot2, | |
| name='roaming') | |
| video_quality = NextStep("Have you tried restarting it", tshoot3, tshoot2, | |
| name='video_quality') | |
| storage = NextStep("Have you tried restarting it", tshoot3, tshoot2, | |
| name='storage') | |
| call_quality = NextStep("Have you tried restarting it", tshoot3, tshoot2, | |
| name='call_quality') | |
| call_groups = NextStep("Have you tried restarting it", tshoot3, tshoot2, | |
| name='call_groups') | |
| dep = NextStep("Have you tried restarting it", tshoot3, tshoot2, name='dep') | |
| vpp = NextStep("Have you tried restarting it", tshoot3, tshoot2, name='vpp') | |
| MX = NextStep("What kind of tshoot?", categories=[dhcp, vpn], name='MX') | |
| MS = NextStep("What kind of tshoot?", categories=[stp, vlan], name='MS') | |
| MR = NextStep("What kind of tshoot?", categories=[throughput, roaming], | |
| name='MR') | |
| MV = NextStep("What kind of tshoot?", categories=[video_quality, storage], | |
| name='MV') | |
| MC = NextStep("What kind of tshoot?", categories=[call_quality, call_groups], | |
| name='MC') | |
| SM = NextStep("What kind of tshoot?", categories=[dep, vpp], name='SM') | |
| tshoot0 = NextStep("Which type of product?", categories=[MR, | |
| MS, | |
| MX, | |
| MV, | |
| SM, | |
| MC]) | |
| tshoot0.start() | |
| """Client VPN | |
| Categories: MX, MS, MR, MV, MC, SM | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment