<jupyter_start><jupyter_text>Visualization part<jupyter_code>colors = ['#827E9A', '#E69999', '#F8BD7F', '#3E4E50', '#B388EB',
          '#8093F1', '#C4B7CB', '#BBC7CE', '#98E2C6', '#99B2DD', '#EDBFC6']


def make_practical_kde_plots(exercices):
    plots = []
    yr = [0, 2.3]

    for i, ex in enumerate(exercices):
        xs = []
        ys = []
        subset = exercices[ex].values

        kde = gaussian_kde(subset)
        # Evenly space x values
        x = np.linspace(0, 2, 100)
        # Evaluate pdf at every value of x
        y = kde.pdf(x)

        # Append the values to plot
        xs.append(list(x))
        ys.append(list(y))

        kernel_source = ColumnDataSource(data={'x': xs, 'y': ys})
        p = figure(width=400, height=100, tools="", y_range=yr)
        p.multi_line('x', 'y', color=colors[i % len(
            colors)], legend=ex, line_width=3, source=kernel_source)
        p.legend.location = 'top_left'
        plots.append(p)

    return gridplot(plots, ncols=2 + (len(plots) > 6))

def make_heatmap_practical(sheet_stats_promo):
    
    data = {'exo': [], 'group': [], 'total': []}

    for index, cols in sheet_stats_promo.iterrows():
        for practical in sheet_stats_promo.columns:
            data['exo'].append(practical)
            data['group'].append(index)
            data['total'].append(sheet_stats_promo[practical][index])

    tp_stats = pd.DataFrame(data=data)
    practical = raw_files[0]
    practical = practical.split('.')[0]

    colors = ["#ea9999", "#f4c7c3", "#fce8b2", "#b7e1cd", "#57bb8a"]
    mapper = LinearColorMapper(
        palette=colors, low=tp_stats.total.min(), high=tp_stats.total.max())

    p = figure(title="Class averages for practical: {0}".format(select_sheet.value),
               x_range=sheet_stats_promo.columns.tolist(), y_range=[index for index, cols in sheet_stats_promo.iterrows()][::-1],
               x_axis_location="above", plot_height=600,
               tools="", toolbar_location='below', width_policy='max',
               tooltips=[('group', '@group'), ('exercise', '@exo'), ('mean', '@total')])

    p.axis.axis_line_color = None
    p.axis.major_tick_line_color = None
    p.axis.major_label_text_font_size = "10pt"
    p.axis.major_label_standoff = 0
    p.axis.major_label_orientation = 'vertical'

    p.rect(x="exo", y="group", width=1, height=1,
           source=tp_stats,
           fill_color={'field': 'total', 'transform': mapper},
           line_color='white')

    color_bar = ColorBar(color_mapper=mapper, major_label_text_font_size="8pt",
                         ticker=BasicTicker(desired_num_ticks=len(colors)),
                         formatter=PrintfTickFormatter(format="%d%%"),
                         label_standoff=8, border_line_color=None, location=(0, 0))
    p.add_layout(color_bar, 'right')

    return p
def group_change(attr, old, new):
    select_student.options = practicals[0][practicals[0]
                                           ['gr'] == new].index.tolist()
    select_group.value = new


def student_change(attr, old, new):
    select_student.value = new


def sheet_change(attr, old, new):
    select_sheet.value = new
    p = practicals[raw_files.index(new)]
    exercices = p[p.columns[4: -3]]
    
    c = column(make_heatmap_practical(stats_promo[new]), make_practical_kde_plots(exercices))
    tab1 = Panel(child=c, title='Practical info')
    tabs.tabs = [tab1, tab2, tab3]
    push_notebook(handle=t)


select_sheet = Select(title='Sheets', options=raw_files, value=raw_files[0])
select_group = Select(
    title='Group', options=practicals[0]['gr'].unique().tolist())
select_group.value = select_group.options[0]
select_student = Select(
    title='Student', options=practicals[0][practicals[0]['gr'] == select_group.value].index.tolist())
select_student.value = select_student.options[0]

select_group.on_change('value', group_change)
select_sheet.on_change('value', sheet_change)
select_student.on_change('value', student_change)


def plaf(doc):
    doc.add_root(row(select_group, select_student, select_sheet))


show(plaf)

p = practicals[raw_files.index(select_sheet.value)]
exercices = p[p.columns[4: -3]]

c = column(make_heatmap_practical(stats_promo[select_sheet.value]), make_practical_kde_plots(exercices))

tab1 = Panel(child=c, title='Practical info')

p2 = figure(plot_width=300, plot_height=300)
p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5],
        line_width=3, color="navy", alpha=0.5)
tab2 = Panel(child=p2, title='Class info')

tab3 = Panel(child=p2, title='Student info')

tabs = Tabs(tabs=[tab1, tab2, tab3])

t = show(tabs, notebook_handle=True)
student_grades = pd.DataFrame([practicals[i].loc[select_student.value, ['total']].append(
    pd.Series([raw_files[i].split('.')[0]], ['TP'])) for i in range(len(raw_files))]).round(2)

s_grades = student_grades
s_grades.index = s_grades['TP'].to_list()
s_grades.drop(['TP'], axis=1, inplace=True)

s_grades
student_grades = pd.DataFrame([practicals[i].loc[select_student.value, ['total']].append(
    pd.Series([raw_files[i].split('.')[0]], ['TP'])) for i in range(len(raw_files))])

student_grades['color'] = student_grades.total.apply(
    lambda grade: 'blue' if grade > 95 else 'red')

source = ColumnDataSource(student_grades)
averages = [practicals[raw_files.index(i)].mean()['total'] for i in raw_files]

p = figure(y_range=student_grades['TP'], tools='')
glyph = HBar(y="TP", right="total", left=0, height=0.5, fill_color="#b3de69")
p.add_glyph(source, glyph)

show(p)
show(make_heatmap_practical(stats_promo))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16343738787226408, 'fraction_numerical': 0.024757804090419805, 'mean_word_length': 3.9555555555555557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '156556', 'license': 'MIT', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1963, 'n_words': 340, 'path': 'sup_grade_analysis.ipynb', 'repo_name': 'Eazhi/SGA', 'size': '5574'}