From c745bdb5a383f63227fa502789a78fd6eea40871 Mon Sep 17 00:00:00 2001 From: gestures Date: Wed, 8 Jul 2026 18:48:22 +0300 Subject: [PATCH] plots --- bloxplot_stats.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ plot_stats.py | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 bloxplot_stats.py create mode 100644 plot_stats.py diff --git a/bloxplot_stats.py b/bloxplot_stats.py new file mode 100644 index 0000000..729b444 --- /dev/null +++ b/bloxplot_stats.py @@ -0,0 +1,57 @@ +import sys +import os +import yaml +import matplotlib.pyplot as plt +import numpy as np +scores_big =[] + +def s_a(n): + return sum(n)/len(n) + +def mediana(n): + while len(n) >2: + n.remove(min(n)) + n.remove(max(n)) + if len(n) == 2: + return s_a(n) + else: + return n[0] + + +def def_file(ax, path, color): + scores =[] + + for filename in sorted(os.listdir(path)): + file_path = os.path.join(path, filename) + # Check if it is a file and not a subdirectory + if os.path.isfile(file_path) and file_path.endswith('.yaml'): + with open(file_path, 'r', encoding='utf-8') as file: + data = yaml.load(file, Loader = yaml.Loader) + scores.append(data['score']) + #scores.append(data['score']/data['total_time']) + scores_big.append(scores) + + + +if __name__ == '__main__': + fig, ax = plt.subplots() + + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "blue") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue") + #print(len(scores_big)) + #plt.boxplotscores_big) + colors1 = ['lightblue', 'pink', 'lightgreen', 'green', 'red', 'blue'] + name = ['Dima', 'Elisey', 'BOBA', 'Nika', 'Sasha', 'Kristina'] + scores_BIG = ax.boxplot(scores_big, patch_artist=True, tick_labels=name) + # Применяем цвета к каждому ящику + for patch, color in zip(scores_BIG['boxes'], colors1): + patch.set_facecolor(color) + ax.set(xlabel='№', ylabel='score/total_time') + ax.grid() + ax.legend() + ax.set_title("Scores of students in dummy simulation") + plt.show() diff --git a/plot_stats.py b/plot_stats.py new file mode 100644 index 0000000..6b8f638 --- /dev/null +++ b/plot_stats.py @@ -0,0 +1,54 @@ +import sys +import os +import yaml +import matplotlib.pyplot as plt +import numpy as np + + +def s_a(n): + return sum(n)/len(n) + +def mediana(n): + while len(n) >2: + n.remove(min(n)) + n.remove(max(n)) + if len(n) == 2: + return s_a(n) + else: + return n[0] + + +def def_file(ax, path, color): + scores =[] + + for filename in sorted(os.listdir(path)): + file_path = os.path.join(path, filename) + # Check if it is a file and not a subdirectory + if os.path.isfile(file_path) and file_path.endswith('.yaml'): + with open(file_path, 'r', encoding='utf-8') as file: + data = yaml.load(file, Loader = yaml.Loader) + scores.append(data['score']) + #scores.append(data['score']/data['total_time']) + + + ax.plot(range(1, len(scores)+1),scores, '.-', label=f"{path.split('/')[-1]}'s scores", color = color) + ax.plot((1, len(scores)),(s_a(scores), s_a(scores)), '--', label=f"{path.split('/')[-1]}'s mean ({round(s_a(scores), 3)})", color = color) + ax.plot((1, len(scores)),(mediana(scores), mediana(scores)), ':', label=f"{path.split('/')[-1]}'s mediana ({round(mediana(scores), 3)})", color = color) + + + +if __name__ == '__main__': + fig, ax = plt.subplots() + + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "orange") + def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue") + + ax.set(xlabel='№', ylabel='score/total_time') + ax.grid() + ax.legend() + ax.set_title("Scores of students in dummy simulation") + plt.show()