Skip to content

Commit

Permalink
added a new case to test_CSV_reader.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JVstarN committed Jun 25, 2020
1 parent 1f72e85 commit c66dcbc
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 33 deletions.
19 changes: 11 additions & 8 deletions App/Infobact.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class InfoBact(tk.Frame):
"""In dit klass kunnen er informatie over een bepaalde bactrie geshowed worden, door gebruik van de json bestand
te maken"""
te maken """
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
Expand All @@ -26,7 +26,7 @@ def __init__(self, parent, controller):
frameMidenMiden = tk.Frame(self, bg= bg_background)

titel = tk.Label(frameOnderInfoBact, text="Informatie over de bacterie", fg="#FFEEDD", font='Arial 30 bold ',
bg =bg_background)
bg=bg_background)
tk.Frame.configure(self, bg=bg_background)

buttonMainPage = tk.Button(frameBovenInfoBact, text="Terug naar de homepagina",height=5, width=23, fg=fg,
Expand All @@ -36,7 +36,7 @@ def __init__(self, parent, controller):
bg="white", font='Arial 10', command=lambda: controller.showFrame("PlotGraph"))

LabelVraag = tk.Label(frameOnderInfoBact,text="Over welke bacterie wil je informatie krijgen?"
, font='Arial 18',bg=bg_background) # "Type de naam van de bacterie hiernaast:",
, font='Arial 18',bg=bg_background)

entryBactName = tk.Entry(frameOnderInfoBact, font="Arial 18")

Expand Down Expand Up @@ -80,15 +80,18 @@ def findJson(input):

naamUitprinten.pack(side=tk.LEFT, fill=tk.X, padx=5, ancho="nw")
infoUitprinten.pack(side=tk.LEFT, fill=tk.X, padx=5, ancho="nw")
# fotolabel.pack(side=tk.TOP, fill=tk.X, padx=5, ancho="nw")

except FileNotFoundError:
messagebox.showwarning("", "We hebben geen informatie over die bacterie kunnen vinden")

img = ImageTk.PhotoImage(Image.open("../Extra bestanden/" + str(input)+".png"))
panel = tk.Label(frameMideen, image=img)
panel.image = img
# panel.pack(side="bottom", ancho="center")
try:
img = ImageTk.PhotoImage(Image.open("../Extra bestanden/" + str(input)+".png"))
panel = tk.Label(frameMideen, image=img)
panel.image = img
fotolabel.pack(side=tk.TOP, fill=tk.X, padx=5, ancho="nw")
panel.pack(side="bottom", ancho="center")
except FileNotFoundError:
print("file not found")

# hier wordt alles op het scherm aangetoond
frameOnderInfoBact.pack(pady=0, expand=tk.TRUE, fill= tk.X)
Expand Down
8 changes: 3 additions & 5 deletions App/Mainpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def __init__(self, parent, controller):
frameOnderMainpage = tk.Frame(self, bg=bg_background)
tk.Frame.configure(self, bg=bg_background)

titel = tk.Label(frameBovenMainpage, text="Welcome to Growth Curve Model!", fg='black', bg="white",
font='Arial 35 bold')
titel = tk.Label(frameBovenMainpage, text="Welcome to Growth Curve Model!", fg='black', bg="white",font='Arial 35 bold')

startGrafiekTekenen = tk.Button(frameOnderMainpage, text="Teken de grafiek", height=5, width=23, fg=fg,
bg="white", font='Arial 14', command=lambda: controller.showFrame("PlotGraph"))
Expand All @@ -32,9 +31,8 @@ def __init__(self, parent, controller):
procesFileButton = tk.Button(frameOnderMainpage, text="Upload a file", height=5, width=23, fg=fg,
bg="white", font='Arial 14', command=lambda: controller.showFrame("ProcesFile"))

# statusbar = tk.Label(self, bd=1, relief=tk.SUNKEN, padx=10, pady=20, bg=bg_button,
# text="Copyright© Maria Dukmak")
# statusbar.pack(side=tk.BOTTOM, fill=tk.BOTH)
statusbar = tk.Label(self, bd=1, relief=tk.SUNKEN, padx=10, pady=20, bg="white",text="Copyright© Maria Dukmak")
statusbar.pack(side=tk.BOTTOM, fill=tk.BOTH)

# hier wordt alles op het schrem aangetoond
titel.pack(side=tk.TOP, fill=tk.X)
Expand Down
1 change: 0 additions & 1 deletion App/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def __init__(self, *args, **kwargs):
# Bouwt het aantal pagina's op als wordt ingegeven.
tk.Tk.__init__(self, *args, **kwargs)


self.title('Growth Curve app')
screenWidth = self.winfo_screenwidth()
screenHeight = self.winfo_screenheight()
Expand Down
32 changes: 19 additions & 13 deletions Code/CSV_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def readd(self, filepath: str) -> list:
A list containing two lists, which are the time and the cells growth lists.
"""
tijd_lijst, cellen_lijst = [], []
cellen_index,tijd_index = [],[]

try:
cellen_index, tijd_index = [], []
with open(str(filepath)) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
next(csv_reader) # This skips the first row of the CSV file.
Expand All @@ -60,11 +60,15 @@ def readd(self, filepath: str) -> list:
cellen_index.append(row[1])
tijd_lijst = [float(i) for i in tijd_index]
cellen_lijst = [float(i) for i in cellen_index]
return [tijd_lijst, cellen_lijst]

except FileNotFoundError as e:
print("Unexpected error ", e)

except UnicodeDecodeError as e:
print("Unexpected error ", e)

