имя автоматически присваеваеться из адреса

main
gestures 2 weeks ago
parent c745bdb5a3
commit a467318d24

@ -4,7 +4,8 @@ import yaml
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
scores_big =[] scores_big =[]
name = []
colors = []
def s_a(n): def s_a(n):
return sum(n)/len(n) return sum(n)/len(n)
@ -17,8 +18,23 @@ def mediana(n):
else: else:
return n[0] return n[0]
def plot(ax, path, color):
scores =[]
def def_file(ax, path, color): 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)
def boxplot(ax, path, color):
scores =[] scores =[]
for filename in sorted(os.listdir(path)): for filename in sorted(os.listdir(path)):
@ -27,31 +43,31 @@ def def_file(ax, path, color):
if os.path.isfile(file_path) and file_path.endswith('.yaml'): if os.path.isfile(file_path) and file_path.endswith('.yaml'):
with open(file_path, 'r', encoding='utf-8') as file: with open(file_path, 'r', encoding='utf-8') as file:
data = yaml.load(file, Loader = yaml.Loader) data = yaml.load(file, Loader = yaml.Loader)
scores.append(data['score']) #scores.append(data['score'])
#scores.append(data['score']/data['total_time']) scores.append(data['score']/data['total_time'])
scores_big.append(scores)
scores_big.append(scores)
name.append(path.split('/')[-1])
colors.append(color)
if __name__ == '__main__': if __name__ == '__main__':
fig, ax = plt.subplots() fig, ax = plt.subplots()
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen") boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red") boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta") boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink") boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "blue") boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "orange")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue") plot(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) scores_BIG = ax.boxplot(scores_big, patch_artist=True, tick_labels=name)
# Применяем цвета к каждому ящику # Применяем цвета к каждому ящику
for patch, color in zip(scores_BIG['boxes'], colors1): for patch, color in zip(scores_BIG['boxes'], colors):
patch.set_facecolor(color) patch.set_facecolor(color)
ax.set(xlabel='', ylabel='score/total_time') ax.set(xlabel='', ylabel='score')
ax.grid() ax.grid()
ax.legend() ax.legend()
ax.set_title("Scores of students in dummy simulation") ax.set_title("Scores of students in dummy simulation")
plt.show() plt.show()
#path.split('/')[-1]

@ -18,7 +18,7 @@ def mediana(n):
return n[0] return n[0]
def def_file(ax, path, color): def plot(ax, path, color):
scores =[] scores =[]
for filename in sorted(os.listdir(path)): for filename in sorted(os.listdir(path)):
@ -40,14 +40,14 @@ def def_file(ax, path, color):
if __name__ == '__main__': if __name__ == '__main__':
fig, ax = plt.subplots() fig, ax = plt.subplots()
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen") plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red") plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta") plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink") plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "orange") plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "orange")
def_file(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue") plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue")
ax.set(xlabel='', ylabel='score/total_time') ax.set(xlabel='', ylabel='score')
ax.grid() ax.grid()
ax.legend() ax.legend()
ax.set_title("Scores of students in dummy simulation") ax.set_title("Scores of students in dummy simulation")

Loading…
Cancel
Save