Best Python code snippet using autotest_python
graphing_utils.py
Source:graphing_utils.py
...397 for index, plot in enumerate(plots):398 if plot['label'] == label:399 return index400 raise ValueError('no plot labeled "%s" found' % label)401def _normalize_to_series(plots, base_series):402 base_series_index = _find_plot_by_label(plots, base_series)403 base_plot = plots[base_series_index]404 base_xs = base_plot['x']405 base_values = base_plot['y']406 base_errors = base_plot['errors']407 del plots[base_series_index]408 for plot in plots:409 old_xs, old_values, old_errors = plot['x'], plot['y'], plot['errors']410 new_xs, new_values, new_errors = [], [], []411 new_base_values, new_base_errors = [], []412 # Select only points in the to-be-normalized data that have a413 # corresponding baseline value414 for index, x_value in enumerate(old_xs):415 try:416 base_index = base_xs.index(x_value)417 except ValueError:418 continue419 new_xs.append(x_value)420 new_values.append(old_values[index])421 new_base_values.append(base_values[base_index])422 if old_errors:423 new_errors.append(old_errors[index])424 new_base_errors.append(base_errors[base_index])425 if not new_xs:426 raise NoDataError('No normalizable data for series ' +427 plot['label'])428 plot['x'] = new_xs429 plot['y'] = new_values430 if old_errors:431 plot['errors'] = new_errors432 plot['y'], plot['errors'] = _normalize(plot['y'], plot['errors'],433 new_base_values,434 new_base_errors)435def _create_metrics_plot_helper(plot_info, extra_text=None):436 """437 Create a metrics plot of the given plot data.438 plot_info: a MetricsPlot object.439 extra_text: text to show at the uppper-left of the graph440 TODO(showard): move some/all of this logic into methods on MetricsPlot441 """442 query = plot_info.query_dict['__main__']443 cursor = readonly_connection.cursor()444 cursor.execute(query)445 if not cursor.rowcount:446 raise NoDataError('query did not return any data')447 rows = cursor.fetchall()448 # "transpose" rows, so columns[0] is all the values from the first column,449 # etc.450 columns = zip(*rows)451 plots = []452 labels = [str(label) for label in columns[0]]453 needs_resort = (cursor.description[0][0] == 'kernel')454 # Collect all the data for the plot455 col = 1456 while col < len(cursor.description):457 y = columns[col]458 label = cursor.description[col][0]459 col += 1460 if (col < len(cursor.description) and461 'errors-' + label == cursor.description[col][0]):462 errors = columns[col]463 col += 1464 else:465 errors = None466 if needs_resort:467 y = _resort(labels, y)468 if errors:469 errors = _resort(labels, errors)470 x = [index for index, value in enumerate(y) if value is not None]471 if not x:472 raise NoDataError('No data for series ' + label)473 y = [y[i] for i in x]474 if errors:475 errors = [errors[i] for i in x]476 plots.append({477 'label': label,478 'x': x,479 'y': y,480 'errors': errors481 })482 if needs_resort:483 labels = _resort(labels, labels)484 # Normalize the data if necessary485 normalize_to = plot_info.normalize_to486 if normalize_to == 'first' or normalize_to.startswith('x__'):487 if normalize_to != 'first':488 baseline = normalize_to[3:]489 try:490 baseline_index = labels.index(baseline)491 except ValueError:492 raise ValidationError({493 'Normalize' : 'Invalid baseline %s' % baseline494 })495 for plot in plots:496 if normalize_to == 'first':497 plot_index = 0498 else:499 try:500 plot_index = plot['x'].index(baseline_index)501 # if the value is not found, then we cannot normalize502 except ValueError:503 raise ValidationError({504 'Normalize' : ('%s does not have a value for %s'505 % (plot['label'], normalize_to[3:]))506 })507 base_values = [plot['y'][plot_index]] * len(plot['y'])508 if plot['errors']:509 base_errors = [plot['errors'][plot_index]] * len(plot['errors'])510 plot['y'], plot['errors'] = _normalize(plot['y'], plot['errors'],511 base_values,512 None or base_errors)513 elif normalize_to.startswith('series__'):514 base_series = normalize_to[8:]515 _normalize_to_series(plots, base_series)516 # Call the appropriate function to draw the line or bar plot517 if plot_info.is_line:518 figure, area_data = _create_line(plots, labels, plot_info)519 else:520 figure, area_data = _create_bar(plots, labels, plot_info)521 # TODO(showard): extract these magic numbers to named constants522 if extra_text:523 text_y = .95 - .0075 * len(plots)524 figure.text(.1, text_y, extra_text, size='xx-small')525 return (figure, area_data)526def create_metrics_plot(query_dict, plot_type, inverted_series, normalize_to,527 drilldown_callback, extra_text=None):528 plot_info = MetricsPlot(query_dict, plot_type, inverted_series,529 normalize_to, drilldown_callback)...
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!!