Compare commits

...
8 Commits
Author SHA1 Message Date
gestures6 1cd15dd6bc first test 2026-07-11 10:45:19 +03:00
gestures6 9321f1973d plots =( 2026-07-11 10:33:22 +03:00
gestures6 fb88fa67e4 save to files 2026-07-11 09:23:45 +03:00
gestures 052db363d7 bar plot 2026-07-10 15:54:49 +03:00
gestures f0d88ac1b3 start for no int data 2026-07-10 11:22:24 +03:00
gestures6 eba2dfc5a6 plots 2026-07-09 18:23:25 +03:00
gestures a467318d24 имя автоматически присваеваеться из адреса 2026-07-09 14:50:26 +03:00
gestures c745bdb5a3 plots 2026-07-08 18:48:22 +03:00
4 changed files with 461 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
import sys
import os
import yaml
import matplotlib.pyplot as plt
import numpy as np
scores_big =[]
name = []
colors = []
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 plot(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)
def boxplot(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)
name.append(path.split('/')[-1])
colors.append(color)
if __name__ == '__main__':
global_path = "/home/gestures/Easy_sim/dummy_simulation/stats/"
# 1. Name (Dima)
# 2. Name-Name (Dima-Elisey)
DATA = {} # Name of creator - {} - Name of tester
for dirname in sorted(os.listdir(global_path)):
dirpath = os.path.join(global_path, dirname)
if os.path.isdir(file_path):
data = []
if not dirname.contains('-'):
name = dirname
if not name is DATA:
DATA[name] = {}
DATA[name][name] = data
else:
names = dirname.split('-')
name1 = names[0]
name2 = names[1]
if not name1 is DATA:
DATA[name1] = {}
DATA[name1][name2] = data
for filename in sorted(os.listdir(dirpath)):
file_path = os.path.join(dirpath, filename)
if file_path.endswith('.yaml'):
with open(file_path, 'r', encoding='utf-8') as file:
datafile = yaml.load(file, Loader = yaml.Loader)
# TODO change score to new formula
data.append(datafile['score'])
fig, ax = plt.subplots()
boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen")
boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red")
boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta")
boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink")
boxplot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "orange")
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue")
scores_BIG = ax.boxplot(scores_big, patch_artist=True, tick_labels=name)
# Применяем цвета к каждому ящику
for patch, color in zip(scores_BIG['boxes'], colors):
patch.set_facecolor(color)
ax.set(xlabel='', ylabel='score')
ax.grid()
ax.legend()
ax.set_title("Scores of students in dummy simulation")
plt.show()
#path.split('/')[-1]
+73
View File
@@ -0,0 +1,73 @@
import matplotlib.pyplot as plt
import numpy as np
# Данные: (первый человек, второй человек, время1, время2)
data = [
("Елисей", "Ника", "01:53.68", "00:46.85"),
("Ника", "Вова", "00:57.28", "01:05.67"),
("Вова", "Елисей","00:38.35", "00:34.74"),
("Дима", "Саша", "00:57.45", "00:52.90"),
("Саша", "Дима", "00:25.69", "00:55.85"),
]
def time_to_seconds(t):
# поддерживает формат mm:ss.xx
mm, rest = t.split(":")
ss = float(rest)
return int(mm) * 60 + ss
def seconds_to_time(sec):
mm = int(sec // 60)
ss = sec % 60
return f"{mm:02d}:{ss:05.2f}"
# Подготовка данных
labels = [f"{a}{b}" for a, b, _, _ in data]
t1 = np.array([time_to_seconds(x[2]) for x in data])
t2 = np.array([time_to_seconds(x[3]) for x in data])
y = np.arange(len(data))
# Визуальный стиль
plt.style.use("seaborn-v0_8-whitegrid")
fig, ax = plt.subplots(figsize=(11, 6))
color1 = "#4C78A8"
color2 = "#F58518"
bars1 = ax.barh(y, t1, color=color1, edgecolor="none", label="Первое время")
bars2 = ax.barh(y, t2, left=t1, color=color2, edgecolor="none", label="Второе время")
# Подписи на сегментах
for i, (b1, b2, a1, a2) in enumerate(zip(bars1, bars2, t1, t2)):
ax.text(
b1.get_x() + b1.get_width() / 2,
b1.get_y() + b1.get_height() / 2,
seconds_to_time(a1),
ha="center", va="center", color="white", fontsize=10, fontweight="bold"
)
ax.text(
b2.get_x() + b2.get_width() / 2,
b2.get_y() + b2.get_height() / 2,
seconds_to_time(a2),
ha="center", va="center", color="white", fontsize=10, fontweight="bold"
)
# Подписи осей и оформление
ax.set_yticks(y)
ax.set_yticklabels(labels, fontsize=11)
ax.invert_yaxis()
ax.set_xlabel("Время, сек.")
ax.set_title("Сравнение суммарного времени выполнения задания", fontsize=15, pad=12)
ax.legend(loc="lower right")
# Сетка и рамки
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.grid(axis="x", linestyle="--", alpha=0.4)
plt.tight_layout()
fig.savefig("first_test.png")
plt.show()
+221
View File
@@ -0,0 +1,221 @@
import sys
import os
import yaml
import matplotlib.pyplot as plt
import numpy as np
def total_boxplot(DATA, creator = 'any', tester = 'any', simulation = "dummy_simulation", savepath = "./"):
fig, ax = plt.subplots()
data_to_plot = []
labels = []
title = f'Boxplot of scores in {simulation},'
xlabel = ""
colors_list = plt.colormaps['tab10'].colors
if creator == tester == 'any':
print(f"Warning: setting both creator and tester as 'any' plots only self testing!")
title += f" self testing"
xlabel = "self tester"
for creator_name, data in DATA.items():
if creator_name in data:
data_to_plot.append(data[creator_name])
labels.append(creator_name)
elif creator == 'any':
title += f" tester: {tester}"
xlabel = "creator"
for creator_name, data in DATA.items():
if tester in data:
data_to_plot.append(data[tester])
#labels.append(f"{creator_name}-{tester}")
labels.append(creator_name)
elif tester == 'any':
title += f" creator: {creator}"
xlabel = "tester"
if creator in DATA:
for tester_name, data in DATA[creator].items():
data_to_plot.append(data)
#labels.append(f"{creator}-{tester}")
labels.append(tester_name)
if len(data_to_plot) == 0:
print("No appropriate data!")
return
#print(len(data_to_plot), len(labels))
median_styling = {'color': 'black', 'linewidth': 2}
elements = ax.boxplot(data_to_plot, patch_artist=True, tick_labels=labels, medianprops=median_styling)
for i, patch in enumerate(elements['boxes']):
patch.set_facecolor(colors_list[(i)%10])
ax.grid()
#ax.legend()
ax.set(xlabel=xlabel, ylabel='Score')
ax.set_title(title)
ax.figure.savefig(f'{savepath}/{creator}_{tester}_{simulation}.png', bbox_inches='tight')
def heat_map(DATA, criteria = np.median, savepath = "./"):
names_to_nums = {name: num for num, name in enumerate(list(DATA.keys()))}
values = np.zeros( (len(names_to_nums)+1, len(names_to_nums)+1) )
testers = {}
for creator, Data in DATA.items():
total_creator = []
for tester, data in Data.items():
if not tester in testers:
testers[tester] = []
if creator in names_to_nums and tester in names_to_nums:
creator_idx = names_to_nums[creator]
tester_idx = names_to_nums[tester]
values[creator_idx, tester_idx] = criteria(data)
total_creator += data
testers[tester] +=data
values[creator_idx, len(names_to_nums)] = criteria(total_creator)
for tester, data in testers.items():
tester_idx = names_to_nums[tester]
values[len(names_to_nums), tester_idx] = criteria(data)
fig, ax = plt.subplots()
im = ax.imshow(values, cmap='coolwarm')
for i in range(values.shape[0]):
for j in range(values.shape[1]):
text = ax.text(j, i, round(values[i, j],1), ha="center", va="center", color="k")
ax.set_xticks(range(len(DATA.keys())+1), labels=list(DATA.keys())+['mean'] )
ax.set_yticks(range(len(DATA.keys())+1), labels=list(DATA.keys())+['mean'] )
ax.set(xlabel='tester', ylabel='creator')
ax.set_title(f"Cross-validation heatmap ({criteria.__name__})")
ax.figure.savefig(f"{savepath}/cross_validation_{criteria.__name__}.png")
def convert_score(data):
score = data['score']
Nsof = len(data['exted_sofs'])
Ncol = len(data['collisions'])
Ksof = data['k_params']['_k_sof']
Khp = data['k_params']['_k_hp']
Kch = data['k_params']['_k_charge']
Khp_max = 100
Kch_max = 100
Kch_r = (score - Ksof*Nsof-Khp*(Khp_max-Ncol)/Khp_max) * Kch_max/Kch
score_new = Ksof*Nsof*(Kch*Kch_r/Khp_max+Khp*(Khp_max-Ncol)/Khp_max)
#print(type(score_new))
return score_new
# DATA[name] = {name: [scores]}
def no_interface_plot(DATA, savepath = "./"):
n = 0
names_with = []#DATA.keys()
names_without = []
for creator, Data in DATA.items():
for tester, data in Data.items():
if tester == creator:
if 'NoInt' in creator:
pass
else:
wInt = creator+'NoInt'
if wInt in DATA:
names_with.append(creator)
names_without.append(wInt)
#print(len(names_with), names_with)
#print(len(names_without), names_without)
'''
for tester, data in Data.items():
if tester == creator:
del DATA[]
'''
creator_means = {
'With interface': [np.median(DATA[name][name]) for name in names_with],
'Without interface': [np.median(DATA[name][name]) for name in names_without]}
x = np.arange(len(names_with)) # the label locations
width = 0.25 # the width of the bars
multiplier = 0
fig, ax = plt.subplots(layout='constrained')
for attribute, measurement in creator_means.items():
offset = width * multiplier
rects = ax.bar(x + offset, np.round(measurement,2), width, label=attribute)
ax.bar_label(rects, padding=3)
multiplier += 1
ax.set_ylabel('Score')
ax.set_title('Change in scores with visual interface disabled')
ax.set_xticks(x + width, names_with)
ax.legend(loc='upper left', ncols=3)
ax.set_ylim(0, 100)
ax.grid(axis='y')
ax.figure.savefig(f"{savepath}/no_interface.png")
if __name__ == '__main__':
global_path = "/home/gestures6/Easy_sim/dummy_simulation/stats/"
# 1. Name (Dima)
# 2. Name-Name (Dima-Elisey)
DATA = {} # Name of creator - {} - Name of tester
for dirname in sorted(os.listdir(global_path)):
dirpath = os.path.join(global_path, dirname)
if os.path.isdir(dirpath) and not dirname.startswith('!'):
data = []
if not '-' in dirname:
name = dirname
if not name in DATA:
DATA[name] = {}
DATA[name][name] = data
else:
names = dirname.split('-')
name1 = names[0]
name2 = names[1]
if not name1 in DATA:
DATA[name1] = {}
DATA[name1][name2] = data
for filename in sorted(os.listdir(dirpath)):
file_path = os.path.join(dirpath, filename)
if file_path.endswith('.yaml'):
with open(file_path, 'r', encoding='utf-8') as file:
datafile = yaml.load(file, Loader = yaml.Loader)
data.append(convert_score(datafile)) # TODO change score to new formula
#data.append(datafile['score'])
#for cr, data in DATA.items():
#print(f"{cr}: {data}")
savepath = global_path
total_boxplot(DATA, creator = 'any', tester = 'any', savepath = savepath)
no_interface_plot(DATA, savepath = savepath)
#for name in DATA.keys():
#total_boxplot(DATA, creator = name, tester = 'any', savepath = savepath)
#total_boxplot(DATA, creator = 'any', tester = name, savepath = savepath)
#heat_map(DATA, savepath = savepath)
plt.show()
+54
View File
@@ -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 plot(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()
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Dima", "limegreen")
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Elisey", "red")
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/BOBA", "magenta")
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Nika", "pink")
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Sasha", "orange")
plot(ax, "/home/gestures/Easy_sim/dummy_simulation/stats/Christine", "blue")
ax.set(xlabel='', ylabel='score')
ax.grid()
ax.legend()
ax.set_title("Scores of students in dummy simulation")
plt.show()