How to use check_iteration method in autotest

Best Python code snippet using autotest_python

main.py

Source:main.py Github

copy

Full Screen

1INCODE_MATRIX = [[10, -3, -2, -1],2 [3, 10, -3, -2],3 [2, 3, 10, -3],4 [1, 2, 3, 10]]56INCODE_F_VECTOR = [31, -17, 49, -19]78# globalne zmienne do sprawdzania (ro)zbieżności metody9divergence_counter = 010last_diff_check = 99999911check_iteration = 1121314def get_sq_matrix(n):15 """16 funkcja zwraca macierz o rozmiarze NxN utworzoną17 z danych wprowadzanych przez użytkownika1819 :param n: integer20 :return: list[n][n]21 """22 matrix = []23 print("Wprowadź współczynniki układu równań: ")24 for i in range(1, n+1):25 row = []26 for j in range(1, n+1):27 prompt = "a" + str(i) + str(j) + ": "28 row.append(int(input(prompt)))29 matrix.append(row)30 return matrix313233def get_start_vector(n):34 """35 funkcja zwraca wektor wstepnego przybliżenia utworzony36 z podanych przez użytkownika danych3738 :param n: int39 :return: list[n]40 """41 vector = []42 print("Wprowadź wektor wstępnych przybliżeń rozwiązania: ")43 for i in range(1, n+1):44 prompt = "x" + str(i) + ": "45 vector.append(int(input(prompt)))46 return vector474849def get_f_vector(n):50 """51 funkcja zwraca wektor f utworzony z podanych przez użytkownika danych5253 :param n: int54 :return: list[n]55 """56 vector = []57 print("Wprowadź wektor f: ")58 for i in range(1, n + 1):59 prompt = "f" + str(i) + ": "60 vector.append(int(input(prompt)))61 return vector626364def define_size():65 """66 funkcja zwraca podany przez użytkownika rozmiar macierzy6768 :return: n69 """70 return int(input("Zdefiniuj rozmiar macierzy (NxN): "))717273def make_choice():74 """75 funkcja pozwala użytkownikowi wybrać czy chce skorzystać76 z macierzy wpisanej do programu, czy podać nową samemu7778 :return: boolean79 """80 print("Czy chcesz użyć własnej macierzy? (T/N)")81 ans = ""82 while ans not in ["t", "n"]:83 ans = input().lower()84 return "t" in ans858687def display(vector, precision):88 """89 funkcja wyświetla wyniki działania programu9091 :param vector: list[n][n]92 :param precision: float93 :return: None94 """95 print(f"Przybliżenie rozwiązania układu z precyzją = {precision}")96 for i in range(len(vector)):97 print(f"x{i+1} = {round(vector[i], 5)}")9899100def divergence_check(prev, curr):101 """102 funkcja sprawdza czy metoda jest rozbieżna dla podanego układu równań103104 :param prev:105 :param curr:106 :return:107 """108 global last_diff_check109 global divergence_counter110 global check_iteration111 divergence_list = []112 for i in range(len(curr)):113 divergence_list.append(abs(prev[i] - curr[i]))114 current_max_divergence = max(divergence_list)115 print("p", check_iteration, " = ", round(current_max_divergence, 10), sep="")116 check_iteration += 1117 if current_max_divergence <= last_diff_check:118 last_diff_check = current_max_divergence119 divergence_counter = 0120 else:121 last_diff_check = current_max_divergence122 divergence_counter += 1123 if divergence_counter >= 5:124 print("Metoda jest rozbieżna dla podanego układu równań")125 exit()126127128def check_precision(prev, curr, acc):129 """130 funkcja sprawdza czy kolejna iteracja osiągnęła wymagane przybliżenie131132 :param prev: list[n]133 :param curr: list[n]134 :param acc: float135 :return: boolean136 """137 divergence_check(prev, curr)138 results = []139 for i in range(len(curr)):140 results.append(abs(prev[i] - curr[i]) > acc)141 for element in results:142 if element:143 return True144 else:145 return False146147148def gauss_seidl(matrix, f_vector, x_vector, precision):149 """150 funkcja przybliża z zadaną dokładnością rozwiązanie układu151 równań na podstawie macierzy współczynników,152 wektora f oraz wektora wstępnych przybliżeń rozwiązania153154 :param matrix: list[n][n]155 :param f_vector: list[n]156 :param x_vector: list[n]157 :param precision: float158 :return: list[n]159 """160 counter = 1161 previous_vector = x_vector.copy()162 try:163 for i in range(len(x_vector)):164 if i == 0:165 frac_top = -sum([matrix[i][j] * x_vector[j] for j in range(i + 1, len(x_vector))]) + f_vector[i]166 x_vector[i] = frac_top / matrix[i][i]167 else:168 right_side = -sum([matrix[i][j] * x_vector[j] for j in range(0, i)])169 left_side = -sum([matrix[i][j] * x_vector[j] for j in range(i + 1, len(x_vector))]) + f_vector[i]170 x_vector[i] = (right_side - left_side) / matrix[i][i]171 while check_precision(previous_vector, x_vector, precision):172 previous_vector = x_vector.copy()173 for i in range(len(x_vector)):174 if i == 0:175 frac_top = -sum([matrix[i][j] * x_vector[j] for j in range(i+1, len(x_vector))]) + f_vector[i]176 x_vector[i] = frac_top / matrix[i][i]177 else:178 right_side = -sum([matrix[i][j] * x_vector[j] for j in range(0, i)])179 left_side = -sum([matrix[i][j] * x_vector[j] for j in range(i+1, len(x_vector))]) + f_vector[i]180 x_vector[i] = (right_side - left_side)/matrix[i][i]181 counter += 1182 except ZeroDivisionError:183 print("Macierz zawiera zera na przekątnej, uruchom program jeszcze raz zamieniając kolejność wierszy.")184 exit()185 print("Wykonano iteracji:", counter)186 return x_vector187188189def main():190 print("Program używa metody Gaussa-Seidla do przybliżenia rozwiązania układu równań z zadaną dokładnością.")191 if make_choice():192 matrix_size = define_size()193 matrix = get_sq_matrix(matrix_size)194 f_vector = get_f_vector(matrix_size)195 x_vector = get_start_vector(matrix_size)196 else:197 matrix = INCODE_MATRIX.copy()198 f_vector = INCODE_F_VECTOR.copy()199 x_vector = get_start_vector(len(matrix))200 precision = float(input("Zadaj dokładność: "))201 approximation = gauss_seidl(matrix, f_vector, x_vector, precision)202 display(approximation, precision)203204205if __name__ == '__main__': ...

