from pyodide.ffi import create_proxy
import numpy as np
import matplotlib.pyplot as plt
def desc_stats(*ags, **kws):
data_element = Element("data")
data = data_element.element.value
data = data.replace(' ','').replace('\t',',').replace('\n',',')
data = np.array([float(i) for i in data.split(',')])
count = len(data)
mean = np.mean(data)
median = np.median(data)
uniqs, counts = np.unique(data, return_counts=True)
mode = uniqs[counts == np.amax(counts)]
range_ = np.max(data) - np.min(data)
var = np.var(data, ddof=1)
std = np.std(data, ddof=1)
Element("count").write(f'{count:.0f}')
Element("mean").write(f'{mean:.3f}')
Element("median").write(f'{median:.3f}')
Element("mode").write(str(mode).replace('[','').replace(']',''))
Element("range").write(f'{range_:.3f}')
Element("var").write(f'{var:.3f}')
Element("std").write(f'{std:.3f}')
x = np.ones(len(data))
fig, ax = plt.subplots()
ax.plot(x, data, marker='o', linestyle='None', color='k', alpha=0.1)
ax.boxplot(data, medianprops=dict(color='black', linewidth=1))
ax.set_xticklabels('')
plt.grid
Element("boxplot").write(fig)
sample_data = str(np.round(np.random.randn(20), 3).tolist())[1:-1]
data_input = Element('data')
data_input.element.setAttribute('value', sample_data)
data_input.element.setAttribute('placeholder', sample_data)
desc_stats()
data_input.element.removeAttribute('value')
data_input.element.disabled = False
button_analysis = Element('analysis')
button_analysis.element.onclick = desc_stats