How to use highlightFilename method in fMBT

Best Python code snippet using fMBT_python

fmbtgti.py

Source:fmbtgti.py Github

copy

Full Screen

...2096 x2, y2 = args[1]2097 retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2098 try:2099 screenshotFilename = loggerSelf._device.screenshot().filename()2100 highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2101 iC = loggerSelf._device.intCoords2102 eyenfinger.drawLines(screenshotFilename, highlightFilename, [], [iC((x1, y1)), iC((x2, y2))])2103 loggerSelf.logReturn(retval, img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name)2104 except:2105 loggerSelf.logReturn(str(retval) + " (no screenshot available)", tip=origMethod.func_name)2106 return retval2107 return dragWRAP2108 def refreshScreenshotLogger(loggerSelf, origMethod):2109 def refreshScreenshotWRAP(*args, **kwargs):2110 loggerSelf._highlightCounter = 02111 logCallReturnValue = loggerSelf.logCall()2112 retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2113 retval._logCallReturnValue = logCallReturnValue2114 loggerSelf.logReturn(retval, img=retval, tip=origMethod.func_name)2115 retval.findItemsByBitmap = loggerSelf.findItemsByBitmapLogger(retval.findItemsByBitmap, retval)2116 retval.findItemsByOcr = loggerSelf.findItemsByOcrLogger(retval.findItemsByOcr, retval)2117 return retval2118 return refreshScreenshotWRAP2119 def tapLogger(loggerSelf, origMethod):2120 def tapWRAP(*args, **kwargs):2121 loggerSelf.logCall()2122 retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2123 try:2124 screenshotFilename = loggerSelf._device.screenshot().filename()2125 highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2126 eyenfinger.drawClickedPoint(screenshotFilename, highlightFilename, loggerSelf._device.intCoords(args[0]))2127 loggerSelf.logReturn(retval, img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name, imgTip=loggerSelf._device.screenshot()._logCallReturnValue)2128 except:2129 loggerSelf.logReturn(str(retval) + " (no screenshot available)", tip=origMethod.func_name)2130 return retval2131 return tapWRAP2132 def findItemsByBitmapLogger(loggerSelf, origMethod, screenshotObj):2133 def findItemsByBitmapWRAP(*args, **kwargs):2134 bitmap = args[0]2135 absPathBitmap = screenshotObj._paths.abspath(bitmap)2136 if loggerSelf._copyBitmapsToScreenshotDir:2137 screenshotDirBitmap = os.path.join(2138 os.path.dirname(screenshotObj.filename()),2139 "bitmaps",2140 bitmap.lstrip(os.sep))2141 if not os.access(screenshotDirBitmap, os.R_OK):2142 # bitmap is not yet copied under screenshotDir2143 destDir = os.path.dirname(screenshotDirBitmap)2144 if not os.access(destDir, os.W_OK):2145 try:2146 os.makedirs(destDir)2147 except IOError:2148 pass # cannot make dir / dir not writable2149 try:2150 shutil.copy(absPathBitmap, destDir)2151 absPathBitmap = screenshotDirBitmap2152 except IOError:2153 pass # cannot copy bitmap2154 else:2155 absPathBitmap = screenshotDirBitmap2156 loggerSelf.logCall(img=absPathBitmap)2157 retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2158 if len(retval) == 0:2159 loggerSelf.logReturn("not found in", img=screenshotObj, tip=origMethod.func_name)2160 else:2161 foundItems = retval2162 screenshotFilename = screenshotObj.filename()2163 highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2164 eyenfinger.drawIcon(screenshotFilename, highlightFilename, bitmap, [i.bbox() for i in foundItems])2165 loggerSelf.logReturn([str(quiItem) for quiItem in retval], img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name, imgTip=screenshotObj._logCallReturnValue)2166 return retval2167 return findItemsByBitmapWRAP2168 def findItemsByOcrLogger(loggerSelf, origMethod, screenshotObj):2169 def findItemsByOcrWRAP(*args, **kwargs):2170 loggerSelf.logCall()2171 retval = loggerSelf.doCallLogException(origMethod, args, kwargs)2172 if len(retval) == 0:2173 loggerSelf.logReturn("not found in words " + str(screenshotObj.dumpOcrWords()),2174 img=screenshotObj, tip=origMethod.func_name)2175 else:2176 foundItem = retval[0]2177 screenshotFilename = screenshotObj.filename()2178 highlightFilename = loggerSelf.highlightFilename(screenshotFilename)2179 eyenfinger.drawIcon(screenshotFilename, highlightFilename, args[0], foundItem.bbox())2180 for appearance, foundItem in enumerate(retval[1:42]):2181 eyenfinger.drawIcon(highlightFilename, highlightFilename, str(appearance+1) + ": " + args[0], foundItem.bbox())2182 loggerSelf.logReturn([str(retval[0])], img=highlightFilename, width=loggerSelf._screenshotWidth, tip=origMethod.func_name, imgTip=screenshotObj._logCallReturnValue)2183 return retval2184 return findItemsByOcrWRAP2185 def relFilePath(self, fileOrDirName, fileLikeObj):2186 if hasattr(fileLikeObj, "name"):2187 referenceDir = os.path.dirname(fileLikeObj.name)2188 else:2189 return fileOrDirName # keep it absolute if there's no reference2190 return os.path.relpath(fileOrDirName, referenceDir)2191 def imgToHtml(self, img, width="", imgTip="", imgClass=""):2192 if imgClass: imgClassAttr = 'class="%s" ' % (imgClass,)2193 else: imgClassAttr = ""2194 if isinstance(img, Screenshot):2195 imgHtmlName = self.relFilePath(img.filename(), self._outFileObj)2196 imgHtml = '<tr><td></td><td><img %stitle="%s" src="%s" width="%s" alt="%s" /></td></tr>' % (2197 imgClassAttr,2198 "%s refreshScreenshot() at %s:%s" % img._logCallReturnValue,2199 imgHtmlName,2200 self._screenshotWidth,2201 imgHtmlName)2202 elif img:2203 if width: width = 'width="%s"' % (width,)2204 if type(imgTip) == tuple and len(imgTip) == 3:2205 imgTip = 'title="%s refreshScreenshot() at %s:%s"' % imgTip2206 else:2207 imgTip = 'title="%s"' % (imgTip,)2208 imgHtmlName = self.relFilePath(img, self._outFileObj)2209 imgHtml = '<tr><td></td><td><img %s%s src="%s" %s alt="%s" /></td></tr>' % (2210 imgClassAttr, imgTip, imgHtmlName, width, imgHtmlName)2211 else:2212 imgHtml = ""2213 return imgHtml2214 def highlightFilename(self, screenshotFilename):2215 self._highlightCounter += 12216 retval = screenshotFilename + "." + str(self._highlightCounter).zfill(5) + ".png"2217 return retval2218 def changeCodeName(self, func, newName):2219 c = func.func_code2220 func.func_name = newName2221 func.func_code = types.CodeType(2222 c.co_argcount, c.co_nlocals, c.co_stacksize, c.co_flags,2223 c.co_code, c.co_consts, c.co_names, c.co_varnames,...

