def _quantile(self, valeur): classe = self._classe_du_quantile(valeur) a = classe.start b = self.interval c = _r(classe.getNext().getNext().frequence_cum - classe.getNext().frequence_cum) d = _r(classe.frequence_cum - classe.getPrev().frequence_cum) print(f"{a} + {b} * ({c} / {d})\t\t{valeur}") return a + b * (c / d)
def histogram(self): histo = "\n\t\t\t c\t\tfreq\tfreq^\tfreq^%" for i in self.classes: interval = f"[{i.start}, {i.end}[" baton = "".join("#" for i in range(i.effectif)) centre = f"({_r(i.centre)})" freq = _r(i.frequence) freq_cum = _r(i.frequence_cum) freq_cum_pc = _r(i.frequence_cum * 100) histo += f"\n{interval}\t{centre}\t{freq} " \ f"\t{freq_cum} \t{freq_cum_pc} \t{baton} {len(baton)}" return histo
def mode(self): classe = self.classe_modale()[0] a = classe.start b = classe.effectif - classe.getPrev().effectif d = classe.effectif - classe.getNext().effectif c = self.interval return _r(a + (b * c) / (b + d))
def _serialize_data(self): """Serialization des données""" return { 'study': { 'general': { 'effectifs': self.effectifs, 'min': min(self.serie), 'max': max(self.serie), 'etendue': self.etendue, 'mode': self.mode(), }, 'centre': { 'centre': _r(self.centre), 'moyenne': _r(self.moyenne), 'mediane': _r(self.mediane()), }, 'dispersion': { 'ecart_absolu_moyen': _r(self.EAM()), 'ecart_semi_inter_quartile': _r(self.ESI()), 'variance': _r(self.variance()), 'ecart_type': _r(self.ecart_type()), 'coefficient_de_variation': { 'data': _r(self.coefficient_variation()), 'info': self._get_coeff_info('variation', COEF_VAR) } }, 'forme': { 'coefficient_asymetrie': { 'data': _r(self.coeff_asym()), 'info': self._get_coeff_info('asymetrie') }, 'coefficient_applatissement': { 'data': _r(self.coeff_appl()), 'info': self._get_coeff_info('applatissement') } }, 'quantiles': { 'quartiles': self.quartiles(), 'deciles': self.deciles(), }, } }
def getData(self): data = self._serialize_data() general = data['study']['general'] general['classe_modale'] = self.classe_modale()[0].range_repr data['plot'] = { "data": {i.range_repr: i.effectif for i in self.classes}, # Delete ? "classes": [i._serialize_data() for i in self.classes], "freq": { "ticks": [i.range_repr for i in self.classes], "eff": [int(i.effectif) for i in self.classes], "eff_pc": [_r(i.frequence_pc) for i in self.classes], }, "cum": { 'ticks': [f"{i.start}{' ' * 5}{i.end}" for i in self.classes], "freq": [_r(i.frequence_cum) for i in self.classes], "eff": [int(i.effectif_cum) for i in self.classes] } } return data
def _quantiles(self, type, population): data = pd.DataFrame(population) position = [_r((1 / type) * i) for i in range(1, type)] quartiles = [_r(data.quantile(i)[0]) for i in position] return {c + 1: i for c, i in enumerate(quartiles)}
def frequences(self, cumule=False, pourcent=False): p = lambda: 100 if pourcent else 1 c = lambda x: x.frequence_cum if cumule else x.frequence return [_r(c(i) * p()) for i in self.classes]
def quartiles(self): q1 = self._quantile(0.25) q2 = self.mediane() q3 = self._quantile(0.75) return {1: _r(q1), 2: _r(q2), 3: _r(q3)}