Best Python code snippet using yandex-tank
pySummary.py
Source:pySummary.py
1"""2 @Author: Guillermo Rodriguez3 @Date: April 1, 20154 @Purpose: The purpose of this algorithm is to determine the minimum, maximum, and average for a series 5 of entries in a predetermined output file. 6"""7import sys8import argparse9import os10print("Starting Summary Calculations ......")11parser = argparse.ArgumentParser(prog='pySummary.py')12parser.add_argument('-engine', help='Search Engine [BING | GOOGLE | YAHOO]')13parser.add_argument('-file', help='Input File Name')14parse = parser.parse_args()15# --------------------------------------------------------------------------16# Global Configuration17# --------------------------------------------------------------------------18_MODE = "DEBUG"19if parse.engine and parse.file:20 _source = os.getcwd()+"\\"+parse.engine.upper()+"\\data\\"+parse.file21 22 if _MODE == "DEBUG":23 print("Engine: %s" % parse.engine)24 print("File: %s" % _source)25 _max = {'description': 0.0, 'div': 0.0, 'h1': 0.0, 'h2': 0.00, 'h3': 0.0, 'h4': 0.0, 'h5': 0.0, 'h6': 0.0, 'inbound_links': 0.0, 'keywords': 0.0, 'outbound_links': 0.0, 'p': 0.0, 'root': 0.0, 'span': 0.0, 'title': 0.0, 'quality': 0.00}26 _min = {'description': 1000.0, 'div': 1000.0, 'h1': 1000.0, 'h2': 1000.00, 'h3': 1000.0, 'h4': 1000.0, 'h5': 1000.0, 'h6': 1000.0, 'inbound_links': 1000.0, 'keywords': 1000.00, 'outbound_links': 1000.0, 'p': 1000.0, 'root': 1000.0, 'span': 1000.0, 'title': 1000.0, 'quality': 1000.00}27 _totals = {'description': 0.0, 'div': 0.0, 'h1': 0.0, 'h2': 0.00, 'h3': 0.0, 'h4': 0.0, 'h5': 0.0, 'h6': 0.0, 'inbound_links': 0.0, 'keywords': 0.0, 'outbound_links': 0.0, 'p': 0.0, 'root': 0.0, 'span': 0.0, 'title': 0.0, 'quality': 0.00}28 _lines = 029 _show_quality = False30 if os.path.exists(_source):31 with open(_source, 'r') as _file:32 for _line in _file:33 _data = _line.strip().split('\t')34 35 if len(_data) == 19 : _show_quality = True36 37 if _data[0].upper() != "INDEX":38 _lines += 139 # Totals40 _totals['description'] = float(_data[3]) 41 _totals['div'] += float(_data[4])42 _totals['h1'] += float(_data[5])43 _totals['h2'] += float(_data[6])44 _totals['h3'] += float(_data[7])45 _totals['h4'] += float(_data[8])46 _totals['h5'] += float(_data[9])47 _totals['h6'] += float(_data[10])48 _totals['inbound_links'] += float(_data[11])49 _totals['keywords'] += float(_data[12])50 _totals['outbound_links'] += float(_data[13])51 _totals['p'] += float(_data[14])52 _totals['root'] += float(_data[15])53 _totals['span'] += float(_data[16])54 _totals['title'] += float(_data[17])55 56 if len(_data) == 19: _totals['quality'] += float(_data[18])57 58 # Maximum59 if float(_data[3]) > _max['description']: _max['description'] = float(_data[3])60 if float(_data[4]) > _max['div']: _max['div'] = float(_data[4])61 if float(_data[5]) > _max['h1']: _max['h1'] = float(_data[5])62 if float(_data[6]) > _max['h2']: _max['h2'] = float(_data[6])63 if float(_data[7]) > _max['h3']: _max['h3'] = float(_data[7])64 if float(_data[8]) > _max['h4']: _max['h4'] = float(_data[8])65 if float(_data[9]) > _max['h5']: _max['h5'] = float(_data[9])66 if float(_data[10]) > _max['h6']: _max['h6'] = float(_data[10])67 if float(_data[11]) > _max['inbound_links']: _max['inbound_links'] = float(_data[11])68 if float(_data[12]) > _max['keywords']: _max['keywords'] = float(_data[12])69 if float(_data[13]) > _max['outbound_links']: _max['outbound_links'] = float(_data[13])70 if float(_data[14]) > _max['p']: _max['p'] = float(_data[14])71 if float(_data[15]) > _max['root']: _max['root'] = float(_data[15])72 if float(_data[16]) > _max['span']: _max['span'] = float(_data[16])73 if float(_data[17]) > _max['title']: _max['title'] = float(_data[17])74 if ( len(_data) == 19 ) and ( float(_data[18]) > _max['quality'] ): _max['quality'] = float(_data[18])75 76 # Minimum77 if float(_data[3]) < _min['description']: _min['description'] = float(_data[3])78 if float(_data[4]) < _min['div']: _min['div'] = float(_data[4])79 if float(_data[5]) < _min['h1']: _min['h1'] = float(_data[5])80 if float(_data[6]) < _min['h2']: _min['h2'] = float(_data[6])81 if float(_data[7]) < _min['h3']: _min['h3'] = float(_data[7])82 if float(_data[8]) < _min['h4']: _min['h4'] = float(_data[8])83 if float(_data[9]) < _min['h5']: _min['h5'] = float(_data[9])84 if float(_data[10]) < _min['h6']: _min['h6'] = float(_data[10])85 if float(_data[11]) < _min['inbound_links']: _min['inbound_links'] = float(_data[11])86 if float(_data[12]) < _min['keywords']: _min['keywords'] = float(_data[12])87 if float(_data[13]) < _min['outbound_links']: _min['outbound_links'] = float(_data[13])88 if float(_data[14]) < _min['p']: _min['p'] = float(_data[14])89 if float(_data[15]) < _min['root']: _min['root'] = float(_data[15])90 if float(_data[16]) < _min['span']: _min['span'] = float(_data[16])91 if float(_data[17]) < _min['title']: _min['title'] = float(_data[17])92 if ( len(_data) == 19 ) and ( float( _data[18] ) < _min['quality'] ): _min['quality'] = float(_data[18])93 else:94 print("Invalid Input File Specified")95 96 if( not _show_quality ): 97 _max.pop('quality', None)98 _min.pop('quality', None)99 _totals.pop('quality', None)100 101 print("MAXIMUM ---------------------------") 102 print(_max)103 print("MINIMUM ---------------------------")104 print(_min)105 print("AVERAGE ---------------------------")106 for key, value in _totals.items():107 _totals[key] = float(value)/_lines108 print(_totals)109else:110 parser.print_help()...
largestRectangleArea.py
Source:largestRectangleArea.py
1from datetime import datetime, time2import heapq3import math4class Solution:5 def largestRectangleArea1(self, h) -> int:6 if h == []:7 return 08 _max = 09 stack = []10 for i in range(len(h)):11 x = h[i]12 if not stack or h[stack[-1]] <= x:13 stack.append(i)14 continue15 n = len(stack)16 for k in range(n):17 _max = max(_max, h[stack[k]] * (i - stack[k]))18 j = n19 while j > 0 and h[stack[j - 1]] >= x:20 j -= 121 del stack[j + 1:]22 h[stack[-1]] = x23 for k in range(len(stack)):24 _max = max(_max, h[stack[k]] * (len(h) - stack[k]))25 return _max26 def largestRectangleArea2(self, heights) -> int:27 if heights == []:28 return 029 _max = 030 stack = []31 for i in range(len(heights)):32 x = heights[i]33 while stack and heights[stack[-1]] >= x:34 h = heights[stack.pop()]35 w = i if not stack else i - stack[-1] - 136 _max = max(_max, h * w)37 stack.append(i)38 n = len(heights)39 while stack:40 h = heights[stack.pop()]41 w = n if not stack else n - stack[-1] - 142 _max = max(_max, h * w)43 return _max44 def largestRectangleArea3(self, heights) -> int:45 if heights == []:46 return 047 _max = 048 stack = []49 for i in range(len(heights)):50 x = heights[i]51 while stack and heights[stack[-1]] > x:52 h = heights[stack.pop()]53 w = i if not stack else i - stack[-1] - 154 _max = max(_max, h * w)55 stack.append(i)56 n = len(heights)57 pre = -158 for i in range(len(stack)):59 h = heights[stack[i]]60 if h == 0:61 pre = stack[i]62 continue63 _max = max(_max, h * (n - (pre + 1)))64 pre = stack[i]65 return _max66 def largestRectangleArea(self, heights) -> int:67 if not heights:68 return 069 heights.append(0)70 _max = 071 stack = []72 for i in range(len(heights)):73 x = heights[i]74 while stack and heights[stack[-1]] >= x:75 h = heights[stack.pop()]76 w = i if not stack else i - stack[-1] - 177 _max = max(_max, h * w)78 stack.append(i)79 return _max80s = Solution()81startTime = datetime.now()82print(s.largestRectangleArea([3, 1, 4, 5, 3, 2, 7, 5, 3]))...
14500.py
Source:14500.py
1n, m = map(int, input().split())2pan = [list(map(int, input().split())) for _ in range(n)]3_max = 04# ì¼ìë§ë5for i in range(n):6 for j in range(m - 3):7 _max = max(_max, pan[i][j] + pan[i][j + 1] + pan[i][j + 2] + pan[i][j + 3])8for i in range(n - 3):9 for j in range(m):10 _max = max(_max, pan[i][j] + pan[i + 1][j] + pan[i + 2][j] + pan[i + 3][j])11 12# ë¤ëª¨13for i in range(n - 1):14 for j in range(m - 1):15 _max = max(_max, pan[i][j] + pan[i][j + 1] + pan[i + 1][j] + pan[i + 1][j + 1])16# ã´17for i in range(n - 1):18 for j in range(m - 2):19 _max = max(_max, pan[i][j] + pan[i][j + 1] + pan[i][j + 2] + pan[i + 1][j + 2])20 _max = max(_max, pan[i][j] + pan[i][j + 1] + pan[i][j + 2] + pan[i + 1][j])21 _max = max(_max, pan[i + 1][j] + pan[i + 1][j + 1] + pan[i + 1][j + 2] + pan[i][j + 2])22 _max = max(_max, pan[i + 1][j] + pan[i + 1][j + 1] + pan[i + 1][j + 2] + pan[i][j])23for i in range(n - 2):24 for j in range(m - 1):25 _max = max(_max, pan[i][j] + pan[i + 1][j] + pan[i + 2][j] + pan[i + 2][j + 1])26 _max = max(_max, pan[i][j] + pan[i + 1][j] + pan[i + 2][j] + pan[i][j + 1])27 _max = max(_max, pan[i][j + 1] + pan[i + 1][j + 1] + pan[i + 2][j + 1] + pan[i + 2][j])28 _max = max(_max, pan[i][j + 1] + pan[i + 1][j + 1] + pan[i + 2][j + 1] + pan[i][j])29# ì§ê·¸30for i in range(n - 1):31 for j in range(m - 2):32 _max = max(_max, pan[i][j] + pan[i][j + 1] + pan[i + 1][j + 1] + pan[i + 1][j + 2])33 _max = max(_max, pan[i + 1][j] + pan[i + 1][j + 1] + pan[i][j + 1] + pan[i][j + 2])34for i in range(n - 2):35 for j in range(m - 1):36 _max = max(_max, pan[i][j]+ pan[i+1][j]+pan[i+1][j+1]+pan[i+2][j+1])37 _max = max(_max, pan[i][j+1]+ pan[i+1][j]+pan[i+1][j+1]+pan[i+2][j])38# íì´í39for i in range(n - 1):40 for j in range(m - 2):41 _max = max(_max, pan[i][j] + pan[i][j + 1] + pan[i][j + 2] + pan[i + 1][j + 1])42 _max = max(_max, pan[i + 1][j] + pan[i + 1][j + 1] + pan[i + 1][j + 2] + pan[i][j + 1])43for i in range(n - 2):44 for j in range(m - 1):45 _max = max(_max, pan[i][j] + pan[i + 1][j] + pan[i + 2][j] + pan[i + 1][j + 1])46 _max = max(_max, pan[i][j + 1] + pan[i + 1][j + 1] + pan[i + 2][j + 1] + pan[i+1][j])47 ...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!