def create_packages(path): pip_freeze_path = path / 'pip_freeze.txt' with pip_freeze_path.open() as fp: pip_freeze = fp.read() return html_utils.monospace(pip_freeze)
def create_short_output(path, uuid): filepath = path / 'stdcombined.txt' output = '' output_truncated = False with filepath.open() as fp: for i, line in enumerate(fp): if i >= MAX_CHARS_IN_SHORT_OUTPUT: output_truncated = True break output += line output = cgi.escape(output) html = html_utils.monospace(output) if output_truncated: html += ''' <button id="show-all-output" class="btn btn-outline-primary" style="width: 120px;">Show all</button> <script> $('#show-all-output').click(function() {{ var promise = $.get('/load_all_output/{uuid}'); promise.done(function(result) {{ $("#experiment-output").html(result); }}); }}); </script> '''.format(uuid=uuid) html = '<div id="experiment-output">{}</div>'.format(html) return html
def create_output(path): filepath = path / 'stdcombined.txt' with filepath.open() as fp: output = fp.read() return html_utils.monospace(output)
def create_summary(uuid, path, experiment_json): columns = ['Name', 'Value'] status = experiment_json['status'] start = datetime.datetime.strptime(experiment_json['startedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") end = None if experiment_json[ 'endedDatetime'] is None else datetime.datetime.strptime( experiment_json['endedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") if end is None: duration = datetime.datetime.now() - start else: duration = end - start duration = utils.floor_timedelta(duration) tags = sorted(experiment_json['tags']) parents = get_parents(experiment_json) exception = None if experiment_json['exceptionType'] is not None: exception = '{}: {}'.format(experiment_json['exceptionType'], experiment_json['exceptionValue']) items = [ ('Status', html_utils.get_status_icon_tag(status) + ' ' + status), ('ID', html_utils.monospace(uuid)), ('Title<br><br><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#titleModal">Edit</button>', '<div id="title-div">{}</div>'.format(cgi.escape(experiment_json['title']))), (same_line('<i class="fas fa-info-circle"></i> Description') \ + '<br><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#descriptionModal">Edit</button>', '<div id="description-div"></div>'), (same_line('<i class="fas fa-lightbulb"></i> Conclusion') \ + '<br><button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#conclusionModal">Edit</button>', '<div id="conclusion-div"></div>'), ('Filename', html_utils.color_circle_and_string(experiment_json['filename'])), ('Duration', str(duration)), ('Start', start.strftime('%Y-%m-%d %H:%M:%S')), ('End', end.strftime('%Y-%m-%d %H:%M:%S') if end is not None else None), ('Tags', ' '.join([html_utils.badge(tag) for tag in tags])), ('Arguments', html_utils.monospace(utils.arguments_to_string(experiment_json['arguments']))), ('Name', experiment_json['name']), ('File space', utils.get_file_space_representation(str(path/c.FILES_FOLDER))), ('Parents', html_utils.monospace(' '.join(parents))), ('Exception', html_utils.monospace(exception) if exception is not None else None), ('Git commit', html_utils.monospace(html_utils.color_circle_and_string(experiment_json['git']['short'])) if experiment_json['git'] is not None else None), ('PID', html_utils.monospace(experiment_json['pid'])), ('Python version', experiment_json['pythonVersion']), ('OS', experiment_json['osVersion']), ] item_by_column_list = [{ 'Name': name, 'Value': value } for name, value in items] html = html_utils.create_table(columns, item_by_column_list, id='summary-table', attrs=[[], [('style', 'width: 100%;')]]) html += create_modal_html(uuid, experiment_json) return html
def create_summary(uuid, path, experiment_json): doc, tag, text = Doc().tagtext() columns = ['Name', 'Value'] status = experiment_json['status'] start = datetime.datetime.strptime(experiment_json['startedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") end = None if experiment_json[ 'endedDatetime'] is None else datetime.datetime.strptime( experiment_json['endedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") if end is None: duration = datetime.datetime.now() - start else: duration = end - start duration = utils.floor_timedelta(duration) tags = sorted(experiment_json['tags']) parents = get_parents(experiment_json) exception = None if experiment_json['exceptionType'] is not None: exception = '{}: {}'.format(experiment_json['exceptionType'], experiment_json['exceptionValue']) items = [ ('Status', html_utils.get_status_icon_tag(status) + ' ' + status), ('Name', experiment_json['name']), ('ID', html_utils.monospace(uuid)), ('Title', experiment_json['title']), ('Filename', html_utils.color_circle_and_string(experiment_json['filename'])), ('Duration', str(duration)), ('Start', start.strftime('%Y-%m-%d %H:%M:%S')), ('End', end.strftime('%Y-%m-%d %H:%M:%S') if end is not None else None), ('Tags', ' '.join([html_utils.badge(tag) for tag in tags])), ('Arguments', html_utils.monospace(' '.join(experiment_json['arguments']))), ('File space', utils.get_file_space_representation(str(path / c.FILES_FOLDER))), ('Parents', html_utils.monospace(' '.join(parents))), ('Exception', html_utils.monospace(exception) if exception is not None else None), ('Git commit', html_utils.monospace( html_utils.color_circle_and_string( experiment_json['git']['short'])) if experiment_json['git'] is not None else None), ('PID', html_utils.monospace(experiment_json['pid'])), ('Python version', experiment_json['pythonVersion']), ('OS', experiment_json['osVersion']), ] item_by_column_list = [{ 'Name': name, 'Value': value } for name, value in items] return html_utils.create_table(columns, item_by_column_list, id='summary-table', attrs=[[], [('style', 'width: 100%;')]])
def create_procedure_item_by_column(uuid, path, metadata, all_scalars, all_params): name = metadata['name'] start = datetime.datetime.strptime(metadata['startedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") end = None if metadata[ 'endedDatetime'] is None else datetime.datetime.strptime( metadata['endedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") if end is None: duration = datetime.datetime.now() - start else: duration = end - start duration = utils.floor_timedelta(duration) status = metadata['status'] tags = sorted(metadata['tags']) file_space = utils.get_file_space_representation(str(path / c.FILES_FOLDER)) experiment_pid = int(metadata['pid']) pids = utils.get_pids() pid_icon_name = 'fas fa-play text-success' if experiment_pid in pids else 'fas fa-stop text-danger' procedure_item_by_column = { 'Select': '<input class="experiment-row" type="checkbox" value="" id="checkbox-{}">' .format(uuid), 'Show': "<button class='btn btn-primary btn-xs experiment-button' id='button-{}'>Show</button>" .format(uuid), 'Status': html_utils.get_status_icon_tag(status), 'PID': html_utils.fa_icon(pid_icon_name) + ' ' + str(experiment_pid), 'Name': name if len(name) > 0 else None, 'Filename': html_utils.monospace( html_utils.color_circle_and_string(metadata['filename'])), 'Duration': str(duration), 'Start': start.strftime('%Y-%m-%d %H:%M:%S'), 'End': end.strftime('%Y-%m-%d %H:%M:%S') if end is not None else None, 'Tags': ' '.join([html_utils.badge(tag) for tag in tags]), 'File space': file_space, 'ID': html_utils.monospace(uuid), 'Git commit': html_utils.monospace( html_utils.color_circle_and_string(metadata['git']['short'])) if metadata['git'] is not None else None, } for scalar_name in all_scalars: value = get_scalar_value(path, scalar_name) if value is not None: value = str( round_to_significant_digits(value, N_SIGNIFICANT_DIGITS)) procedure_item_by_column[scalar_name] = value params = metadata['parameters'] for name in all_params: if name in params: value = params[name] value = round_to_significant_digits(value, N_SIGNIFICANT_DIGITS) value = str(value) else: value = None procedure_item_by_column[name] = value return procedure_item_by_column
def load_all_output(id): with open(str(Path(c.DEFAULT_PARENT_FOLDER) / id / 'stdcombined.txt')) as fp: output = cgi.escape(fp.read()) return html_utils.monospace(output)
def create_procedure_item_by_column(uuid, path, metadata, all_scalars, all_params): name = metadata['name'] start = datetime.datetime.strptime(metadata['startedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") end = None if metadata[ 'endedDatetime'] is None else datetime.datetime.strptime( metadata['endedDatetime'], "%Y-%m-%dT%H:%M:%S.%f") if end is None: duration = datetime.datetime.now() - start else: duration = end - start duration = utils.floor_timedelta(duration) status = metadata['status'] tags = sorted(metadata['tags']) file_space = utils.get_file_space_representation(str(path / c.FILES_FOLDER)) experiment_pid = int(metadata['pid']) pids = psutil.pids() pid_icon_name = 'fas fa-play text-success' if experiment_pid in pids else 'fas fa-stop text-danger' # Set lightbulb class: if metadata['status'] == 'running': lightbulb_class = 'text-{}'.format( 'primary' if metadata['conclusion'] else 'secondary') else: lightbulb_class = 'text-{}'.format( 'primary' if metadata['conclusion'] else 'danger') infoicon_class = 'text-primary' if metadata[ 'description'] else 'text-secondary' arguments = utils.arguments_to_string(metadata['arguments']) procedure_item_by_column = { 'select-row': '', 'DetailsControl': '', 'UUID': uuid, 'Show': "<button class='btn btn-primary btn-xs experiment-button' id='button-{}'>Show</button>".format(uuid), 'Icons': same_line('{}<span style="display:inline-block; width: 12px;"></span>{}<span style="display:inline-block; width: 12px;"></span>{}'.format( html_utils.get_status_icon_tag(status), html_utils.icon('fas fa-info-circle {}'.format(infoicon_class)), html_utils.icon('fas fa-lightbulb {}'.format(lightbulb_class)), )), 'PID': same_line(html_utils.fa_icon(pid_icon_name) + ' ' + str(experiment_pid)), 'Name': name if len(name) > 0 else None, 'Title': cgi.escape(metadata['title']) if metadata['title'] else None, 'Filename': same_line(html_utils.color_circle_and_string(metadata['filename'])), 'Duration': str(duration), 'Start': start.strftime('%Y-%m-%d %H:%M:%S'), 'End': end.strftime('%Y-%m-%d %H:%M:%S') if end is not None else None, 'Tags': ' '.join([html_utils.badge(tag) for tag in tags]), 'File space': file_space, 'ID': same_line("""<button class='btn btn-light btn-xs' onclick="copyToClipboard('{}')">{}</button>""".format(utils.get_short_uuid(uuid), html_utils.fa_icon('copy')) \ + ' ' + html_utils.color_circle(uuid) + ' ' + utils.get_short_uuid(uuid)), 'Git commit': same_line(html_utils.color_circle_and_string(metadata['git']['short'])) if metadata['git'] is not None else None, 'Description': markdown.markdown(cgi.escape(metadata['description'])), 'Conclusion': markdown.markdown(cgi.escape(metadata['conclusion'])), 'Arguments': html_utils.monospace(arguments + """ <button class='btn btn-light btn-xs' onclick="copyToClipboard('{}')">{}</button>""".format(arguments, html_utils.fa_icon('copy'))) if arguments else '', 'Exception': html_utils.monospace('{}: {}'.format(metadata['exceptionType'], metadata['exceptionValue']) if metadata['exceptionType'] is not None else ''), } for scalar_name in all_scalars: value = get_scalar_value(path, scalar_name) if value is not None: value = str( utils.round_to_significant_digits(value, N_SIGNIFICANT_DIGITS)) procedure_item_by_column[scalar_name] = value params = metadata['parameters'] for name in all_params: if name in params: value = params[name] if type(value) in (int, float): value = utils.round_to_significant_digits( value, N_SIGNIFICANT_DIGITS) value = str(value) else: value = None procedure_item_by_column[name] = value return procedure_item_by_column