| import seaborn as sns
|
| import matplotlib.pyplot as plt
|
| import numpy as np
|
| from predict_function import predict
|
|
|
| def calculate_plot(total_att, total_memory, total_fluency, total_speech, total_spatial):
|
|
|
|
|
| labels = ['Внимание', 'Память', 'Беглость', 'Речь', 'Пространство']
|
| data = np.array([total_att, total_memory, total_fluency, total_speech, total_spatial], dtype=np.float32)
|
| max_value = np.array([18, 26, 14, 26, 16 ], dtype=np.float32)
|
| relative_data = np.divide(data, max_value )* 100
|
| plt.close('all')
|
| fig=plt.figure(figsize=(6, 5))
|
| ax=sns.barplot(y=labels, x=relative_data, palette="Blues_d", hue=labels, legend=False)
|
|
|
| ax.set_xlabel('Процент сохранных функций', fontsize=12, labelpad=10)
|
| ax.set_ylabel('Когнитивные функции', fontsize=12, labelpad=10)
|
|
|
|
|
| plt.xticks(fontsize=10)
|
| plt.yticks(fontsize=10)
|
| plt.title('Оценка когнитивных функций', fontsize=14, pad=20)
|
|
|
|
|
| ax.grid(True, linestyle='--', alpha=0.3)
|
|
|
|
|
|
|
| plt.title(f"Когнитивный профиль. Общий балл:{np.sum(data)}")
|
|
|
|
|
| plt.tight_layout()
|
|
|
| return fig
|
|
|
| def predict_plot(total, total_att, total_memory, total_fluency, total_speech, total_spatial, age):
|
|
|
| data=[total, total_att, total_memory, total_fluency, total_speech, total_spatial, age]
|
|
|
| dict_data = predict(data)
|
|
|
| plt.close('all')
|
| fig, ax=plt.subplots(figsize=(6,4))
|
|
|
|
|
|
|
| sorted_items = sorted(dict_data.items(), key=lambda x: x[1])
|
| labels = [item[0] for item in sorted_items]
|
| values = [item[1] for item in sorted_items]
|
|
|
|
|
| bars = ax.barh(labels, values, color='skyblue')
|
|
|
|
|
| max_idx = np.argmax(values)
|
| bars[max_idx].set_color('green')
|
|
|
|
|
| for bar in bars:
|
| width = bar.get_width()
|
| ax.text(width + 0.01, bar.get_y() + bar.get_height()/2,
|
| f'{width:.2f}',
|
| va='center', ha='left', fontsize=9)
|
|
|
|
|
| ax.set_title(f'Нарушения соответствуют: {labels[max_idx]}',
|
| fontsize=12, pad=10)
|
| ax.set_xlabel('Вероятность', fontsize=10)
|
| ax.set_ylabel('Тип нарушений', fontsize=10)
|
| ax.set_xlim(0, 1.1 if max(values) <= 1 else None)
|
|
|
| plt.tight_layout()
|
| return fig
|
|
|
|
|