def __save_metric_long_history(cls, metric, report_dir): filename = report_dir / 'json' / '{stable_id}.txt'.format( stable_id=metric.normalized_stable_id()) filesystem.write_file(",".join( str(i) if i is not None else '' for i in metric.long_history()), filename, mode='w', encoding=None)
def __create_resources(report_dir): """ Create and write the resources. """ resource_manager = pkg_resources.ResourceManager() resource_module = app.__name__ for resource_type, encoding in (('img', None), ('dist', None), ('html', 'utf-8')): resource_dir = (report_dir / resource_type) if resource_type != 'html' else report_dir filesystem.create_dir(resource_dir) for resource in resource_manager.resource_listdir(resource_module, resource_type): filename = resource_dir / resource contents = resource_manager.resource_string(resource_module, resource_type + '/' + resource) mode = 'w' if encoding else 'wb' contents = contents.decode(encoding) if encoding else contents filesystem.write_file(contents, filename, mode, encoding)
def __create_trend_images(cls, quality_report, report_dir): """ Retrieve and write the trend images. """ style = pygal.style.Style(background='transparent', plot_background='transparent') dates = '' filesystem.create_dir(report_dir / 'chart') for metric in quality_report.metrics(): line_chart = pygal.Line(style=style, range=metric.y_axis_range()) line_chart.add('', metric.recent_history(), stroke_style={'width': 2}) image = line_chart.render_sparkline() filename = report_dir / 'chart' / '{0!s}.svg'.format(metric.id_string()) filesystem.write_file(image, filename, mode='wb', encoding=None) cls.__save_metric_long_history(metric, report_dir) if not dates: dates = metric.get_long_history_dates() filename = report_dir / 'json' / 'dates.txt' filesystem.write_file(dates, filename, mode='w', encoding=None)
def __format_and_write_report(quality_report, report_formatter, filename, mode, encoding, **kwargs): """ Format the report using the formatter and write it to the specified file. """ formatted_report = report_formatter(**kwargs).process(quality_report) filesystem.write_file(formatted_report, filename, mode, encoding)
def __format_and_write_report(quality_report, report_formatter, filename, mode, encoding, **kwargs): """ Format the report using the formatter and write it to the specified file. """ formatted_report = report_formatter(**kwargs).process(quality_report) filesystem.write_file(formatted_report, filename, mode, encoding)
def __save_metric_long_history(cls, metric, report_dir): filename = report_dir / 'json' / '{stable_id}.txt'.format(stable_id=metric.normalized_stable_id()) filesystem.write_file(",".join(str(i) if i is not None else '' for i in metric.long_history()), filename, mode='w', encoding=None)