Full Screen

Full Screen

IAA.py

Source:IAA.py Github

copy

Full Screen

1import csv2from ChecklistCoding import *3from ExtraInfo import *4from dataV2 import *5from repScores import *6import os7path = 'sss_pull_8_22/SSSPECaus2-2018-08-22T2019-DataHuntHighlights.csv'8def calc_agreement_directory(directory, hardCodedTypes = False, repCSV=None, answersFile = None, outDirectory = None):9 print("IAA STARTING")10 if outDirectory is None:11 outDirectory = 's_iaa_'+directory12 highlights = []13 answers = []14 schema = []15 for root, dir, files in os.walk(directory):16 for file in files:17 if file.endswith('.csv') and 'IAA' not in file:18 print("Checking Agreement for "+directory+'/'+file)19 if 'Highlights' in file:20 print('highlight')21 highlights.append(directory+'/'+file)22 elif 'Answers' in file:23 answers.append(directory+'/'+file)24 elif 'Schema' in file:25 schema.append(directory+'/'+file)26 #sorting filenames alphabetically separates them into the right schemas, it's a gimmick and might not scale27 #if it doesn't work there'll be key errors because taskIDS won't align28 highlights.sort()29 answers.sort()30 schema.sort()31 assert(len(highlights) == len(schema), 'files not found')32 for i in range(len(highlights)):33 calc_scores(highlights[i], hardCodedTypes=hardCodedTypes, repCSV = repCSV,34 answersFile = answers[i], schemaFile=schema[i], outDirectory=outDirectory)35 #will be an error for every file that isn't the right file, there's a more graceful solution, but36 #we'll save that dream for another day37 return outDirectory38def calc_scores(highlightfilename, hardCodedTypes = False, repCSV=None, answersFile = None, schemaFile = None, fileName = None, thirtycsv = None, outDirectory = 's_iaa'):39 print('collecting Data')40 uberDict = data_storer(highlightfilename, answersFile, schemaFile)41 print("donegettingdata")42 data = [["article_num", "article_sha256", "task_uuid","schema_namespace","question_Number", "question_type", "agreed_Answer", "coding_perc_agreement", "one_two_diff",43 "highlighted_indices", "alpha_unitizing_score", "alpha_unitizing_score_inclusive", "agreement_score","odds_by_chance", "binary_odds_by_chance",44 "num_users", "num_answer_choices","target_text", 'question_text', 'answer_content']]45 #initialize rep46 # print('starting rep')47 # try:48 # repDF = pd.read_csv(repCSV)49 # except:50 # repDF = create_user_dataframe(uberDict, csvPath = None)51 # thirtyDf = create_last30_dataframe(uberDict, thirtycsv)52 repDF, thirtyDf = None, None53 print('initialized repScores')54 for task in uberDict.keys(): # Iterates throuh each article55 #task_id = get_article_num(uberDict, task)56 task_id = task57 article_num = get_article_num(uberDict,task_id)58 article_sha = get_article_sha(uberDict, task_id)59 schema_namespace = get_schema(uberDict, task_id)60 questions = uberDict[task]['quesData'].keys()61 #has to be sorted for questions depending on each other to be handled correctly62 for ques in sorted(questions): # Iterates through each question in an article63 agreements = score(task, ques, uberDict, repDF, thirtyDf = thirtyDf,hardCodedTypes = hardCodedTypes)64 # if it's a list then it was a checklist question65 question_text = get_question_text(uberDict, task, ques)66 if type(agreements) is list:67 #Checklist Question68 for i in range(len(agreements)):69 codingPercentAgreement, unitizingScore = agreements[i][4], agreements[i][2]70 winner, units = agreements[i][0], agreements[i][1]71 inclusiveUnitizing = agreements[i][3]72 selectedText, firstSecondScoreDiff = agreements[i][6], agreements[i][7]73 question_type, num_choices = agreements[i][8], agreements[i][9]74 num_users = agreements[i][5]75 totalScore = calcAgreement(codingPercentAgreement, unitizingScore)76 answer_text = get_answer_content(uberDict,task, ques, agreements[i][0])77 # parent_data, units, unitizingScore, inclusiveUnitizing = evalDependency(uberDict, task, parentData,78 # ques, winner, units,79 # unitizingScore, inclusiveUnitizing)80 bin_chance_odds = oddsDueToChance(codingPercentAgreement,num_users=num_users, num_choices=2)81 #Treat each q as a binary yes/no82 chance_odds = bin_chance_odds83 ques_num = ques84 units = str(units).replace('\n', '')85 units = units.replace(' ', ', ')86 data.append([article_num, article_sha, task_id, schema_namespace, ques_num, agreements[i][8], winner,87 codingPercentAgreement, agreements[i][7], units,88 unitizingScore, inclusiveUnitizing, totalScore, chance_odds, bin_chance_odds, num_users, agreements[i][9],agreements[i][6],89 question_text, answer_text])90 else:91 #winner, units, uScore, iScore, highScore, numUsers, selectedText, firstSecondScoreDiff92 winner, units = agreements[0], agreements[1]93 inclusiveUnitizing, numUsers = agreements[3], agreements[5]94 selectedText, firstSecondScoreDiff = agreements[6], agreements[7]95 question_type, num_choices = agreements[8], agreements[9]96 codingPercentAgreement, unitizingScore = agreements[4], agreements[2]97 num_users = agreements[5]98 # parent_data, units, unitizingScore, inclusiveUnitizing = evalDependency(uberDict, task, parentData,99 # ques, winner, units,100 # unitizingScore,101 # inclusiveUnitizing)102 bin_chance_odds = oddsDueToChance(codingPercentAgreement,num_users=num_users, num_choices=2)103 chance_odds = oddsDueToChance(codingPercentAgreement,num_users=num_users, num_choices=num_choices)104 answer_text = get_answer_content(uberDict, task, ques, agreements[0])105 totalScore = calcAgreement(codingPercentAgreement, unitizingScore)106 #ques_num = parse(ques, 'Q')107 ques_num = ques108 units = str(units).replace('\n', '')109 units = units.replace(' ', ', ')110 data.append([article_num, article_sha,task_id,schema_namespace, ques_num, agreements[8], winner, codingPercentAgreement, agreements[7],111 units, unitizingScore, inclusiveUnitizing,112 totalScore, chance_odds, bin_chance_odds, num_users, agreements[9], selectedText,113 question_text, answer_text])114 # push out of womb, into world115 #print('exporting rep_scores')116 # print(repDF)117# repDF.to_csv('RepScores/Repscore10.csv', mode='a', header=False)118 # userid_to_CSV(repDF)119 print('exporting to csv')120 # if outDirectory[-1] != '/':121 # outDirectory = outDirectory +'/'122 #123 # try:124 # scores = open(outDirectory+'S_IAA_'+name, 'w', encoding = 'utf-8')125 # except FileNotFoundError:126 # os.mkdir(outDirectory)127 outDirectory = make_directory(outDirectory)128 path, name = get_path(highlightfilename)129 scores = open(outDirectory + 'S_IAA_' + name, 'w', encoding='utf-8')130 with scores:131 writer = csv.writer(scores)132 writer.writerows(data)133 print("Table complete")134 print('iaa outdir', outDirectory)135 return outDirectory136def adjustForJson(units):137 units = str(units)138 out = '['139 prev = False140 for u in range(len(units)):141 if units[u].isdigit():142 out+=units[u]143 prev = True144 elif units[u] == ' ' and prev == True:145 out+=', '146 else:147 prev = False148 out+=']'149 return out150def score(article, ques, data, repDF = None, thirtyDf = None, hardCodedTypes = False):151 """calculates the relevant scores for the article152 returns a tuple (question answer most chosen, units passing the threshold,153 the Unitizing Score of the users who highlighted something that passed threshold, the unitizing score154 among all users who coded the question the same way (referred to as the inclusive unitizing score),155 the percentage agreement of the category with the highest percentage agreement """156 """ Commnted code below previously denoted different types of questions for hard-coding,157 can still be used for hard-coding but eventually will be phased out by a line of code that158 checks the question_type based off the table data"""159 # ordinal_questions = [1,2,4,12,13,14,15,16,17,18,19,20,21,25]160 # nominal_questions = [7,22]161 # unit_questions = [9,10,11, 24] #asks users to highlight, nothing else OR they highlight w/ txt answer162 # multiple_questions = [3,5,8,23]163 starts = get_question_start(data,article, ques)164 ends = get_question_end(data, article, ques)165 length = get_text_length(data, article, ques)166 if len(ends)>0 and max(ends)>0:167 texts = get_answer_texts(data, article, ques)168 sourceText = makeList(length)169 sourceText = addToSourceText(starts, ends, texts, sourceText)170 hlUsers = get_question_hlUsers(data, article,ques)171 hlAns = get_question_hlAns(data, article, ques)172 else:173 sourceText = []174 hlUsers = []175 hlAns = []176 # TODO: find actual number of choices always177 num_choices = 5178 question_type = get_question_type(data, article, ques)179 if hardCodedTypes:180 schema = get_schema(data, article)181 question_type, num_choices = get_type_hard(schema, ques)182 #print("QUESTION TYPE IS", question_type)183 #This block for scoring only a single article, iuseful for debugging184 # print()185 # if article!= '171SSSArticle.txt':186 # #print(question_type)187 # if question_type == 'checklist':188 # return [189 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],190 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],191 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],192 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],193 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],194 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],195 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],196 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],197 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],198 # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]199 #200 # ]201 # return(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)202 if question_type == 'interval':203 # TODO: verify if these still exist, if they do, bring up to speed with new output formats204 return run_2step_unitization(data, article, ques, repDF)205 answers = get_question_answers(data, article, ques)206 users = get_question_userid(data, article, ques)207 print('art', article,ques)208 numUsers = get_num_users(data, article, ques)209 print('nu', numUsers, users)210 assert (len(answers) == len(users))211 if num_choices == 1:212 return 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0213 if question_type == 'ordinal':214 #assert(len(answers) == len(users))215 out = evaluateCoding(answers, users, starts, ends, numUsers, length, sourceText, hlUsers, hlAns, repDF = repDF, dfunc='ordinal', num_choices=num_choices)216 #print("ORDINAL", out[1], starts, ends)217 #do_rep_calculation_ordinal(users, answers, out[0], num_choices, out[1], hlUsers, starts, ends, length, repDF, thirtyDf)218 out = out+(question_type, num_choices)219 elif question_type == 'nominal':220 print('nominal', users)221 out = evaluateCoding(answers, users, starts, ends, numUsers, length, sourceText,hlUsers, hlAns, repDF = repDF, num_choices=num_choices)222 #do_rep_calculation_nominal(users, answers, out[0], out[1], starts, ends, length, repDF)223 #print("NOMINAL", out[1], starts, ends)224 out = out+(question_type, num_choices)225 elif question_type == 'checklist':226 out = evaluateChecklist(answers, users, starts, ends, numUsers, length, repDF, sourceText, hlUsers, hlAns, num_choices = num_choices)227 return out228def calcAgreement(codingScore, unitizingScore):229 """averages coding and unitizing agreement scores to create a final agreement score to be used elsewhere in the230 Public Editor algorithm"""231 if codingScore == 'NA':232 return unitizingScore233 elif codingScore == 'L' or codingScore == 'M' or codingScore == 'U':234 return codingScore235 elif unitizingScore == 'NA':236 return codingScore237 elif unitizingScore == 'L' or unitizingScore == 'M' or unitizingScore == 'U':238 unitizingScore = 0239 return (float(codingScore) + float(unitizingScore)) / 2240def run_2step_unitization(data, article, question, repDF):241 starts, ends, length, numUsers, users = get_question_start(data, article, question).tolist(), get_question_end(data,242 article,243 question).tolist(), \244 get_text_length(data, article, question), get_num_users(data, article,245 question), get_question_userid(246 data, article, question).tolist()247 uqU = np.unique(users)248 userWeightDict = {}249 #for u in uqU:250 #userWeightDict[u] = get_user_rep(u, repDF)251 score, indices, iScore = scoreNuUnitizing(starts, ends, length, numUsers, users, userWeightDict)252 return 'NA', indices, score, score, 'NA'253# # # TEST STUFF254#calc_agreement_directory('./demo1', hardCodedTypes= True)255# calc_scores('./demo1/Demo1ArgRel3-2018-09-01T0658-DataHuntHighlights.csv', answersFile='./demo1/Demo1ArgRel3-2018-09-01T0658-DataHuntAnswers.csv',256# schemaFile = './demo1/Demo1ArgRel3-2018-09-01T0658-Schema.csv', hardCodedTypes=True)257# calc_scores('./demo1/Demo1QuoSour-2018-09-01T0658-DataHuntHighlights.csv', answersFile='./demo1/Demo1QuoSour-2018-09-01T0658-DataHuntAnswers.csv',258# schemaFile = './demo1/Demo1QuoSour-2018-09-01T0658-Schema.csv', hardCodedTypes=True)259# calc_scores('./demo1/Demo1Prob-2018-09-01T0758-DataHuntHighlights.csv', answersFile='./demo1/Demo1Prob-2018-09-01T0758-DataHuntAnswers.csv',260# schemaFile = './demo1/Demo1Prob-2018-09-01T0758-Schema.csv', hardCodedTypes=True)261# calc_scores('./demo1/DemoLang-2018-09-01T0815-DataHuntHighlights.csv', answersFile='./demo1/DemoLang-2018-09-01T0815-DataHuntAnswers.csv',262# schemaFile = './demo1/DemoLang-2018-09-01T0815-Schema.csv', hardCodedTypes=True)263#calc_scores('testhl.csv', answersFile = 'testans.csv', schemaFile='testsch.csv', hardCodedTypes=True)264#calc_agreement_directory('demo1', hardCodedTypes=True)265#calc_scores('demo1/Demo1Prob-2018-08-28T2257-DataHuntHighlights.csv', hardCodedTypes= True)266# # calc_scores('data_pull_8_10/PreAlphaLanguage-2018-08-10T0420-DataHuntHighlights.csv', hardCodedTypes=True)267#calc_scores(path, hardCodedTypes=True)268# #in sss file I renamed the filenamecolumn to be sha256 so it fits in with the other mechanisms for extracting data269# calc_scores('data_pull_8_10/SSSPECaus2-2018-08-08T0444-DataHuntHighlights.csv', hardCodedTypes=True)270# calc_scores('data_pull_8_17/ArgumentRelevance1.0C2-2018-08-17T2012-DataHuntHighlights.csv')271# # calc_scores('data_pull_8_17/ArgumentRelevance1.0C2-2018-08-17T2012-DataHuntHighlights.csv')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful