def logistic(self, bact_name: str, time: float, pH: float, temperature: float) -> list: """ This formula calculates the growth of the bacteria based on the logistics formula. Here the growth is calculated until reaching the limiting factor. Using the formula: y(t) = limiting factor/ (1+ initial value* exp^(-growth rate *t )) Return -------- List A list of the intervals of growth of the bacteria, that would be used by the plot of the graph """ ant_lijst = [] groeisFcator = EndResults.new_growth_rate(self, bact_name, pH, temperature) beperkendeFactor = JsonChecker(bact_name, temperature, pH, "br", None) beperkendeFactor_is = beperkendeFactor.read_value_json() begingValue_is = JsonChecker(bact_name, None, None, "bw", None) begingValue = begingValue_is.read_value_json() for t in range(0, int(time)): ant = (beperkendeFactor_is[0] / (1 + begingValue[0] * np.exp(-groeisFcator * t))) if ant <= beperkendeFactor_is[0]: ant_lijst.append(ant) return ant_lijst
def temp_growth_rate( self, bact_name: str, pH: float, end_time: float, temp_check: list, ) -> list: """ This formula calculates the growth factor per temperature difference. the temperature rises one grade up every hour, until the max temperature is reached. The temperatures are shown on the x-axis and the growth factors on the y-axis. Using the function : new_growth_rate Return ------ list A list with growth factors that were calculated in the algorithm """ beginRange, eindRange = 0, 0 list = [] tijd_lijst = [] if temp_check is not None: if len(temp_check) == 3: beginRange = temp_check[0] eindRange = temp_check[2] + 1 elif len(temp_check) == 2: beginRange = temp_check[0] eindRange = temp_check[1] + 1 elif len(temp_check) == 1: beginRange = temp_check[0] eindRange = temp_check[0] + 1 begingValue_is = JsonChecker(bact_name, None, None, "bw", None) begingValue = begingValue_is.read_value_json() beperkingsFactor_is = JsonChecker(bact_name, None, None, "br", None) beperkingsFactor = beperkingsFactor_is.read_value_json() groei_lijst = [] for time in range(0, int(100) + 1): tijd_lijst.append(time) for temp in range(int(beginRange), int(eindRange) + 1): if list: if list[-1] <= beperkingsFactor[0]: if tijd_lijst: groeisFactor = EndResults.new_growth_rate( self, bact_name, pH, temp) groei_lijst.append(groeisFactor) list.append(beperkingsFactor[0] / (1 + begingValue[0] * np.exp(-groeisFactor * tijd_lijst[0]))) tijd_lijst.pop(0) else: list.append(0) return groei_lijst
def new_growth_rate(self, bact_name: str, pH: float, temperature: float) -> list: """ Here the growth factor is calculated at a certain temperature and ph value. Using the CTPM equation : μ max (T, pH) = CTPM(T, pH) = μ opt t(T)* p(pH) t(T)= (T - T MAX)(T - T MIN)**2 / (T opt 2 T min) [(Topt - Tmin)(T - Topt) - (Topt - Tmax) (Topt + Tmin - 2T)] p(pH) = (pH - pH min) (pH - pH max)/(pH - pH min)(pH - pH max) - (pH - pH opt) **2 Return -------- Float A float of the new growth rate """ temp_check = JsonChecker(bact_name, temperature, pH, "temp", temperature) temp_waardes = temp_check.read_value_json() ph_check = JsonChecker(bact_name, temperature, pH, "ph", pH) pH_waardes = ph_check.read_value_json() groeisFcator = JsonChecker(bact_name, temperature, pH, "gr", None) groeisFcator_is = groeisFcator.read_value_json() # max growth rate(T, pH) = CTPM(T, pH)= optimum growth rate t(T) p(pH) # temerature t(T) # de noemer stukje 1 tt = ((temp_waardes[1] - temp_waardes[0]) * (temperature - temp_waardes[1]) - (temp_waardes[1] - temp_waardes[2]) * (temp_waardes[1] + temp_waardes[0] - 2 * temperature)) # de noemer stukje 2 tt2 = ((temp_waardes[1] - temp_waardes[0]) * tt) # de teller tt3 = ((temperature - temp_waardes[2]) * (temperature - temp_waardes[0])**2 / tt2) # pH p(pH) # de noemer phh = ((pH - pH_waardes[0]) * (pH - pH_waardes[2]) - (pH - pH_waardes[1])**2) # de teller phh2 = ((pH - pH_waardes[0]) * (pH - pH_waardes[2]) / phh) # new groei factor newgroeiFactor = groeisFcator_is[0] * tt3 * phh2 return newgroeiFactor
def logstic_curve(self, bact_name: str, time: float, pH: float, temperature: float) -> list: """ This formula use the logistic formula to calculate the growth until the limiting factor. Then it would calculate the death phase of the bacteria. Return -------- List A list of the intervals of growth of the bacteria, that would be used by the plot of the graph """ list = EndResults.logistic(self, bact_name, time, pH, temperature) groeisFcator = EndResults.new_growth_rate(self, bact_name, pH, temperature) beperkendeFactor = JsonChecker(bact_name, temperature, pH, "br", None) beperkendeFactor_is = beperkendeFactor.read_value_json() lijstDeath = [] lijstDeath.append(list[-1]) while lijstDeath[-1] > list[0]: # zolang de deathwaarde grooter of glijk is aan de beginwaarde van de groei is: antwoord = lijstDeath[-1] - (groeisFcator * len(lijstDeath)) if beperkendeFactor_is[0] >= antwoord >= list[0]: # als de antwoord niet gelijk of groter aan de beperkende factor is lijstDeath.append(antwoord) else: lijstDeath.append(list[0]) break for item in lijstDeath: list.append(item) return list
class TestJsonChecker(TestCase): def setUp(self) -> None: #tempratuur testen self.readeersteFile_temp = JsonChecker(bacteria_name="xx", temperature=10, pH=10, item="temp", inputWaarde=10) self.readeersteFile_temp_O2 = JsonChecker(bacteria_name="xx", temperature=4, pH=10, item="temp", inputWaarde=4) self.readeersteFile_temp_O3 = JsonChecker(bacteria_name="xx", temperature=37, pH=10, item="temp", inputWaarde=37) self.readeersteFile_temp_O4 = JsonChecker(bacteria_name="xx", temperature=45, pH=10, item="temp", inputWaarde=45) self.readeersteFile_temp_O5 = JsonChecker(bacteria_name="xx", temperature=50, pH=10, item="temp", inputWaarde=50) self.readeersteFile_temp1 = self.readeersteFile_temp.read_value_json() self.readeersteFile_temp_2 = self.readeersteFile_temp.values_check() self.readeersteFile_temp_O2_1 = self.readeersteFile_temp_O2.values_check( ) self.readeersteFile_temp_O3_1 = self.readeersteFile_temp_O3.values_check( ) self.readeersteFile_temp_O4_1 = self.readeersteFile_temp_O4.values_check( ) self.readeersteFile_temp_O5_1 = self.readeersteFile_temp_O5.values_check( ) #ph testen self.readeersteFile_pH = JsonChecker(bacteria_name="xx", temperature=10, pH=10, item="ph", inputWaarde=10) self.readeersteFile_pH_O2 = JsonChecker(bacteria_name="xx", temperature=10, pH=3.5, item="ph", inputWaarde=3.5) self.readeersteFile_pH_O3 = JsonChecker(bacteria_name="xx", temperature=10, pH=5, item="ph", inputWaarde=5) self.readeersteFile_pH_O4 = JsonChecker(bacteria_name="xx", temperature=10, pH=4.5, item="ph", inputWaarde=4.5) self.readeersteFile_pH_O5 = JsonChecker(bacteria_name="xx", temperature=10, pH=20, item="ph", inputWaarde=20) self.readeersteFile_pH1 = self.readeersteFile_pH.read_value_json() self.readeersteFile_pH2 = self.readeersteFile_pH.values_check() self.readeersteFile_pH_O2_1 = self.readeersteFile_pH_O2.values_check() self.readeersteFile_pH_O3_1 = self.readeersteFile_pH_O3.values_check() self.readeersteFile_pH_O4_1 = self.readeersteFile_pH_O4.values_check() self.readeersteFile_pH_O5_1 = self.readeersteFile_pH_O5.values_check() #aw_testen self.readeersteFile_aw = JsonChecker(bacteria_name="xx", temperature=10, pH=10, item="aw", inputWaarde=10) self.readeersteFile_aw_1 = self.readeersteFile_aw.read_value_json() def tearDown(self) -> None: self.readeersteFile_temp1 = None self.readeersteFile_temp_2 = None self.readeersteFile_temp_O2_1 = None self.readeersteFile_pH1 = None self.readeersteFile_pH2 = None self.readeersteFile_pH_O2_1 = None def test_read_json(self): # temp lezen self.assertEqual(self.readeersteFile_temp1, [6.0, 37.0, 45.0]) # ph lezen self.assertEqual(self.readeersteFile_pH1, [4.0, 5.0, 10.0]) #aw lezen self.assertEqual(self.readeersteFile_aw_1, [0.85]) def test_value_check(self): #temp check # temp is grooter dan de min en kleiner dan de optimum self.assertEqual(self.readeersteFile_temp_2, [10.0, 37, 45.0]) # temp is kleiner dan de min self.assertRaises(Exception, self.readeersteFile_temp_O2_1) # temp is gelijk aan de optimum self.assertEqual(self.readeersteFile_temp_O3_1, [37.0, 45.0]) # tep is gelijk aan de max self.assertEqual(self.readeersteFile_temp_O4_1, [45.0]) # temp is grooter dan de max self.assertRaises(Exception, self.readeersteFile_temp_O5_1) # ph check # ph is gelijk aan de max self.assertEqual(self.readeersteFile_pH2, [10.0]) # ph is kleiner dan de min self.assertRaises(Exception, self.readeersteFile_pH_O2_1) # ph is gelijk aan de optimum self.assertEqual(self.readeersteFile_pH_O3_1, [5.0, 10.0]) # ph is kleiner dan de optimum en groter dan de min self.assertEqual(self.readeersteFile_pH_O4_1, [4.5, 5.0, 10.0]) # ph is grooter dan de max self.assertEqual(self.readeersteFile_pH_O5_1, None)
def findJson(input): """ De input van de gebruiker wordt naar deze functie doorgestuurd om vervolgens de bijhornde info in de json bestand op te zoeken. Er wordt ook een foto van de bacterie laten zien als het bestaat. Voor het gevaal dat de gebruiker een bacterienaam invoert die niet in de json bestanden bestaat, gebruik ik een try except """ try: with open("../Extra bestanden/" + str(input) + ".json", "r") as f: info = json.load(f) informatieVanJson = info["info"] infoUitprinten = tk.Label(frameMideen, text="", font='Arial 18 ', bg=bg_background, fg=fg) fotolabel = tk.Label( frameMideen, text="Foto van de bacterie", bg=bg_background, fg="#FFEEDD", ) naamUitprinten = tk.Label(frameMideen, text=str(input), font='Arial 20 bold', bg=bg_background, fg=fg) omstandigheden = tk.Label(frameMidenMiden, text="\nOmgevingsfactoren", font='Arial 20 bold', bg=bg_background, fg=fg) infoUitprinten.config(text=informatieVanJson) omstandigheden.pack(side=tk.LEFT, fill=tk.X, padx=5, ancho="nw") items = ["temp", "ph", "aw"] for item in items: maxminInfo = tk.Label(frameMidenMiden, text="", font='Arial 18 ', bg=bg_background, fg=fg) jsonjsno = JsonChecker(str(input), None, None, item, None) maxenmin = jsonjsno.read_value_json() if len(maxenmin) == 3: maxminInfo.config( text= f"De {str(item)} waarde is:\n de maximum gelijk aan {str(maxenmin[2])} garde" f" \nde mimium is gelijk aan {str(maxenmin[0])} grade\n en de optimum waarde is" f": {str(maxenmin[1])} grade.") maxminInfo.pack(side=tk.LEFT, fill=tk.X, padx=5, ancho="nw") else: maxminInfo.config( text= f"De {str(item)} waarde is :\n {str(maxenmin[0])} grade.\n\n" ) maxminInfo.pack(side=tk.BOTTOM, fill=tk.X, padx=5, ancho="nw") print(maxenmin) naamUitprinten.pack(side=tk.LEFT, fill=tk.X, padx=5, ancho="nw") infoUitprinten.pack(side=tk.LEFT, fill=tk.X, padx=5, ancho="nw") except FileNotFoundError: messagebox.showwarning( "", "We hebben geen informatie over die bacterie kunnen vinden" ) 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")
def log_growth(self, bact_name: str, time: float, pH: float, temperature: float) -> list: """ This function calculates the growth of the bactria on the basis of 4 phases: Lag phase, logarithmic phase, the stationary phase and the death phase. Using this equation: Ln N -Ln N0 = μ *(t-t0) where: μ stands for the growth rate per h^-1 N stands for the number of CFU / ml at time t N0 stands for the initial number of CFU / ml at time t0 t stands for time Parameters ---------- bact_naam: String The name of a bacteria time: Float The user input of end time pH: Float The user input of the PH temperature: Float The user input for the temperature ant_lijst: List The list where the results of the algorithm are stored Return -------- List A list of the intervals of growth of the bacteria, that would be used by the plot of the graph """ 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) lnN0 = lnN0_.read_value_json() ant_lijst.append(lnN0[0]) # de specfieke groeifactor uitrekenen newgroeiFactor = EndResults.new_growth_rate(self, bact_name, pH, temperature) for t in range(0, int(time) + 1): lnN = (newgroeiFactor * t) + lnN0[0] if lnN < beperkendeFactor_is[0]: ant_lijst.append(lnN) else: ant_lijst.append(beperkendeFactor_is[0]) lijstDeath.append(ant_lijst[-1]) if ant_lijst[-1] == beperkendeFactor_is[0]: while lijstDeath[-1] >= lnN0[0]: antwoord = lijstDeath[-1] - (newgroeiFactor * len(lijstDeath)) if antwoord >= lnN0[0]: lijstDeath.append(antwoord) else: lijstDeath.append(lnN0[0]) break for item in lijstDeath: ant_lijst.append(item) return ant_lijst