def prepare_series(self, result_dir=None): """ Extract all series from the respective benchmark files and append them to the series file. """ if result_dir is None: result_dir = self.result_dir output = {} output['title'] = self.title output['x'] = self.argx output['y'] = self.argy output['common_params'] = {} output['series'] = [] common = None for series in self.series_in: idfile = os.path.join(result_dir, 'benchmark_' + str(series['id']) + '.json') try: rows = json_from_file(idfile)['json'] except FileNotFoundError: print(SKIP_NO_FILE_MSG.format(idfile)) continue # If it is dict() it indicates a mix workload consisting of # two parts: 'read' and 'write'. In this case, the series # has to provide 'rw_dir' to pick one of them. if isinstance(rows, dict): rw_dir = series['rw_dir'] rows = rows[rw_dir] if not rows: print(SKIP_NO_ROWS_MSG.format(series['id'])) continue # it is assumed each row has the same names of columns keys = rows[0].keys() # skip the series if it does not have required keys if self.argx not in keys: print(SKIP_NO_AXIS_MSG.format( self.argx, series['id'], str(keys))) continue if self.argy not in keys: print(SKIP_NO_AXIS_MSG.format( self.argy, series['id'], str(keys))) continue points = [[row[self.argx], row[self.argy]] for row in rows] common = Figure._get_common_params(common, rows) output['series'].append( {'label': series['label'], 'points': points}) output['common_params'] = {} if common is None else common # save the series to a file series_path = self._series_file(result_dir) if os.path.exists(series_path): figures = json_from_file(series_path)['json'] else: figures = {} figures[self.key] = output with open(series_path, 'w', encoding='utf-8') as file: json.dump(figures, file, indent=4) # mark as done self.output['done'] = True self.series = output['series'] self.common_params = output['common_params']
def prepare_series(self) -> None: """prepare JSON files with picked results for the comparison Loop over all provided `benches` in order to generate all defined figures. For a given figure all the `lib.bench.Bench` objects are browsed in order to find all occurrences of the figure. All occurrences of the figure are compiled into a single figure combining all series from all figures prepended with names of the respective `lib.bench.Bench` (`names`). e.g. - Consider a figure composed of three series: A, B and C and - the figure exists in two `lib.bench.Bench` instances named: Alfa and Beta. - The resulting figure will be have the following series: - `Alfa A`, `Alfa B`, `Alfa C` and - `Beta A`, `Beta B`, `Beta C`. """ if os.path.isfile(self.__series_file()): output = json_from_file(self.__series_file())['json'] else: output = {} keycontent = self.__merge() output[self.__figure.key] = keycontent with open(self.__series_file(), 'w', encoding='utf-8') as file: json.dump(output, file, indent=4)
def create_tables(self) -> str: """Generate an image and a table of results.""" data = json_from_file(self.__series_file())['json'] keycontent = data.get(self.__figure.key) file_name = self.file_name() table = '<img src="' + self.png_path() + '" alt="' + file_name + '"/>' table += data_table(keycontent['series'], True) return table
def to_pngs(self): """generate all PNG files""" os.chdir(self._compare._result_dir) data = json_from_file(self._series_file())['json'] keycontent = data.get(self._figure.key) output_path = self.png_path() # XXX add setters to yaxis_max for bw and lat Figure.draw_png(keycontent['x'], keycontent['y'], keycontent['series'], keycontent['xscale'], output_path, None, None, None)
def prepare_series(self): """prepare JSON files with picked results for the comparison""" if os.path.isfile(self._series_file()): output = json_from_file(self._series_file())['json'] else: output = {} keycontent = self._merge() output[self._figure.key] = keycontent with open(self._series_file(), 'w', encoding='utf-8') as file: json.dump(output, file, indent=4)
def to_pngs(self) -> None: """generate all PNG files Please see `lib.figure.image.draw_png()`. """ os.chdir(self.__compare.result_dir) data = json_from_file(self.__series_file())['json'] keycontent = data.get(self.__figure.key) output_path = self.png_path() # XXX add setters to yaxis_max for bw and lat draw_png(keycontent['x'], keycontent['y'], keycontent['series'], keycontent['xscale'], output_path, None, None, keycontent['title'])
def __init__(self, f, result_dir=""): self.output = f['output'] self.output['done'] = self.output.get('done', False) # copies for convenience self.title = self.output['title'] self.file = self.output['file'] self.argx = self.output['x'] self.argy = self.output['y'] self.yaxis_max = None self.key = self.output['key'] self.xscale = self.output.get('xscale', 'log') self.result_dir = result_dir self.series_in = f['series'] if self.output['done']: data = json_from_file(self._series_file(result_dir)) self.series = data['json'][self.key]['series'] self.common_params = data['json'][self.key].get('common_params', {})