From af501ebeec3774014cd3e19df87f806fe202d2d3 Mon Sep 17 00:00:00 2001 From: Azerty6 <46007498+Azerty6@users.noreply.github.com> Date: Fri, 19 Nov 2021 10:59:43 +0100 Subject: [PATCH] A lot of values + import of values --- input/data | 10 ++++++++++ src/DataInput.py | 10 ++++++++-- src/Frame.py | 34 +++++++++++++++++++++++++++++++--- src/main.py | 7 ------- src/utils/xhi2.py | 16 ++++++---------- 5 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 input/data diff --git a/input/data b/input/data new file mode 100644 index 0000000..7316403 --- /dev/null +++ b/input/data @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +15 +15 \ No newline at end of file diff --git a/src/DataInput.py b/src/DataInput.py index 4428640..2b4ccab 100644 --- a/src/DataInput.py +++ b/src/DataInput.py @@ -30,12 +30,18 @@ def add_data_callback(var, indx, mode): self.generate_entry() # For some reason, if we remove that, it doesn't seem to work anymore. Strange... entry_value.trace_add("write", add_data_callback) - entry = Entry(self, width=50, font=("Arrial", 18), bg='#FFFFFF', fg='#4682B4', + entry = Entry(self, width=10, font=("Arrial", 18), bg='#FFFFFF', fg='#4682B4', textvariable=entry_value) - entry.pack(expand=YES) + entry.grid(column=len(self.entries) % 10, row=len(self.entries) // 10) self.entries.append(entry) def get_data(self): print([entry for entry in self.entries]) [print(entry.get()) for entry in self.entries] return [float(entry.get()) for entry in self.entries if entry.get() != ""] + + def clear(self): + for entry in self.entries: + entry.destroy() + self.entries.clear() + self.generate_entry() diff --git a/src/Frame.py b/src/Frame.py index 3341583..1414827 100644 --- a/src/Frame.py +++ b/src/Frame.py @@ -1,7 +1,9 @@ +import os +import statistics from tkinter import Frame, Label, Button, YES from time import sleep from src.DataInput import DataInput -from src.utils import present_xhi2_data +from src.utils import get_xhi2_data, display_data class Frame(Frame): @@ -72,12 +74,21 @@ def build_home(cls, window, callback): @classmethod def build_data_selection(cls, window, callback): - + def import_values(): + data_input.clear() + print(os.listdir()) + with open("../input/data", "r") as file: + content = file.readlines() + print(content) + for i, line in enumerate(content): + data_input.entries[i].insert(0, line.replace("\n", "")) + data_input.generate_entry() frame = Frame(window, "#4682B4") frame.add_text( "Sélectionnez votre échantillons de mesures", "Arial", 18, '#4682B4', '#FFFFFF') frame.add_Button("Calculer", "Arial", 20, '#FFFFFF', '#4682B4', callback) + frame.add_Button("Importer des valeurs (fichier input/data)", "Arial", 20, '#FFFFFF', '#4682B4', import_values) data_input = DataInput(frame) frame.add_element(data_input) return frame, data_input @@ -86,5 +97,22 @@ def build_data_selection(cls, window, callback): def build_table(cls, window, data_provider): frame = Frame(window, "#4682B4") frame.add_text("Tableau de \u03C7\u00B2", "Arial", 20, '#4682B4', '#FFFFFF') - frame.on_load(lambda e: present_xhi2_data(data_provider())) + def load(e): + data = data_provider() + class_data, xhi2 = get_xhi2_data(data) + frame.add_text("Classes :", "Arial", 15, "#4682B4", "#FFFFFF") + frame.add_text("\n".join([str(class_) for class_ in class_data]), "Arial", 10, "#4682B4", "#FFFFFF") + frame.add_text(f"\u03C7\u00B2 : {xhi2}", "Arial", 15, "#4682B4", "#FFFFFF") + frame.add_text("Données random :", "Arial", 15, "#4682B4", "#FFFFFF") + frame.add_text(f"Moyenne : {statistics.mean(data)}", "Arial", 10, "#4682B4", "#FFFFFF") + frame.add_text(f"Ecart type : {statistics.stdev(data)}", "Arial", 10, "#4682B4", "#FFFFFF") + display_data( + experimental_frequencies=(class_.experimental_frequency for class_ in class_data), + data=data, + mean=statistics.mean(data), + std_dev=statistics.stdev(data), + class_count=len(class_data), + xhi2=xhi2 + ) + frame.on_load(load) return frame diff --git a/src/main.py b/src/main.py index 9954b01..343eba1 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,4 @@ -import math -import statistics -import matplotlib.pyplot as plt -import numpy as np -from src.DataArray import DataArray -from src.ClassData import ClassData from src.Frame import Frame -from src.utils import present_xhi2_data from tkinter import Tk, mainloop, Entry, YES diff --git a/src/utils/xhi2.py b/src/utils/xhi2.py index 6a35ec9..b987eb7 100644 --- a/src/utils/xhi2.py +++ b/src/utils/xhi2.py @@ -76,9 +76,10 @@ def display_data(experimental_frequencies, data, mean, std_dev, class_count, xhi # On met une legende sur l'axe y plt.ylabel('Frequence') plt.show() + print(xhi2) -def present_xhi2_data(data): +def get_xhi2_data(data): values = compute_reduced_centered_vars(data) min_value = values[0] max_value = values[-1] @@ -98,17 +99,12 @@ def present_xhi2_data(data): xhi2 = class_count * sum( [(class_.experimental_frequency * class_.theorical_frequency) ** 2 / class_.theorical_frequency for class_ in class_data]) - display_data( - experimental_frequencies=(class_.experimental_frequency for class_ in class_data), - data=data, - mean=statistics.mean(data), - std_dev=statistics.stdev(data), - class_count=class_count, - xhi2=xhi2 - ) + return class_data, xhi2 + __all__ = [ - "present_xhi2_data" + "get_xhi2_data", + "display_data" ]