def createDiff(blockA, blockB, nameA=None, nameB=None): if nameA == None: if 'instance_name' in blockA: nameA = mus.getName(blockA) else: nameA = str(nameA) if nameB == None: if 'instance_name' in blockB: nameB = mus.getName(blockB) else: nameB = str(nameB) stri = formatBlock(blockA) strj = formatBlock(blockB) if len(stri) != 0 and len(strj) != 0: ratio = float(len(stri)) / float(len(strj)) if ratio > 0.9 and ratio < 1.1: global diffDirectory path = "diff" if diffDirectory == "": diffDirectory = datetime.datetime.now().strftime("%Y-%m-%d::%H:%M:%S") path = os.path.join("diffs", diffDirectory) if not os.path.exists(path): os.makedirs(os.path.join("diffs", diffDirectory)) with open(os.path.join(path, nameA + "-" + nameB + ".html"), "w") as f: f.write(difflib.HtmlDiff().make_file(stri, strj, nameA, nameB)) f.flush()
def furtherProcess(usersDir, userID, projName, jailHolder, jail): screens = jail["*Names of Screens"] if userID not in jailHolder: jailHolder[userID] = {} jailHolder["usersIDs"].append(userID) jailHolder[userID][projName] = {} jailHolder[userID][projName]["jail"] = jail screenJail = jail["screens"] blockLimit = 10 for s in screens: jailHolder[userID][projName]["counts by screens"] = {} jailHolder[userID][projName]["num blocks by screens"] = {} jailHolder[userID][projName]["num greater than limit"] = {} jailHolder[userID][projName]["kinds greater than limit"] = {} jailHolder[userID][projName]["kinds ratio"] = {} if "bky" in screenJail[s]: if mus.isADictionary(screenJail[s]["bky"]): #jailHolder[userID][projName]["counts by screens"][s] = {} for block in screenJail[s]["bky"]["topBlocks"]: if not mus.isGlobalDeclaration(block): count = countKindsOfBlocks(block) if "note" not in count: greaterThanLimit = False # [2019/01/16] The version before adding depths #for key in count: # greaterThanLimit = greaterThanLimit or count[key] >= 5 #[2019/01/16] The version with depths in account numGreaterThanLimit = 0 commonRepeatedBlocks = {} for depth in count: #mus.logwrite(mus.prettyPrint(count[depth])) if not depth.endswith(".5") and not depth.endswith(".0"): for key in count[depth]: #print key, count[depth][key] #bigEnough = count[depth][key] >= blockLimit #oldGreaterThanLimit = greaterThanLimit #greaterThanLimit = greaterThanLimit or (count[depth][key] >= blockLimit) if (count[depth][key] >= blockLimit): numGreaterThanLimit += 1 commonRepeatedBlocks[str(depth) + "." + key] = count[depth][key] #if (not oldGreaterThanLimit) and greaterThanLimit: # mus.logwrite(mus.prettyPrint(count)) if numGreaterThanLimit >= 2: if s not in jailHolder[userID][projName]["counts by screens"]: jailHolder[userID][projName]["counts by screens"][s] = {} jailHolder[userID][projName]["num blocks by screens"][s] = {} jailHolder[userID][projName]["num greater than limit"][s] = {} jailHolder[userID][projName]["kinds greater than limit"][s] = {} jailHolder[userID][projName]["kinds ratio"][s] = {} jailHolder[userID][projName]["counts by screens"][s][mus.getName(block)] = count jailHolder[userID][projName]["num blocks by screens"][s][mus.getName(block)] = mus.countBlocksInside(block) jailHolder[userID][projName]["num greater than limit"][s][mus.getName(block)] = numGreaterThanLimit jailHolder[userID][projName]["kinds greater than limit"][s][mus.getName(block)] = ";".join([(k + ":" + str(v)) for k,v in commonRepeatedBlocks.iteritems()]) jailHolder[userID][projName]["kinds ratio"][s][mus.getName(block)] = getAverageRatio(commonRepeatedBlocks) jailHolder["totalCount"] += 1 if jailHolder["totalCount"] % 1000 == 0: print jailHolder["totalCount"], usersDir, userID, projName
def dupesByEquivsObject(project, projectSet, equivClass): return { "programmer": project.programmerName, "project": "\"" + project.projectName + "\"", "screen": projectSet.screenName, "name": "" if equivClass.size() == 0 else "\"" + mus.getName(equivClass.members[0]) + "\"", # [2019/08/01, lyn] All types are component_event, so punt # "type": "" if equivClass.size() == 0 else equivClass.members[0]["*type"], # [2019/08/01, lyn] All kinds are declaration, so punt # "kind": "" if equivClass.size() == 0 else equivClass.members[0]["kind"], # [2019/08/01, lyn] Add this field from ec_sizes (so don't need ec_sizes anymore) "numberDuplicatedHandlers": str(equivClass.size()), # [2019/08/01, lyn] Change size to numBlocks, and use equiv class numBlocks method # "size": "0" if equivClass.size() == 0 else str(mus.countAllBlocks(equivClass.members[0])), "numBlocks": "0" if equivClass.size() == 0 else str(equivClass.numBlocks()), "requiresGenerics": str(equivClass.needsGenerics()), # [2019/08/01, lyn] Added this "isSingleProcedureCall": str(equivClass.isSingleProcedureCall()) }
def fuzzify(blk, depth=0): childBlockKey = '~bodyStm' argsKey = '~args' branchesKey = "~branches" elseKey = '~branchofelse' tagsToRemove = ['id', 'instance_name', 'COMPONENT_SELECTOR', 'x', 'y'] tagsToCheck = ['test', '~bodyExp'] genericTags = {'text': ('TEXT', '*generic_text*'), 'logic_boolean': ('BOOL', '*generic_boolean*')}#, # 'math_number': ('NUM', '*generic_number*')} blockListKeys = ['~bodyStm', '~args', '~branches', '~branchofelse', 'then'] # [2018/07/18] standardize ordering of arguments if mus.isCommutative(blk): if argsKey in blk: arg1 = copy.deepcopy(blk[argsKey][0]) arg2 = copy.deepcopy(blk[argsKey][1]) name1 = getName(arg1) name2 = mus.getName(arg2) if len(name1) > len(name2): blk[argsKey][0] = arg2 blk[argsKey][1] = arg1 for tag in tagsToCheck: if tag in blk: fuzzify(blk[tag], depth + 1) for tag in tagsToRemove: if tag in blk: blk.pop(tag, 0) for key in blockListKeys: if key in blk: for child in blk[key]: fuzzify(child, depth + 1) for k,v in genericTags.iteritems(): if "*type" in blk: if blk['*type'] == k: a = v[0] b = v[1] blk[a] = b
printHeader2('Sales',errorString) ################ # Get list of items for add sale form cursor.execute("SELECT itemId,manufacturer,brand,name FROM item INNER JOIN binItems USING (itemId) WHERE quantity > 0 GROUP BY manufacturer,brand,name ORDER BY manufacturer,brand,name") itemOptions = [] for (itemId,manufacturer,brand,name) in cursor: itemOptions.append('<OPTION VALUE=Item%s>%s</OPTION>'%(itemId,getItemName(manufacturer,brand,name))) ################### # Get list of kits for add sale form cursor.execute("SELECT kitId,name FROM Kit ORDER BY name") for (kitId,name) in cursor: itemOptions.append('<OPTION VALUE=Kit%s>Kit: %s</OPTION>'%(kitId,getName(name))) ##### # Add form print ''' <div class=addthing> <H2>Add new sale</H2> <FORM name=addTran ACTION=newSaleDetails.py> Buyer: <INPUT TYPE=TEXT NAME=buyer ID=buyer SIZE=40 /> <br /> Reconcile entry: <INPUT TYPE=checkbox NAME=reconcile /> <br /> <TABLE BORDER=1 ID=addTranItemTable> <TR><TH>Item</TH><TH>Qty</TH><TH>Cost/item</TH><TH>Total</TH></TR> <TR><TD COLSPAN=3>Shipping costs:</TD><TD><INPUT TYPE=TEXT CLASS=money NAME=shipping ID=shipping VALUE=0.00 SIZE=5 onBlur='moneyFormat(event.target);calcTotals()'/></TD></TR>
def furtherProcess(usersDir, userID, projName, jailDict, jail): screens = jail["*Names of Screens"] screenJail = jail["screens"] userIDKey = "userID" projNameKey = "projectName" blockNameKey = "blockName" #mus.logwrite("furtherProcess::{}, {}, {}".format(usersDir, userID, projName)) furtherProcess.numForLoops = 0 furtherProcess.numWhileLoops = 0 # Hopefully by short-circuiting, the second part won't actually throw any errors if (len(jailDict["loopsByProgrammer"]) == 0) or (jailDict["loopsByProgrammer"][ jailDict["numLoopsByProgrammer"]][userIDKey] != userID): jailDict["loopsByProgrammer"].append({ userIDKey: userID, "numForLoops": 0, "numWhileLoops": 0 }) jailDict["numLoopsByProgrammer"] += 1 jailDict["loopsByProject"].append({ userIDKey: userID, projNameKey: projName, "numForLoops": 0, "numWhileLoops": 0 }) jailDict["numLoopsByProj"] += 1 def enumerateLoop(blk): t = mus.getType(blk) if t != None: if t == "controls_forRange": furtherProcess.numForLoops += 1 elif t == "controls_while": furtherProcess.numWhileLoops += 1 for s in screens: if "bky" in screenJail[s]: jailDict["forLoopsByScreen"].append({ "screen": s, userIDKey: userID, projNameKey: projName, "numForLoops": 0, "numWhileLoops": 0 }) num = len(jailDict["forLoopsByScreen"]) - 1 if mus.isADictionary(screenJail[s]["bky"]): for block in screenJail[s]["bky"]["topBlocks"]: if not mus.isGlobalDeclaration(block): furtherProcess.numForLoops = 0 furtherProcess.numWhileLoops = 0 mus.countSomething(block, enumerateLoop) minidict = { userIDKey: userID, projNameKey: projName, blockNameKey: "\"{}\"".format(mus.getName(block)), "screen": s, "numForLoops": furtherProcess.numForLoops, "numWhileLoops": furtherProcess.numWhileLoops } #minidict[userIDKey] = userID #minidict[projNameKey] = projName #minidict[blockNameKey] = "\"{}\"".format(mus.getName(block)) #minidict["screen"] = s #minidict["numForLoops"] = furtherProcess.numForLoops jailDict["forLoopsByScreen"][num][ "numForLoops"] += furtherProcess.numForLoops jailDict["forLoopsByScreen"][num][ "numWhileLoops"] += furtherProcess.numWhileLoops #minidict["numWhileLoops"] = furtherProcess.numWhileLoops jailDict["loopStats"].append( copy.deepcopy(minidict)) jailDict["totalCount"] += 1 if jailDict["totalCount"] % printEvery == 0: mus.logwrite("{}\t{}\t{}\t{}".format( jailDict["totalCount"], usersDir, userID, projName)) jailDict["loopsByProject"][ jailDict["numLoopsByProj"]]["numForLoops"] += jailDict[ "forLoopsByScreen"][num]["numForLoops"] jailDict["loopsByProject"][ jailDict["numLoopsByProj"]]["numWhileLoops"] += jailDict[ "forLoopsByScreen"][num]["numWhileLoops"] jailDict["loopsByProgrammer"][jailDict["numLoopsByProgrammer"]][ "numForLoops"] += jailDict["loopsByProject"][ jailDict["numLoopsByProj"]]["numForLoops"] jailDict["loopsByProgrammer"][jailDict["numLoopsByProgrammer"]][ "numWhileLoops"] += jailDict["loopsByProject"][ jailDict["numLoopsByProj"]]["numWhileLoops"]