Esempio n. 1
0
    def waring(self, bact_naam: str, temperature: float, pH: float, aw: float):
        """
        In deze functie wordt de input(entries) waardes gecheckt, met behulp van de json bestand en class JsonChecker

        """
        waring_ = ""
        try:
            bact_naam = str(bact_naam)
            temperature = float(temperature)
            pH = float(pH)
            aw = float(aw)
        except ValueError:
            waring_ += ""

        try:
            with open("../Extra bestanden/" + bact_naam + ".json", "r") as f:
                info = json.load(f)
        except FileNotFoundError:
            waring_ += " bacterie naam , "

        temp_check = JsonChecker(bact_naam, temperature, pH, "temp",
                                 temperature)
        temp_check_terug = temp_check.values_check()

        ph_check = JsonChecker(bact_naam, temperature, pH, "ph", pH)
        ph_check_terug = ph_check.values_check()

        aw_check = JsonChecker(bact_naam, temperature, pH, "aw", aw)
        aw_check_terug = aw_check.values_check()

        if temp_check_terug is None: waring_ += "tempratuur ,"
        if ph_check_terug is None: waring_ += "pH , "
        if aw_check_terug is None: waring_ += "water activiteit, "
        return waring_
    def __new__(cls, bact_naam: str, temp_input: float, ph_input: float,
                aw: float, end_time: float, type_graph: int) -> list:
        """
        Constructs based, got everything the same except that in the this method there is a return of the answer.
        Based on the type equation that the user chooses, calls a function.

        Raises
        --------
        ValueError
                when the check of the ph and the temperature returns a None

        Return
        --------
            list
                A list of the intervals of growth of the bacteria, that would be used by the plot of the graph

        """
        temp_check = JsonChecker(bact_naam, temp_input, ph_input, "temp",
                                 temp_input)
        temp_check_terug = temp_check.values_check()

        ph_check = JsonChecker(bact_naam, temp_input, ph_input, "ph", ph_input)
        ph_check_terug = ph_check.values_check()

        aw_check = JsonChecker(bact_naam, temp_input, ph_input, "aw", aw)
        aw_check_terug = aw_check.values_check()

        antwoord = 0
        try:
            if (temp_check_terug and ph_check_terug
                    and aw_check_terug) is not None:
                if type_graph == 1:
                    antwoord = cls.logistic(cls, bact_naam, end_time, ph_input,
                                            temp_input)
                if type_graph == 2:
                    antwoord = cls.logstic_curve(cls, bact_naam, end_time,
                                                 ph_input, temp_input)
                if type_graph == 3:
                    antwoord = cls.log_growth(cls, bact_naam, end_time,
                                              ph_input, temp_input)
                if type_graph == 4:
                    antwoord = cls.temp_growth_rate(cls, bact_naam, ph_input,
                                                    end_time, temp_check_terug)

                return antwoord
        except ValueError as e:
            print("incorrect type of value was entered", e)
Esempio n. 3
0
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)