except FileNotFoundError:
print("File not found")

return [tijd_lijst, cellen_lijst]

def bereken_growth_rate(self) -> float:
"""
Expand All @@ -86,10 +90,12 @@ def bereken_growth_rate(self) -> float:
The grawth rate would be a float number
"""
lijst_cellen, lijst_tijd = self.lijst[1], self.lijst[0]
lnN, lnN0 = lijst_cellen[-1], lijst_cellen[0]
t, t0 = lijst_tijd[-1], lijst_tijd[0]
growth_rate = (lnN - lnN0)/(t - t0)
growth_rate = 0
if self.lijst is not None:
lijst_cellen, lijst_tijd = self.lijst[1], self.lijst[0]
lnN, lnN0 = lijst_cellen[-1], lijst_cellen[0]
t, t0 = lijst_tijd[-1], lijst_tijd[0]
growth_rate = (lnN - lnN0)/(t - t0)

# lijst3 = [float(lijst_cellen[item + 1] - lijst_cellen[item]) for item in range(len(lijst_cellen) - 1)]
# growthrate = max(lijst3)
Expand All @@ -107,7 +113,7 @@ def bereken_maxcellen(self) -> list:
and the max number of cells made in CFU / ml.
"""

delta_tijd = max(self.lijst[0]) - min(self.lijst[0])
delta_cellen = max(self.lijst[1]) - min(self.lijst[1])
return [delta_tijd, delta_cellen]
if self.lijst is not None:
delta_tijd = max(self.lijst[0]) - min(self.lijst[0])
delta_cellen = max(self.lijst[1]) - min(self.lijst[1])
return [delta_tijd, delta_cellen]
6 changes: 3 additions & 3 deletions Code/EndResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def log_growth(self, bact_name: str, time: float, pH: float, temperature: float)
A list of the intervals of growth of the bacteria, that would be used by the plot of the graph
"""

ant_lijst, lijstDeath = [], []
ant_lijst, lijstDeath= [], []
beperkendeFactor = JsonChecker(bact_name, temperature, pH, "br", None)
beperkendeFactor_is = beperkendeFactor.read_value_json()
lnN0_ = JsonChecker(bact_name, temperature, pH, "bw", None)
Expand Down Expand Up @@ -297,7 +297,7 @@ def temp_growth_rate(self, bact_name: str, pH: float, end_time: float, temp_chec
beperkingsFactor = beperkingsFactor_is.read_value_json()
groei_lijst = []

for time in range(0, int(end_time)+1):
for time in range(0, int(100)+1):
tijd_lijst.append(time)
for temp in range(int(beginRange), int(eindRange)+1):
if list:
Expand All @@ -309,4 +309,4 @@ def temp_growth_rate(self, bact_name: str, pH: float, end_time: float, temp_chec
tijd_lijst.pop(0)
else:
list.append(0)
return groei_lijst
return groei_lijst
5 changes: 4 additions & 1 deletion Documentation/CSV_reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@ <h2 id="returns">Returns</h2>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
<ul>
<li><a href="EndResults.html">EndResults</a></li>
<li><a href="JsonChecker.html">JsonChecker</a></li>
</ul>
</div>
<ul id="index">
<li><h3><a href="#header-classes">Classes</a></h3>
Expand Down
6 changes: 5 additions & 1 deletion Documentation/EndResults.html
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,11 @@ <h2 id="return">Return</h2>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
<ul>
<li><a href="CSV_reader.html">CSV_reader</a></li>
<li><a href="JsonChecker.html">JsonChecker</a></li>

</ul>
</div>
<ul id="index">
<li><h3><a href="#header-classes">Classes</a></h3>
Expand Down
5 changes: 4 additions & 1 deletion Documentation/JsonChecker.html
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ <h2 id="returns">Returns</h2>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
<ul>
<li><a href="CSV_reader.html">CSV_reader</a></li>
<li><a href="EndResults.html">EnsResults</a></li>
</ul>
</div>
<ul id="index">
<li><h3><a href="#header-classes">Classes</a></h3>
Expand Down
16 changes: 16 additions & 0 deletions Test/test_CSV_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,37 @@ def setUp(self) -> None:
self.growth = self.testIt.bereken_growth_rate()
self.cellen = self.testIt.bereken_maxcellen()

self.testIt2 = ReadIt("C:/Users/marya/OneDrive/Bureaublad/xxx-waardes.xlsx")
self.pathread2 = ReadIt.readd(self,"C:/Users/marya/OneDrive/Bureaublad/xxx-waardes.xlsx")
self.growth2 = self.testIt2.bereken_growth_rate()
self.cellen2 = self.testIt2.bereken_maxcellen()

def tearDown(self) -> None:
self.testIt = None
self.pathread = None
self.growth = None

self.pathread2 =None
self.growth2 = None
self.cellen2 = None

def test_readd(self):
self.assertNotEqual(self.pathread, [])
self.assertNotEqual(self.pathread, None)

self.assertRaises(UnicodeDecodeError, )
self.assertNotEqual(self.pathread2, [])

def test_bereken_growthrate(self):
self.assertEqual(self.growth, 0.15266666666666673)
self.assertNotEqual(self.growth, None)
self.assertNotEqual(self.growth, [])

self.assertEqual(self.growth2, 0)

def test_bereken_maxcellen(self):
self.assertEqual(self.cellen, [15.0, 2.3199999999999985])
self.assertNotEqual(self.cellen, None)
self.assertNotEqual(self.cellen, [])

self.assertEqual(self.cellen2, None)

0 comments on commit c66dcbc

Please sign in to comment.