from pprint import pprint import json from pathlib import Path from main import RunResults, Iteration, Centroid import matplotlib.pyplot as plt from persistance import run_result_from_dict def process(runs: list[RunResults]) -> None: runs.sort(key=lambda a: a.k) x = tuple(run.k for run in runs) y = tuple(run.iterations[-1].wss for run in runs) plt.scatter(x, y) plt.ylabel("wss") plt.xlabel("K") # for i_x, i_y in zip(x, y): # For k labels on every point # plt.text(i_x, i_y, '{}'.format(i_x)) plt.show() # def process(runs: list[RunResults]) -> None: # for run in runs: # if run.k == 1000: # print(run.k, run.iterations[-1].wss) def main(): runs = list() for json_file in Path(".").glob("*.json"): with open(json_file, mode="r") as file: try: runs.append(run_result_from_dict(json.load(file), str(json_file))) except Exception as e: print(json_file) raise e process(runs) if __name__ == "__main__": main()