Skip to content

Commit

Permalink
A lot of values + import of values
Browse files Browse the repository at this point in the history
  • Loading branch information
TeddyRoncin committed Nov 19, 2021
1 parent 35365b4 commit af501eb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
10 changes: 10 additions & 0 deletions input/data
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1
2
3
4
5
6
7
8
15
15
10 changes: 8 additions & 2 deletions src/DataInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
34 changes: 31 additions & 3 deletions src/Frame.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
7 changes: 0 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 6 additions & 10 deletions src/utils/xhi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
]

0 comments on commit af501eb

Please sign in to comment.