def index(): if request.form.has_key("changeCat") or request.form.has_key("changeProb"): myObj = None for node in roots: if (node.nodeType() == "Category" and node.payload.name == request.form['selectedCat']) or node.nodeType() == "Problem": myObj = node break if myObj!=None: del roots[:] for thing in myObj.returnRootChildren(): roots.append(thing) #else elif len(roots) == 0: metaData=Tree.query() if len(metaData.fetch(None))==0: r1 = Node(storeCat("Lawn Equipment")) roots.append(r1) lm = r1.addSubNode(storeCat("Lawn Mower")) we = r1.addSubNode(storeCat("Weed Eater")) r1.addSubNode(storeCat("Edger")) r2 = Node(storeCat("Mobile Phone")) rr2 = r2.addSubNode(storeProb("Are you having a problem?", None)) roots.append(r2); gp = rr2.addSubNode(storeProb("Does the lawn mower have gas?", None)) rr2.addSubNode(storeProb("Is the lawn mower making noises?", None)) gp.addSubNode(storeProb(None, "You don't have any gas!")) we.addSubNode(storeCat("Torro")) honda = lm.addSubNode(storeCat("Honda")) bd = lm.addSubNode(storeCat("B&D")) honda.addSubNode(storeProb("WOW",None)) bd.addSubNode(storeCat("itWORKS!")) r1.printTree() treeDict = r1.convertTree() Tree(str(r1.convertTree())).put() Tree(str(r2.convertTree())).put() r1Prime = Node(treeDict) r1Prime.printTree() else: for probsol in Problem.query(): config.probList.append(probsol) for cat in Category.query(): config.catList.append(cat) trees = Tree.query() # get item list for tree in trees: # find correct item roots.append(Node(ast.literal_eval(tree.tree))) return render_template("testindex.html", roots=roots)
def index(): if request.form.has_key("changeCat") or request.form.has_key("changeProb"): myObj = None for node in roots: if (node.nodeType() == "Category" and node.payload.name == request.form['selectedCat'] ) or node.nodeType() == "Problem": myObj = node break if myObj != None: del roots[:] del problems[:] del models[:] roots.append(myObj) for thing in myObj.returnRootChildren(): items.append(thing) elif request.form.has_key("changeItem"): myObj = None for node in items: if (node.nodeType() == "Category" and node.payload.name == request.form['selectedItem']): myObj = node break if myObj != None: del items[:] items.append(myObj) for thing in myObj.returnRootChildren(): models.append(thing) elif request.form.has_key("changeModelParts"): myObj = None for node in models: if (node.nodeType() == "Category" and node.payload.name == request.form['selectedModel']): myObj = node break if myObj != None: del models[:] models.append(myObj) for thing in myObj.returnRootChildren(): if thing.nodeType() == "Category": parts.append(thing) return render_template("parts.html", models=models, parts=parts) elif request.form.has_key("Parts"): return render_template("parts.html", models=models, parts=parts) elif request.form.has_key("Part"): myObj = None for node in parts: if node.nodeType( ) == "Category" and node.payload.name == request.form[ 'selectedPart']: myObj = node break if myObj != None: del roots[:] del items[:] del models[:] del parts[:] part = myObj return render_template("partSelectedDiv.html", part=part) elif request.form.has_key("changeModelProblems"): myObj = None for node in models: if (node.nodeType() == "Category" and node.payload.name == request.form['selectedModel']): myObj = node break if myObj != None: del models[:] models.append(myObj) for thing in myObj.returnRootChildren(): if thing.nodeType() == "Problem": problems.append(thing) return render_template("problems.html", models=models, problems=problems) elif request.form.has_key("Problems"): return render_template("problems.html", models=models, problems=problems) elif request.form.has_key("Problem") and request.form['yesProbs']: myObj = None for node in problems: if (node.nodeType() == "Problem" and (node.payload.problem == request.form['selectedThing'] or node.payload.solution == request.form['selectedThing'])): myObj = node break if myObj != None: del roots[:] del items[:] del parts[:] del problems[:] problems.append(myObj) for thing in myObj.returnRootChildren(): if thing.payload.problem: problems.append(thing) else: answer = thing.payload.solution return render_template("problems.html", models=models, problems=problems, answer=answer) #Needs to be pushed to github #else elif len(roots) == 0: metaData = Tree.query() if len(metaData.fetch(None)) == 0: r1 = Node(storeCat("Lawn Equipment")) roots.append(r1) lm = r1.addSubNode(storeCat("Lawn Mower")) we = r1.addSubNode(storeCat("Weed Eater")) ed = r1.addSubNode(storeCat("Edger")) r2 = Node(storeCat("Mobile Phone")) att = r2.addSubNode(storeCat("AT&T")) verizon = r2.addSubNode(storeCat("Verizon")) sprint = r2.addSubNode(storeCat("Sprint")) nexs = sprint.addSubNode(storeCat("Nexus")) iphones = sprint.addSubNode(storeCat("iPhone 7")) galaxys = sprint.addSubNode(storeCat("Galaxy 7S")) nexa = att.addSubNode(storeCat("Nexus")) iphonea = att.addSubNode(storeCat("iPhone 7")) galaxya = att.addSubNode(storeCat("Galaxy 7S")) nexv = verizon.addSubNode(storeCat("Nexus")) iphonev = verizon.addSubNode(storeCat("iPhone 7")) galaxyv = verizon.addSubNode(storeCat("Galaxy 7S")) nexsprobone = nexs.addSubNode(storeProb("Broken Screen?", None)) nexsprobtwo = nexs.addSubNode( storeProb("Broken home button?", None)) nexsprobthree = nexs.addSubNode( storeProb("Phone doesn't turn on?", None)) nexsprobone.addSubNode(storeProb(None, "You need a new screen!")) nexsprobtwo.addSubNode( storeProb(None, "You need a new home button!")) nexsprobthree.addSubNode(storeProb(None, "You need a new battery!")) nexaprobone = nexa.addSubNode(storeProb("Broken Screen?", None)) nexaprobtwo = nexa.addSubNode( storeProb("Broken home button?", None)) nexaprobthree = nexa.addSubNode( storeProb("Phone doesn't turn on?", None)) nexaprobone.addSubNode(storeProb(None, "You need a new screen!")) nexaprobtwo.addSubNode( storeProb(None, "You need a new home button!")) nexaprobthree.addSubNode(storeProb(None, "You need a new battery!")) nexvprobone = nexv.addSubNode(storeProb("Broken Screen?", None)) nexvprobtwo = nexv.addSubNode( storeProb("Broken home button?", None)) nexvprobthree = nexv.addSubNode( storeProb("Phone doesn't turn on?", None)) nexvprobone.addSubNode(storeProb(None, "You need a new screen!")) nexvprobtwo.addSubNode( storeProb(None, "You need a new home button!")) nexvprobthree.addSubNode(storeProb(None, "You need a new battery!")) iphonesprobone = iphones.addSubNode( storeProb("Broken Screen?", None)) iphonesprobtwo = iphones.addSubNode( storeProb("Broken home button?", None)) iphonesprobthree = iphones.addSubNode( storeProb("Phone doesn't turn on?", None)) iphonesprobone.addSubNode(storeProb(None, "You need a new screen!")) iphonesprobtwo.addSubNode( storeProb(None, "You need a new home button!")) iphonesprobthree.addSubNode( storeProb(None, "You need a new battery!")) iphoneaprobone = iphonea.addSubNode( storeProb("Broken Screen?", None)) iphoneaprobtwo = iphonea.addSubNode( storeProb("Broken home button?", None)) iphoneaprobthree = iphonea.addSubNode( storeProb("Phone doesn't turn on?", None)) iphoneaprobone.addSubNode(storeProb(None, "You need a new screen!")) iphoneaprobtwo.addSubNode( storeProb(None, "You need a new home button!")) iphoneaprobthree.addSubNode( storeProb(None, "You need a new battery!")) iphonevprobone = iphonev.addSubNode( storeProb("Broken Screen?", None)) iphonevprobtwo = iphonev.addSubNode( storeProb("Broken home button?", None)) iphonevprobthree = iphonev.addSubNode( storeProb("Phone doesn't turn on?", None)) iphonevprobone.addSubNode(storeProb(None, "You need a new screen!")) iphonevprobtwo.addSubNode( storeProb(None, "You need a new home button!")) iphonevprobthree.addSubNode( storeProb(None, "You need a new battery!")) galaxysprobone = galaxys.addSubNode( storeProb("Broken Screen?", None)) galaxysprobtwo = galaxys.addSubNode( storeProb("Broken home button?", None)) galaxysprobthree = galaxys.addSubNode( storeProb("Phone doesn't turn on?", None)) galaxysprobone.addSubNode(storeProb(None, "You need a new screen!")) galaxysprobtwo.addSubNode( storeProb(None, "You need a new home button!")) galaxysprobthree.addSubNode( storeProb(None, "You need a new battery!")) galaxyaprobone = galaxya.addSubNode( storeProb("Broken Screen?", None)) galaxyaprobtwo = galaxya.addSubNode( storeProb("Broken home button?", None)) galaxyaprobthree = galaxya.addSubNode( storeProb("Phone doesn't turn on?", None)) galaxyaprobone.addSubNode(storeProb(None, "You need a new screen!")) galaxyaprobtwo.addSubNode( storeProb(None, "You need a new home button!")) galaxyaprobthree.addSubNode( storeProb(None, "You need a new battery!")) galaxyvprobone = galaxyv.addSubNode( storeProb("Broken Screen?", None)) galaxyvprobtwo = galaxyv.addSubNode( storeProb("Broken home button?", None)) galaxyvprobthree = galaxyv.addSubNode( storeProb("Phone doesn't turn on?", None)) galaxyvprobone.addSubNode(storeProb(None, "You need a new screen!")) galaxyvprobtwo.addSubNode( storeProb(None, "You need a new home button!")) galaxyvprobthree.addSubNode( storeProb(None, "You need a new battery!")) nexs.addSubNode(storeCat("Screen")) nexs.addSubNode(storeCat("Home Button")) nexs.addSubNode(storeCat("Battery")) nexa.addSubNode(storeCat("Screen")) nexa.addSubNode(storeCat("Home Button")) nexa.addSubNode(storeCat("Battery")) nexv.addSubNode(storeCat("Screen")) nexv.addSubNode(storeCat("Home Button")) nexv.addSubNode(storeCat("Battery")) iphones.addSubNode(storeCat("Screen")) iphones.addSubNode(storeCat("Home Button")) iphones.addSubNode(storeCat("Battery")) iphonea.addSubNode(storeCat("Screen")) iphonea.addSubNode(storeCat("Home Button")) iphonea.addSubNode(storeCat("Battery")) iphonev.addSubNode(storeCat("Screen")) iphonev.addSubNode(storeCat("Home Button")) iphonev.addSubNode(storeCat("Battery")) galaxys.addSubNode(storeCat("Screen")) galaxys.addSubNode(storeCat("Home Button")) galaxys.addSubNode(storeCat("Battery")) galaxya.addSubNode(storeCat("Screen")) galaxya.addSubNode(storeCat("Home Button")) galaxya.addSubNode(storeCat("Battery")) galaxyv.addSubNode(storeCat("Screen")) galaxyv.addSubNode(storeCat("Home Button")) galaxyv.addSubNode(storeCat("Battery")) roots.append(r2) torro = we.addSubNode(storeCat("Torro")) torro.addSubNode(storeCat("Gas Tank")) torro.addSubNode(storeCat("Pull String")) torro.addSubNode(storeCat("Spark Plugs")) craftsmen = we.addSubNode(storeCat("Craftsmen")) craftsmen.addSubNode(storeCat("Gas Tank")) craftsmen.addSubNode(storeCat("Nylon String")) honda = lm.addSubNode(storeCat("Honda")) honda.addSubNode(storeCat("Gas Tank")) honda.addSubNode(storeCat("Blades")) honda.addSubNode(storeCat("Spark Plugs")) bd = lm.addSubNode(storeCat("B&D")) bd.addSubNode(storeCat("Wheels")) bd.addSubNode(storeCat("Bearings")) torro2 = ed.addSubNode(storeCat("Torro")) torro2.addSubNode(storeCat("Handles")) torro2.addSubNode(storeCat("Screws")) torroprobone = torro.addSubNode(storeProb("Do you have gas?", None)) torroprobtwo = torro.addSubNode( storeProb("Is your pull string tangled?", None)) torroprobone.addSubNode(storeProb(None, "You have no gas!")) torroprobtwo.addSubNode( storeProb(None, "You need to untangle your pull string!")) craftsmenprobone = craftsmen.addSubNode( storeProb("Do you have gas?", None)) craftsmenprobtwo = craftsmen.addSubNode( storeProb("Is your pull string tangled?", None)) craftsmenprobone.addSubNode(storeProb(None, "You have no gas!")) craftsmenprobtwo.addSubNode( storeProb(None, "You need to untangle your pull string!")) hondaprobone = honda.addSubNode(storeProb("Do you have gas?", None)) hondaprobtwo = honda.addSubNode( storeProb("Are the blades dull?", None)) hondaprobone.addSubNode(storeProb(None, "You have no gas!")) hondaprobtwo.addSubNode(storeProb(None, "Your blades are dull!")) bdprobone = bd.addSubNode( storeProb("Are your wheels wobbling?", None)) bdprobtwo = bd.addSubNode( storeProb("Are you hearing a squeaking noise as you mow?", None)) bdprobone.addSubNode( storeProb(None, "You need to tighten the wheels!")) bdprobtwo.addSubNode( storeProb( None, "You need to put some damn WD-40 on those bearings!!!")) torro2probone = torro2.addSubNode( storeProb("Are you handles wobbling off as you cut?", None)) torro2probtwo = torro2.addSubNode( storeProb("Are your handles rusty?", None)) torro2probone.addSubNode( storeProb(None, "You need to tighten the screws!")) torro2probtwo.addSubNode( storeProb(None, "You definitely need some new handles!")) r1.printTree() #treeDict = r1.convertTree() Tree(str(r1.convertTree())).put() Tree(str(r2.convertTree())).put() #r1Prime = Node(treeDict) #r1Prime.printTree() else: for probsol in Problem.query(): config.probList.append(probsol) for cat in Category.query(): config.catList.append(cat) trees = Tree.query() # get item list for tree in trees: # find correct item roots.append(Node(ast.literal_eval(tree.tree))) return render_template("testindex.html", roots=roots, items=items)
def setupTree(): if len(roots) == 0: metaData = Tree.query() if len(metaData.fetch(None)) == 0: root1 = Node(storeCat("Lawn Equipment")) roots.append(root1) lawnmower = root1.addSubNode(storeCat("Lawn Mower")) weedeater = root1.addSubNode(storeCat("Weed Eater")) edger = root1.addSubNode(storeCat("Edger")) wontStart = lawnmower.addSubNode( storeProb("Lawn mower won't start", None)) ws1 = wontStart.addSubNode( storeProb("Is there gas in the tank?", "Put gas in the mower!")) ws2 = ws1.addSubNode( storeProb("Will the mower jump start?", "Replace the battery!")) ws3 = ws2.addSubNode( storeProb("Do the spark plugs appear clean?", "Clear or replace the plugs!", url="https://goo.gl/FJneX0")) wontCut = lawnmower.addSubNode( storeProb("Mower isn't cutting the grass well", None)) wc1 = wontCut.addSubNode( storeProb("Is the grass a reasonable height?", "Raise the cutting height on your lawn mower")) wc2 = wc1.addSubNode( storeProb("Does the blade appear to be sharp?", "Replace or sharpen the blade", "https://goo.gl/ANuuah")) toro = lawnmower.addSubNode(storeCat("Toro", type='part')) honda = lawnmower.addSubNode(storeCat("Honda", type='part')) craftsman = lawnmower.addSubNode(storeCat("Craftsman", type='part')) honda.addSubNode( storeCat("Spark Plug", type='part', url="https://goo.gl/4988HT")) honda.addSubNode( storeCat("Blade", type='part', url="https://goo.gl/6IzHDH")) honda.addSubNode( storeCat("Battery", type='part', url="https://goo.gl/j32Qs0")) toro.addSubNode( storeCat("Spark Plug", type='part', url="https://goo.gl/iSq3IM")) toro.addSubNode( storeCat("Blade", type='part', url="https://goo.gl/awrF4W")) toro.addSubNode( storeCat("Battery", type='part', url="https://goo.gl/hxFbMM")) craftsman.addSubNode( storeCat("Spark Plug", type='part', url="https://goo.gl/uMbjzb")) craftsman.addSubNode( storeCat("Blade", type='part', url="https://goo.gl/6mcSAe")) craftsman.addSubNode( storeCat("Battery", type='part', url="https://goo.gl/Txykkp")) root2 = Node(storeCat("Smartphone")) roots.append(root2) android = root2.addSubNode(storeCat("Google Android")) apple = root2.addSubNode(storeCat("Apple iOS")) slow = android.addSubNode(storeProb("My phone is slow", None)) sl1 = slow.addSubNode( storeProb("Has the phone been restarted recently?", "Reboot the phone")) sl2 = sl1.addSubNode( storeProb("Are there only a few apps open?", "Close the apps you aren't actively using")) sl3 = sl2.addSubNode( storeProb("Is atleast 90% of the phone storage free?", "Removed unused apps or upgrade the storage")) app = android.addSubNode( storeProb("I want to develop an app", "Follow a tutorial", None)) app.addSubNode( storeProb( "Have you tried following a tutorial?", "Use an online tutorial", url= "https://developer.android.com/training/basics/firstapp/index.html" )) slow = apple.addSubNode(storeProb("My phone is slow", None)) sl1 = slow.addSubNode( storeProb("Has the phone been restarted recently?", "Reboot the phone")) sl2 = sl1.addSubNode( storeProb("Are there only a few apps open?", "Close the apps you aren't actively using")) sl3 = sl2.addSubNode( storeProb("Is atleast 90% of the phone storage free?", "Removed unused apps or upgrade the storage")) app = apple.addSubNode( storeProb("I want to develop an app", "Follow a tutorial", None)) app.addSubNode( storeProb( "Have you tried following a tutorial?", "Use an online tutorial", url= "https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/" )) moto = android.addSubNode(storeCat("Motorola", type='part')) samsung = android.addSubNode(storeCat("Samsung", type='part')) huawei = android.addSubNode(storeCat("Huawei", type='part')) moto.addSubNode( storeCat("Case", type='part', url="https://goo.gl/aSNG2U")) samsung.addSubNode( storeCat("Case", type='part', url="https://goo.gl/T10QPU")) huawei.addSubNode( storeCat("Case", type='part', url="https://goo.gl/frSgRq")) apple.addSubNode( storeCat("Case", type='part', url="https://goo.gl/6vclg7")) root1.printTree() root2.printTree() testTree = str(root1.convertTree()) print testTree # treeDict = root1.convertTree() Tree(tree=testTree).put() Tree(tree=str(root2.convertTree())).put() # r1Prime = Node(treeDict) # print r1Prime print root1 print root2 else: for probsol in Problem.query(): probList.append(probsol) for cat in Category.query(): catList.append(cat) trees = Tree.query() # get item list for tree in trees: # find correct item roots.append(Node(ast.literal_eval(tree.tree))) for root in roots: root.printTree() print "Length of probList is " + str(len(probList)) print "Length of catList is " + str(len(catList))