Full Screen

Full Screen

inet.py

Source:inet.py Github

copy

Full Screen

...68 logger.info("Loaded data from {}".format(data_file))69 return result70 def _scrape_html(self):71 for k, v in self.data.items():72 if self.check_iteration(v.get('iteration')):73 url = v['website']74 try:75 v['html'] = self.html_scraper.scrape(url)76 logger.info("Stored html for {}".format(url))77 except TypeError:78 logger.warn("No html stored for {}".format(url))79 v['html'] = None80 def _scrape_twitter_handles(self):81 for k, v in self.data.items():82 if self.check_iteration(v.get('iteration')):83 url = v['website']84 try:85 for html in v.get('html'):86 v['twitter_handles'] = self.html_scraper.twitter_handles(html) # noqa87 logger.info("Found {} twitter handles in {}"88 .format(len(v.get('twitter_handles', [])), url)) # noqa89 except TypeError:90 logger.warn("No twitter handles stored for {}".format(url))91 v['twitter_handles'] = None92 def twitter_followers(self):93 for k, v in self.data.items():94 if self.check_iteration(v.get('iteration')):95 v['twitter_followers'] = self.twitter_handler.followers(v['twitter_handles']) # noqa96 def twitter_following(self):97 for k, v in self.data.items():98 if self.check_iteration(v.get('iteration')):99 v['twitter_following'] = self.twitter_handler.following(v['twitter_handles']) # noqa100 def mutual_follows(self):101 for k, v in self.data.items():102 v['mutual_follows'] = {}103 if self.check_iteration(v.get('iteration')):104 for handle in v['twitter_followers']:105 followers = v['twitter_followers'][handle]106 following = v['twitter_following'][handle]107 mutual_set = set(followers).intersection(following)108 mutual_list = list(mutual_set)109 v['mutual_follows'][handle] = mutual_list110 def _get_company_data(self):111 for k, v in self.data.items():112 if self.check_iteration(v.get('iteration')):113 v['company_data'] = self.ch_client.get_company_data(k, v)114 def _shared_directors(self):115 for k, v in self.data.items():116 if self.check_iteration(v.get('iteration')):117 self.data[k]['directors'] = self.ch_client.get_directors(k, v)118 def check_iteration(self, iteration):119 return iteration == self._iteration120 def start(self, iterations=1):121 """Start the iteration process.122 Starts the iteration process that expands the original seed123 data.124 Parameters125 ----------126 iterations: int, default 5127 Number of iterations to complete128 Returns129 -------130 None131 """132 logger.info("Starting data crawl. Number of iterations is {}"...

Full Screen

Full Screen

euler52.py

Source:euler52.py Github

copy

Full Screen

1iteration_works = False2i = 03def check_iteration(i):4 stuff5while not iteration_works:6 i += 17 if check_iteration(i):8 iteration_works = True...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful