How to use _get_hostnames_in_bucket method in autotest

Best Python code snippet using autotest_python

graphing_utils.py

Source: graphing_utils.py Github

copy

Full Screen

...528 plot_info = MetricsPlot(query_dict, plot_type, inverted_series,529 normalize_to, drilldown_callback)530 figure, area_data = _create_metrics_plot_helper(plot_info, extra_text)531 return _create_image_html(figure, area_data, plot_info)532def _get_hostnames_in_bucket(hist_data, bucket):533 """\534 Get all the hostnames that constitute a particular bucket in the histogram.535 hist_data: list containing tuples of (hostname, pass_rate)536 bucket: tuple containing the (low, high) values of the target bucket537 """538 return [hostname for hostname, pass_rate in hist_data539 if bucket[0] <= pass_rate < bucket[1]]540def _create_qual_histogram_helper(plot_info, extra_text=None):541 """\542 Create a machine qualification histogram of the given data.543 plot_info: a QualificationHistogram544 extra_text: text to show at the upper-left of the graph545 TODO(showard): move much or all of this into methods on546 QualificationHistogram547 """548 cursor = readonly_connection.cursor()549 cursor.execute(plot_info.query)550 if not cursor.rowcount:551 raise NoDataError('query did not return any data')552 # Lists to store the plot data.553 # hist_data store tuples of (hostname, pass_rate) for machines that have554 # pass rates between 0 and 100%, exclusive.555 # no_tests is a list of machines that have run none of the selected tests556 # no_pass is a list of machines with 0% pass rate557 # perfect is a list of machines with a 100% pass rate558 hist_data = []559 no_tests = []560 no_pass = []561 perfect = []562 # Construct the lists of data to plot563 for hostname, total, good in cursor.fetchall():564 if total == 0:565 no_tests.append(hostname)566 continue567 if good == 0:568 no_pass.append(hostname)569 elif good == total:570 perfect.append(hostname)571 else:572 percentage = 100.0 * good /​ total573 hist_data.append((hostname, percentage))574 interval = plot_info.interval575 bins = range(0, 100, interval)576 if bins[-1] != 100:577 bins.append(bins[-1] + interval)578 figure, height = _create_figure(_SINGLE_PLOT_HEIGHT)579 subplot = figure.add_subplot(1, 1, 1)580 # Plot the data and get all the bars plotted581 _,_, bars = subplot.hist([data[1] for data in hist_data],582 bins=bins, align='left')583 bars += subplot.bar([-interval], len(no_pass),584 width=interval, align='center')585 bars += subplot.bar([bins[-1]], len(perfect),586 width=interval, align='center')587 bars += subplot.bar([-3 * interval], len(no_tests),588 width=interval, align='center')589 buckets = [(bin, min(bin + interval, 100)) for bin in bins[:-1]]590 # set the x-axis range to cover all the normal bins plus the three "special"591 # ones - N/​A (3 intervals left), 0% (1 interval left) ,and 100% (far right)592 subplot.set_xlim(-4 * interval, bins[-1] + interval)593 subplot.set_xticks([-3 * interval, -interval] + bins + [100 + interval])594 subplot.set_xticklabels(['N/​A', '0%'] +595 ['%d%% - <%d%%' % bucket for bucket in buckets] +596 ['100%'], rotation=90, size='small')597 # Find the coordinates on the image for each bar598 x = []599 y = []600 for bar in bars:601 x.append(bar.get_x())602 y.append(bar.get_height())603 f = subplot.plot(x, y, linestyle='None')[0]604 upper_left_coords = f.get_transform().transform(zip(x, y))605 bottom_right_coords = f.get_transform().transform(606 [(x_val + interval, 0) for x_val in x])607 # Set the title attributes608 titles = ['%d%% - <%d%%: %d machines' % (bucket[0], bucket[1], y_val)609 for bucket, y_val in zip(buckets, y)]610 titles.append('0%%: %d machines' % len(no_pass))611 titles.append('100%%: %d machines' % len(perfect))612 titles.append('N/​A: %d machines' % len(no_tests))613 # Get the hostnames for each bucket in the histogram614 names_list = [_get_hostnames_in_bucket(hist_data, bucket)615 for bucket in buckets]616 names_list += [no_pass, perfect]617 if plot_info.filter_string:618 plot_info.filter_string += ' AND '619 # Construct the list of drilldown parameters to be passed when the user620 # clicks on the bar.621 params = []622 for names in names_list:623 if names:624 hostnames = ','.join(_quote(hostname) for hostname in names)625 hostname_filter = 'hostname IN (%s)' % hostnames626 full_filter = plot_info.filter_string + hostname_filter627 params.append({'type': 'normal',628 'filterString': full_filter})...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Scala Testing: A Comprehensive Guide

Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.

What Agile Testing (Actually) Is

So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.

How To Choose The Right Mobile App Testing Tools

Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools

A Complete Guide To CSS Houdini

As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????

Appium Testing Tutorial For Mobile Applications

The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.

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 autotest 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