Beispiel #1
0
    def read_settings():

        # Default settings
        pi_algorithm = PiAlgorithmType.BBP
        alpha_approximation_algorithm = AlphaAlgorithmType.Newton
        precision = 11

        settings = None

        try:
            settings = ET.parse(SettingsManager.__get_file_path())
        except Exception:
            errormsg = "Unable to open settings file. Running the default settings."
            print(errormsg)
            raise IOError(errormsg)

        if settings != None:
            settings_root = settings.getroot()

            if settings_root != None:
                # Reading pi settings from the XML
                pi_element = settings_root.find("pi")
                pi_algorithm_text = ""

                if pi_element != None:
                    pi_algorithm_elem = pi_element.find("algorithm")
                    if pi_algorithm_elem != None:
                        pi_algorithm_text = pi_algorithm_elem.text

                if pi_algorithm_text != "":
                    pi_algorithm = PiAlgorithmType[pi_algorithm_text]

                # Reading alpha settings from the XML : alpha approximation algorithm
                alpha_elemet = settings_root.find("alpha")
                alpha_algorithm_text = ""
                precision_text = ""

                if alpha_elemet != None:
                    alpha_algorithm_elem = alpha_elemet.find("algorithm")
                    if alpha_algorithm_elem != None:
                        alpha_algorithm_text = alpha_algorithm_elem.text

                    # Reading alpha settings from the XML : precision of calculation
                    precision_element = alpha_elemet.find("precision")
                    if precision_element != None:
                        precision_text = precision_element.text

                if alpha_algorithm_text != "":
                    alpha_approximation_algorithm = AlphaAlgorithmType[
                        alpha_algorithm_text]

                if precision_text != "":
                    precision = int(precision_text)

        conditions = CalculationConditions(pi_algorithm,
                                           alpha_approximation_algorithm,
                                           precision)
        return conditions
Beispiel #2
0
 def test_length_10dp_r1000_000_accuracy(self):
     """Test for coaster radius = 1,000,000."""
     print("Test for coaster radius = 1,000,000")
     conditions = CalculationConditions(PiAlgorithmType.BBP,
                                        AlphaAlgorithmType.Newton, 10)
     radius = 1000000
     result = OverlapCalculator.calculate_overlapping_length(
         radius, conditions)
     self.assertTrue(
         almosteq(result.get_overlapping_length(),
                  mpmathify("1192054.49341826", strings=True), 1e-10))
     print("=======================")
Beispiel #3
0
 def test_length_10dp_r1_precision(self):
     """Checking if the results repeat under the same conditions."""
     print("Test for coaster radius = 1")
     conditions = CalculationConditions(PiAlgorithmType.BBP,
                                        AlphaAlgorithmType.Newton, 10)
     radius = 1
     result = OverlapCalculator.calculate_overlapping_length(
         radius, conditions)
     self.assertTrue(
         almosteq(result.get_overlapping_length(),
                  mpmathify("1.1920544934", strings=True), 1e-10))
     print("=======================")
Beispiel #4
0
 def test_length_20dp_r0_000019_accuracy(self):
     """Test for coaster radius = 0.000019 with the precision of 20 ."""
     print("Test for coaster radius = 0.000019 with the precision of 20")
     conditions = CalculationConditions(PiAlgorithmType.BBP,
                                        AlphaAlgorithmType.Newton, 20)
     radius = mpmathify("0.000019", strings=True)
     result = OverlapCalculator.calculate_overlapping_length(
         radius, conditions)
     self.assertTrue(
         almosteq(result.get_overlapping_length(),
                  mpmathify("0.0000226490353746183460458808", strings=True),
                  1e-20))
     print("=======================")
Beispiel #5
0
    def __save(self):
        """Saves the changes on the xml file"""
        try:
            precision = self.__txt_precision.get()
            self.__validate_input(precision)

            pi_algorithm = PiAlgorithmType[self.__pi_algorithm_var.get()]
            alpha_algorithm = AproximationAlgorithmType[
                self.__alpha_algorithm_var.get()]

            conditions = CalculationConditions(pi_algorithm, alpha_algorithm,
                                               int(precision))
            self.__settings = conditions
            self.__exit()
        except ValidationException as err:
            self.__handleError(err)
Beispiel #6
0
    def __read_settings(self):
        # Default algorithm to calculate pi
        pi_algorithm = PiAlgorithmType.BBP
        alpha_approximation_algorithm = AlphaAlgorithmType.Newton
        precision = 11

        conditions = None

        try:
            conditions = SettingsManager.read_settings()
        except IOError as err:
            conditions = CalculationConditions(pi_algorithm,
                                               alpha_approximation_algorithm,
                                               precision)
            messagebox.showwarning(title="Warning",
                                   message=err,
                                   parent=self.__main_form)

        return conditions