def output_categories(categories, remaining): f = open(OUTPUT_CATEGORY_FILE, "w") f.write("category number:" + str(len(categories)) + " , remaining locations:" + str(remaining) + "\n") for idx, a_category in enumerate(categories): f.write("Category:" + str(idx + 1) + " , #= " + str(len(a_category)) + ">>>\n") clocation.output_location_part_list([x.clocation for x in a_category], f) f.close()
def output_location_cluster(locations, output_file): sorted_locations = sorted(locations.values(), key=lambda x:x.cluster1) groups = {x:list(y) for x, y in itertools.groupby(sorted_locations, lambda x:x.cluster1)} clocation.output_location_list([], output_file) f = open(output_file, "a") # for each cluster for c, a_group in groups.items(): f.write("Cluster:" + str(c) + "\t#:" + str(len(a_group)) + "\n") clocation.output_location_part_list(a_group, f) f.close()
def output_location_cluster(locations, output_file): sorted_locations = sorted(locations.values(), key=lambda x: x.cluster1) groups = { x: list(y) for x, y in itertools.groupby(sorted_locations, lambda x: x.cluster1) } clocation.output_location_list([], output_file) f = open(output_file, "a") # for each cluster for c, a_group in groups.items(): f.write("Cluster:" + str(c) + "\t#:" + str(len(a_group)) + "\n") clocation.output_location_part_list(a_group, f) f.close()