Best Python code snippet using localstack_python
Markov_use_bellman.py
Source: Markov_use_bellman.py
...25 self.my_map[(index_x, index_y)] = [prim_value,26 prim_action] # åå§åå°å¾27 def put_wall(self, x, y):28 self.my_map[(x, y)] = ['#', '#']29 def put_destination(self, x, y, value):30 self.my_map[(x, y)] = [value, value]31 def change_value(self, new_value):32 for index in new_value.keys():33 self.my_map[index][0] = new_value[index]34 def print_map(self):35 for index_y in range(map.y, 0, -1):36 temp = []37 for index_x in range(1, map.x + 1):38 if self.my_map[(index_x, index_y)][1] == '#':39 temp.append("#")40 elif self.my_map[(index_x, index_y)][1] == 1:41 temp.append(1)42 elif self.my_map[(index_x, index_y)][1] == -1:43 temp.append(-1)44 else:45 temp.append(self.my_map[(index_x, index_y)][1])46 print(temp)47 def print_value(self):48 for index_y in range(map.y, 0, -1):49 temp = []50 for index_x in range(1, map.x + 1):51 if self.my_map[(index_x, index_y)][1] == '#':52 temp.append("#")53 elif self.my_map[(index_x, index_y)][1] == 1:54 temp.append(1)55 elif self.my_map[(index_x, index_y)][1] == -1:56 temp.append(-1)57 else:58 temp.append(self.my_map[(index_x, index_y)][0])59 print(temp)60def up(x, y, map):61 if y + 1 <= map.y and not (map.my_map[(x, y + 1)][0] is symbol[0]):62 y += 163 return x, y64def down(x, y, map):65 if y - 1 > 0 and not (map.my_map[(x, y - 1)][0] is symbol[0]):66 y -= 167 return x, y68def left(x, y, map):69 if x - 1 > 0 and not (map.my_map[(x - 1, y)][0] is symbol[0]):70 x -= 171 return x, y72def right(x, y, map):73 if x + 1 <= map.x and not (map.my_map[(x + 1, y)][0] is symbol[0]):74 x += 175 return x, y76def make_reward(map, value):77 reward = {}78 for index_x in range(1, map.x + 1):79 for index_y in range(1, map.y + 1):80 if not (map.my_map[(index_x, index_y)][0] in symbol):81 reward[(index_x, index_y)] = value82 return reward83def bellman_function(x, y, map, reward, a1, a2, a3, b):84 array = [a1 * map.my_map[up(x, y, map)][0] + \85 a2 * map.my_map[left(x, y, map)][0] + \86 a3 * map.my_map[right(x, y, map)][0],87 # ======================88 a1 * map.my_map[down(x, y, map)][0] + \89 a2 * map.my_map[left(x, y, map)][0] + \90 a3 * map.my_map[right(x, y, map)][0],91 # ======================92 a1 * map.my_map[left(x, y, map)][0] + \93 a2 * map.my_map[up(x, y, map)][0] + \94 a3 * map.my_map[down(x, y, map)][0],95 # ======================96 a1 * map.my_map[right(x, y, map)][0] + \97 a2 * map.my_map[up(x, y, map)][0] + \98 a3 * map.my_map[down(x, y, map)][0]99 # ======================100 ]101 new_value = reward[(x, y)] + b * np.max(array)102 return new_value103def iteration_of_value(map, reward, a1, a2, a3, b):104 new_value = {}105 stop = False106 i = 0107 while not stop:108 for index_x in range(1, map.x + 1):109 for index_y in range(1, map.y + 1):110 if not (map.my_map[(index_x, index_y)][1] in symbol):111 new_value[(index_x, index_y)] = \112 round_point_five(bellman_function(index_x, index_y, map,113 reward,114 a1, a2, a3, b))115 if the_equal(new_value, map):116 stop = True117 i += 1118 # print(i)119 if i == 10000:120 stop = True121 map.change_value(new_value)122 return map123def round_point_five(num):124 return int(num * 100000) / 100000125def the_equal(new_value, map):126 result = True127 for key in new_value.keys():128 if map.my_map[key][0] != new_value[key]:129 result = False130 break131 return result132def choose_best_way(map, a1, a2, a3):133 for x in range(1, map.x + 1):134 for y in range(1, map.y + 1):135 if not (map.my_map[(x, y)][1] in symbol):136 array = [a1 * map.my_map[up(x, y, map)][0] + \137 a2 * map.my_map[left(x, y, map)][0] + \138 a3 * map.my_map[right(x, y, map)][0],139 # ======================140 a1 * map.my_map[down(x, y, map)][0] + \141 a2 * map.my_map[left(x, y, map)][0] + \142 a3 * map.my_map[right(x, y, map)][0],143 # ======================144 a1 * map.my_map[left(x, y, map)][0] + \145 a2 * map.my_map[up(x, y, map)][0] + \146 a3 * map.my_map[down(x, y, map)][0],147 # ======================148 a1 * map.my_map[right(x, y, map)][0] + \149 a2 * map.my_map[up(x, y, map)][0] + \150 a3 * map.my_map[down(x, y, map)][0]151 # ======================152 ]153 max = np.max(array)154 best_way = []155 for index in range(4):156 if array[index] == max:157 best_way.append(num_to_direction(index))158 map.my_map[(x, y)][1] = best_way159def num_to_direction(num):160 direction = ['UP', 'DOWN', 'LEFT', 'RIGHT']161 return direction[num]162if __name__ == "__main__":163 map = map(5, 5) # çæx * yå°å¾164 # æ¾ç½®éç¢165 map.put_wall(2, 2)166 map.put_wall(4, 3)167 # æ¾ç½®ç®æ å¼168 map.put_destination(5, 5, 1)169 map.put_destination(5, 4, -1)170 # 计ç®åæ¥å½æ°ï¼è¾å
¥ç为åæ¥å½æ°çå¼ï¼171 reward = make_reward(map, -1)172 # 计ç®æç»çæç¨å¼(è¾å
¥agentçå个æ¹åçæ¦çåææ£å åï¼173 map = iteration_of_value(map, reward, 0.8, 0.1, 0.1, 0.5)174 # 计ç®æä¼è·¯å¾175 choose_best_way(map, 0.8, 0.1, 0.1)176 # æå°ç¸å
³æ°æ®177 map.print_map()...
copy.py
Source: copy.py
...16 files = message['files']17 source = files['source']18 destination = files['destination']19 source_content = self.get_source(source)20 success = self.put_destination(destination, source_content)21 return success22 def get_source(self, source):23 """Get the content of the source file."""24 service, file_path = source.split(":")25 if service == "cloudfiles":26 body = self._get_from_rackspace(file_path)27 if service == "s3":28 body = self._get_from_aws(file_path)29 else:30 raise NotImplementedError31 return body32 def put_destination(self, destination, source_content):33 """Upload content to the destination."""34 service, destination_path = destination.split(":")35 if service == "s3":36 success = self._put_to_aws(destination_path, source_content)37 else:38 raise NotImplementedError39 return success40 def _get_from_rackspace(self, file_path):41 """Get the content from rackspace."""42 obj_name, container_name = self._parse_file_dir_name(file_path)43 response = self.rackspace.object_store.download_object(44 obj_name, container=container_name)45 return response46 def _get_from_aws(self, file_path):...
cli.py
Source: cli.py
...41def copy(source, destination):42 """Copy one file."""43 fc = FileCopier()44 source_content = fc.get_source(source)45 success = fc.put_destination(destination, source_content)...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!