def cmd(diversity_file, categories, prune, output): data = load_diversity_data(diversity_file) if categories is not None: categories = categories.split(",") if prune is not None: prune = prune.split(",") data_tree = tree.data_to_tree(data, categories) compute_internal_counts(data_tree) compute_verbose_labels(data_tree) if prune is not None: data_tree = prune_tree(data_tree, prune) rectangles = compute_rectangles(data_tree) if output == "-": for rect in rectangles: print(rect) else: drawing.draw_rectangles(rectangles, output)
def test_compute_rectangles(datasets, d, levels): test_file = "data/rectangles-" + d + "_" + "-".join(levels) + ".json" error_prefix = "Error when testing {}\n".format(test_file) expected_rects = json.load(open(test_file)) tree = tr.data_to_tree(datasets[d], levels) rects = treemap.compute_rectangles(tree) compare_rectangles(rects, expected_rects["rectangles"], error_prefix)
def test_prune_tree(datasets, test_file): error_prefix = "Error when testing {}\n".format(test_file) test_data = json.load(open(test_file)) tree = tr.data_to_tree(datasets[test_data["dataset"]], test_data["levels"]) pruned_tree = treemap.prune_tree(tree, test_data["prune"]) compare_trees(pruned_tree, test_data["tree"], error_prefix, compare_counts=True)
def test_compute_verbose_labels(datasets, d, levels): test_file = "data/tree-" + d + "_" + "-".join(levels) + ".json" error_prefix = "Error when testing {}\n".format(test_file) test_data = json.load(open(test_file)) tree = tr.data_to_tree(datasets[d], levels) treemap.compute_verbose_labels(tree) compare_trees(tree, test_data["tree"], error_prefix, compare_verbose_labels=True)
def test_compute_internal_counts(datasets, d, levels): test_file = "data/tree-" + d + "_" + "-".join(levels) + ".json" error_prefix = "Error when testing {}\n".format(test_file) test_data = json.load(open(test_file)) tree = tr.data_to_tree(datasets[d], levels) total_count = treemap.compute_internal_counts(tree) assert total_count == test_data["total_count"], \ error_prefix + "Incorrect compute_internal_counts return value. " \ "Got {}, expected {}".format(total_count, test_data["total_count"]) assert tree.label == "", "Root node does not have empty string label" assert tree.count == test_data["tree"]["count"], \ error_prefix + "Root node has incorrect count." \ "Got {}, expected {}".format(tree.count, test_data["tree"]["count"]) compare_trees(tree, test_data["tree"], error_prefix, compare_counts=True)