How to use __calc_percentiles method in yandex-tank

Best Python code snippet using yandex-tank

screen.py

Source:screen.py Github

copy

Full Screen

...563 for second in tuple(self.last_min.keys()):564 if ts - second > 60:565 self.last_min.pop(second)566 self.last_min[ts] = dist567 def __calc_percentiles(self):568 def hist_to_quant(histogram, quant):569 cumulative = histogram.cumsum()570 total = cumulative.max()571 positions = cumulative.searchsorted([float(i) / 100 * total for i in quant])572 quant_times = [cumulative.index[i] / 1000. for i in positions]573 return quant_times574 all_times = hist_to_quant(self.overall, self.quantiles)575 last_data = self.last_min[max(self.last_min.keys())]576 last_times = hist_to_quant(last_data, self.quantiles)577 # Check if we have precise data for last second quantiles instead of binned histogram578 for position, q in enumerate(self.quantiles):579 if q in self.precise_quantiles:580 last_times[position] = self.precise_quantiles[q]581 # Replace binned values with precise, if lower quantile bin happens to be582 # greater than upper quantile precise values583 for position in reversed(range(1, len(last_times))):584 if last_times[position - 1] > last_times[position]:585 last_times[position - 1] = last_times[position]586 last_1m = pd.Series()587 for ts, data in self.last_min.items():588 if last_1m.empty:589 last_1m = data590 else:591 last_1m = last_1m.add(data, fill_value=0)592 last_1m_times = hist_to_quant(last_1m, self.quantiles)593 quant_times = reversed(594 list(zip(self.quantiles, all_times, last_1m_times, last_times))595 )596 data = []597 for q, all_time, last_1m, last_time in quant_times:598 data.append({599 'quantile': q,600 'all': all_time,601 'last_1m': last_1m,602 'last': last_time603 })604 return data605 def render(self, expected_width=None):606 prepared = [(self.screen.markup.WHITE, self.title)]607 if self.overall is None:608 prepared.append(('',))609 else:610 data = self.__calc_percentiles()611 prepared += self.formatter.render_table(data, ['quantile', 'all', 'last_1m', 'last'])612 self.width, self.lines = self.fill_rectangle(prepared)613class CurrentHTTPBlock(AbstractBlock):614 ''' Http codes with highlight'''615 def __init__(self, screen):616 AbstractBlock.__init__(self, screen)617 self.overall_dist = defaultdict(int)618 self.title = 'HTTP codes: '619 self.total_count = 0620 template = {621 'count': {'tpl': '{:>,}'}, # noqa: E241622 'last': {'tpl': '+{:>,}'}, # noqa: E241623 'percent': {'tpl': '{:>.2f}%'}, # noqa: E241624 'code': {'tpl': '{:>3}', 'final': '{{{:}:<{len}}}'}, # noqa: E241...

Full Screen

Full Screen

generation.py

Source:generation.py Github

copy

Full Screen

...31 else:32 for (i, j), x in np.ndenumerate(self.heightmap):33 self.heightmap[i][j] = x / mx34 return self35 def __calc_percentiles(self):36 """Converts each value in the heightmap to the largest percentile in which it37 still lies. If values are the same, they are assigned the same percentile.38 """39 arr_as_srtd_lst = sorted(list(np.ndenumerate(self.heightmap)),40 key=lambda x: x[1])41 last_percentile = None42 last_value = None43 for (k, ((i, j), v)) in enumerate(arr_as_srtd_lst):44 curr_percentile = (k + 1.0) / len(arr_as_srtd_lst)45 if v == last_value:46 curr_percentile = last_percentile47 self.heightmap[i][j] = curr_percentile48 last_percentile = curr_percentile49 last_value = v50 return self51 def __calc_groups(self):52 """Maps normalized tile values to groups. A group is a number indicating between53 which thresholds a value lies. The groups can later easily be mapped to54 color maps by a visualization strategy.55 """56 thresholds = self.config['thresholds']57 if thresholds is None:58 raise Exception("The config parameter 'thresholds' must be set.")59 for ((i, j), x) in np.ndenumerate(self.heightmap):60 groupFound = False61 for k, t in enumerate(thresholds):62 if x < t:63 self.heightmap[i][j] = k64 groupFound = True65 break66 if not groupFound:67 # assign to last group68 self.heightmap[i][j] = len(thresholds)69 return self70 @staticmethod71 def __get_neighbors(pt, shape):72 """Get all neighbours for the given point pt. This function is used by the73 erosion filter. At most 8 neighbors are returned. The second parameter74 denotes the shape of the heightmap (i.e. width and height).75 """76 x, y = pt77 w, h = shape78 neighbors = [((x - 1, y), 1), ((x - 1, y - 1), 1), ((x - 1, y + 1), 1),79 ((x, y), 2), ((x, y - 1), 1), ((x, y + 1), 1),80 ((x + 1, y), 1), ((x + 1, y - 1), 1), ((x + 1, y + 1), 1)]81 return [((a, b), wt) for ((a, b), wt) in neighbors if 0 <= a < w and b >= 0 and b < h]82 def __smooth(self):83 """Erosion filter. This filter reduces some of the noise from the generated data.84 After applying it, it is unlikely for tiles of high and low height to be85 adjacent.86 """87 if 'erosion' in self.config:88 for m in range(self.config['erosion']):89 hm_copy = np.copy(self.heightmap)90 for i in range(self.width):91 for j in range(self.height):92 neighbors = self.__get_neighbors((i, j),93 (self.width, self.height))94 vals = [self.heightmap[k][l] * w for ((k, l), w) in neighbors]95 sum_weights = sum([w for ((k, l), w) in neighbors])96 hm_copy[i][j] = round(sum(vals) / (sum_weights))97 self.heightmap = hm_copy98 return self99 def generate(self):100 """Generates height data by calling generate_raw() which should be overridden by101 all subclasses. Afterwards, a normalization is performed and finally each102 normalized value is mapped to a group.103 """104 return self._generate_raw().__calc_percentiles().__calc_groups().__smooth()105class RandomStrategy(GenerationStrategy):106 """Simple height map generation strategy: Uses uniformly distributed random values107 for each tile.108 """109 def _generate_raw(self):110 """Creates height map of random values.111 """112 self.heightmap = np.random.rand(self.width, self.height)113 return self114class LinearFaultStrategy(GenerationStrategy):115 """Generates a random height map by using the "fault" algorithm. This algorithm116 iteratively creates random straights and increases the height for all117 points either below or above the straight. Which side is increased is also118 decided randomly....

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 yandex-tank 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