def pprint(self, resource, out=sys.stdout): """Pretty prints a resource or part of it. """ if (isinstance(resource, dict) and 'object' in resource and 'resource' in resource): resource_id = resource['resource'] if (SOURCE_RE.match(resource_id) or DATASET_RE.match(resource_id) or MODEL_RE.match(resource_id) or EVALUATION_RE.match(resource_id) or ENSEMBLE_RE.match(resource_id) or CLUSTER_RE.match(resource_id) or ANOMALY_RE.match(resource_id) or TOPIC_MODEL_RE.match(resource_id) or LOGISTIC_REGRESSION_RE.match(resource_id) or TIME_SERIES_RE.match(resource_id) or DEEPNET_RE.match(resource_id) or FUSION_RE.match(resource_id) or PCA_RE.match(resource_id) or LINEAR_REGRESSION_RE.match(resource_id) or OPTIML_RE.match(resource_id)): out.write("%s (%s bytes)\n" % (resource['object']['name'], resource['object']['size'])) elif PREDICTION_RE.match(resource['resource']): objective_field_name = ( resource['object']['fields'][ resource['object']['objective_fields'][0]]['name']) input_data = {} for key, value in resource['object']['input_data'].items(): try: name = resource['object']['fields'][key]['name'] except KeyError: name = key input_data[name] = value prediction = ( resource['object']['prediction'][ resource['object']['objective_fields'][0]]) out.write("%s for %s is %s\n" % (objective_field_name, input_data, prediction)) out.flush() else: pprint.pprint(resource, out, indent=4)
def pprint(self, resource, out=sys.stdout): """Pretty prints a resource or part of it. """ if (isinstance(resource, dict) and 'object' in resource and 'resource' in resource): resource_id = resource['resource'] if (SOURCE_RE.match(resource_id) or DATASET_RE.match(resource_id) or MODEL_RE.match(resource_id) or EVALUATION_RE.match(resource_id) or ENSEMBLE_RE.match(resource_id) or CLUSTER_RE.match(resource_id) or ANOMALY_RE.match(resource_id) or TOPIC_MODEL_RE.match(resource_id) or LOGISTIC_REGRESSION_RE.match(resource_id) or TIME_SERIES_RE.match(resource_id) or DEEPNET_RE.match(resource_id) or FUSION_RE.match(resource_id) or PCA_RE.match(resource_id) or LINEAR_REGRESSION_RE.match(resource_id) or OPTIML_RE.match(resource_id)): out.write("%s (%s bytes)\n" % (resource['object']['name'], resource['object']['size'])) elif PREDICTION_RE.match(resource['resource']): objective_field_name = ( resource['object']['fields'][ resource['object']['objective_fields'][0]]['name']) input_data = {} for key, value in resource['object']['input_data'].items(): try: name = resource['object']['fields'][key]['name'] except KeyError: name = key input_data[name] = value prediction = ( resource['object']['prediction'][ resource['object']['objective_fields'][0]]) out.write("%s for %s is %s\n" % (objective_field_name, input_data, prediction)) out.flush() else: pprint.pprint(resource, out, indent=4)