How to use regions method in localstack

Best Python code snippet using localstack_python

porn.py

Source:porn.py Github

copy

Full Screen

...152 self.detected_regions[region].append(self.skin_map[_id - 1])153 # Íê³ÉËùÓÐÇøÓòºÏ²¢ÈÎÎñ£¬ºÏ²¢ÕûÀíºóµÄÇøÓò´æ´¢µ½ self.skin_regions154 self._merge(self.detected_regions, self.merge_regions)155 # ·ÖÎöƤ·ôÇøÓò£¬µÃµ½Åж¨½á¹û156 self._analyse_regions()157 return self158 # self.merge_regions µÄÔªËض¼ÊÇ°üº¬Ò»Ð© int ¶ÔÏó£¨ÇøÓòºÅ£©µÄÁбí159 # self.merge_regions µÄÔªËØÖеÄÇøÓòºÅ´ú±íµÄÇøÓò¶¼ÊÇ´ýºÏ²¢µÄÇøÓò160 # Õâ¸ö·½·¨±ãÊǽ«Á½¸ö´ýºÏ²¢µÄÇøÓòºÅÌí¼Óµ½ self.merge_regions ÖÐ161 def _add_merge(self, _from, _to):162 # Á½¸öÇøÓòºÅ¸³Öµ¸øÀàÊôÐÔ163 self.last_from = _from164 self.last_to = _to165 # ¼Ç¼ self.merge_regions µÄij¸öË÷ÒýÖµ£¬³õʼ»¯Îª -1166 from_index = -1167 # ¼Ç¼ self.merge_regions µÄij¸öË÷ÒýÖµ£¬³õʼ»¯Îª -1168 to_index = -1169 # ±éÀúÿ¸ö self.merge_regions µÄÔªËØ170 for index, region in enumerate(self.merge_regions):171 # ±éÀúÔªËØÖеÄÿ¸öÇøÓòºÅ172 for r_index in region:173 if r_index == _from:174 from_index = index175 if r_index == _to:176 to_index = index177 # ÈôÁ½¸öÇøÓòºÅ¶¼´æÔÚÓÚ self.merge_regions ÖÐ178 if from_index != -1 and to_index != -1:179 # Èç¹ûÕâÁ½¸öÇøÓòºÅ·Ö±ð´æÔÚÓÚÁ½¸öÁбíÖÐ180 # ÄÇôºÏ²¢ÕâÁ½¸öÁбí181 if from_index != to_index:182 self.merge_regions[from_index].extend(self.merge_regions[to_index])183 del(self.merge_regions[to_index])184 return185 # ÈôÁ½¸öÇøÓòºÅ¶¼²»´æÔÚÓÚ self.merge_regions ÖÐ186 if from_index == -1 and to_index == -1:187 # ´´½¨ÐµÄÇøÓòºÅÁбí188 self.merge_regions.append([_from, _to])189 return190 # ÈôÁ½¸öÇøÓòºÅÖÐÓÐÒ»¸ö´æÔÚÓÚ self.merge_regions ÖÐ191 if from_index != -1 and to_index == -1:192 # ½«²»´æÔÚÓÚ self.merge_regions ÖеÄÄǸöÇøÓòºÅ193 # Ìí¼Óµ½ÁíÒ»¸öÇøÓòºÅËùÔÚµÄÁбí194 self.merge_regions[from_index].append(_to)195 return196 # ÈôÁ½¸ö´ýºÏ²¢µÄÇøÓòºÅÖÐÓÐÒ»¸ö´æÔÚÓÚ self.merge_regions ÖÐ197 if from_index == -1 and to_index != -1:198 # ½«²»´æÔÚÓÚ self.merge_regions ÖеÄÄǸöÇøÓòºÅ199 # Ìí¼Óµ½ÁíÒ»¸öÇøÓòºÅËùÔÚµÄÁбí200 self.merge_regions[to_index].append(_from)201 return202 # ºÏ²¢¸ÃºÏ²¢µÄƤ·ôÇøÓò203 def _merge(self, detected_regions, merge_regions):204 # н¨Áбí new_detected_regions 205 # ÆäÔªËؽ«ÊÇ°üº¬Ò»Ð©´ú±íÏñËØµÄ Skin ¶ÔÏóµÄÁбí206 # new_detected_regions µÄÔªËؼ´´ú±íƤ·ôÇøÓò£¬ÔªËØË÷ÒýΪÇøÓòºÅ207 new_detected_regions = []208 # ½« merge_regions ÖеÄÔªËØÖеÄÇøÓòºÅ´ú±íµÄËùÓÐÇøÓòºÏ²¢209 for index, region in enumerate(merge_regions):210 try:211 new_detected_regions[index]212 except IndexError:213 new_detected_regions.append([])214 for r_index in region:215 new_detected_regions[index].extend(detected_regions[r_index])216 detected_regions[r_index] = []217 # Ìí¼ÓʣϵÄÆäÓàƤ·ôÇøÓòµ½ new_detected_regions218 for region in detected_regions:219 if len(region) > 0:220 new_detected_regions.append(region)221 # ÇåÀí new_detected_regions222 self._clear_regions(new_detected_regions)223 # Ƥ·ôÇøÓòÇåÀíº¯Êý224 # Ö»±£´æÏñËØÊý´óÓÚÖ¸¶¨ÊýÁ¿µÄƤ·ôÇøÓò225 def _clear_regions(self, detected_regions):226 for region in detected_regions:227 if len(region) > 30:228 self.skin_regions.append(region)229 # ·ÖÎöÇøÓò230 def _analyse_regions(self):231 # Èç¹ûƤ·ôÇøÓòСÓÚ 3 ¸ö£¬²»ÊÇÉ«Çé232 if len(self.skin_regions) < 3:233 self.message = "Less than 3 skin regions ({_skin_regions_size})".format(234 _skin_regions_size=len(self.skin_regions))235 self.result = False236 return self.result237 # ΪƤ·ôÇøÓòÅÅÐò238 self.skin_regions = sorted(self.skin_regions, key=lambda s: len(s),239 reverse=True)240 # ¼ÆËãƤ·ô×ÜÏñËØÊý241 total_skin = float(sum([len(skin_region) for skin_region in self.skin_regions]))242 # Èç¹ûƤ·ôÇøÓòÓëÕû¸öͼÏñµÄ±ÈֵСÓÚ 15%£¬ÄÇô²»ÊÇÉ«ÇéͼƬ243 if total_skin / self.total_pixels * 100 < 15:244 self.message = "Total skin percentage lower than 15 ({:.2f})".format(total_skin / self.total_pixels * 100)...

Full Screen

Full Screen

follow_wall.py

Source:follow_wall.py Github

copy

Full Screen

1#! /usr/bin/env python2'''3Author: Marco Antonio Arruda4Source: https://bitbucket.org/theconstructcore/two-wheeled-robot-motion-planning5Modified: Roberto Zegers6'''7# import ros stuff8import rospy9from sensor_msgs.msg import LaserScan10from geometry_msgs.msg import Twist11from nav_msgs.msg import Odometry12from tf import transformations13from std_srvs.srv import *14import math15active_ = False16pub_ = None # defining a global publisher17regions_ = {18 'right': 0,19 'fright': 0,20 'front': 0,21 'fleft': 0,22 'left': 0,23}24# state variable and state dictionary25state_ = 026state_dict_ = {27 0: 'find the wall',28 1: 'turn left',29 2: 'follow the wall',30}31def wall_follower_switch(req):32 global active_33 active_ = req.data34 res = SetBoolResponse()35 res.success = True36 res.message = 'Done!'37 return res38def clbk_laser(msg):39 global regions_40 # read the minimum values of each region41 # a second min is required to filter out 'inf' values, in that case 10 is used 42 regions_ = {43 'right': min(min(msg.ranges[0:143]), 10),44 'fright': min(min(msg.ranges[144:287]), 10),45 'front': min(min(msg.ranges[288:431]), 10),46 'fleft': min(min(msg.ranges[432:575]), 10),47 'left': min(min(msg.ranges[576:719]), 10),48 }49 50 #print 'Laser Callback Call!' # for debugging51 #rospy.logdebug('Laser Callback Call!')52 take_action()53def change_state(state):54 global state_, state_dict_55 if state is not state_:56 print 'Wall follower - [%s] - %s' % (state, state_dict_[state])57 state_ = state58def take_action():59 ''' obstacle avoidance logic '''60 global regions_61 regions = regions_62 msg = Twist()63 linear_x = 064 angular_z = 065 66 state_description = ''67 68 d = 0.5 # fine tune distance used to consider a region blocked as by an obstacle69 70 if regions['front'] > d and regions['fleft'] > d and regions['fright'] > d and regions['left'] > d and regions['right'] > d:71 state_description = 'case 1 - no obstacle sensed'72 print state_description # for debugging73 change_state(0) # find wall: turn CW and move ahead74 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] > d and regions['left'] > d and regions['right'] > d:75 state_description = 'case 2 - obstacle sensed only in front'76 print state_description # for debugging77 change_state(1) # turn left78 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] < d and regions['left'] > d and regions['right'] > d:79 state_description = 'case 3 - obstacle sensed only in front-right'80 print state_description # for debugging81 change_state(1) # turn left82 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] > d and regions['left'] > d and regions['right'] > d:83 state_description = 'case 4 - obstacle sensed only in front-left'84 print state_description # for debugging85 change_state(0) # find wall: turn CW and move ahead86 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] < d and regions['left'] > d and regions['right'] > d:87 state_description = 'case 5 - obstacle sensed in front and front-right'88 print state_description # for debugging89 change_state(1) # turn left90 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] > d and regions['left'] > d and regions['right'] > d:91 state_description = 'case 6 - obstacle sensed in front and front-left'92 print state_description # for debugging93 change_state(1) # turn left94 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] < d and regions['left'] > d and regions['right'] > d:95 state_description = 'case 7 - obstacle sensed in front and front-left and front-right'96 print state_description # for debugging97 change_state(1) # turn left98 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] < d and regions['left'] > d and regions['right'] > d:99 state_description = 'case 8 - obstacle sensed in front-left and front-right'100 print state_description # for debugging101 change_state(3) # move slow straight ahead102# logic block 2: 103 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] > d and regions['left'] > d and regions['right'] < d:104 state_description = 'case 9 - obstacle sensed only in right'105 print state_description # for debugging106 change_state(2) #follow the wall: keep moving straight ahead107 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] > d and regions['left'] > d and regions['right'] < d:108 state_description = 'case 10 - obstacle sensed in front and right'109 print state_description # for debugging110 change_state(1) # turn left111 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] < d and regions['left'] > d and regions['right'] < d:112 state_description = 'case 11 - obstacle sensed in front-right and right'113 print state_description # for debugging114 change_state(1) # turn left115 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] > d and regions['left'] > d and regions['right'] < d:116 state_description = 'case 12 - obstacle sensed in front-left and right'117 print state_description # for debugging118 change_state(3) # move slow straight ahead119 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] < d and regions['left'] > d and regions['right'] < d:120 state_description = 'case 13 - obstacle sensed in front, front-right and right'121 print state_description # for debugging122 change_state(1) # turn left123 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] > d and regions['left'] > d and regions['right'] < d:124 state_description = 'case 14 - obstacle sensed in front, front-left and right'125 print state_description # for debugging126 change_state(1) # turn left127 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] < d and regions['left'] > d and regions['right'] < d:128 state_description = 'case 15 - obstacle sensed in front, front-left, front-right and right'129 print state_description # for debugging130 change_state(1) # turn left131 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] < d and regions['left'] > d and regions['right'] < d:132 state_description = 'case 16 - obstacle sensed in front-left, front-right and right'133 print state_description # for debugging134 change_state(3) # move slow straight ahead135# logic block 3: 136 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] > d and regions['left'] < d and regions['right'] > d:137 state_description = 'case 17 - obstacle sensed only in left'138 print state_description # for debugging139 change_state(0) # find wall: turn CW and move ahead140 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] > d and regions['left'] < d and regions['right'] > d:141 state_description = 'case 18 - obstacle sensed in front and left'142 print state_description # for debugging143 change_state(0) # find wall: turn CW and move ahead144 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] < d and regions['left'] < d and regions['right'] > d:145 state_description = 'case 19 - obstacle sensed in front-right and left'146 print state_description # for debugging147 change_state(3) # move slow straight ahead148 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] > d and regions['left'] < d and regions['right'] > d:149 state_description = 'case 20 - obstacle sensed in front-left and left'150 print state_description # for debugging151 change_state(0) # find wall: turn CW and move ahead152 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] < d and regions['left'] < d and regions['right'] > d:153 state_description = 'case 21 - obstacle sensed in front, front-right and left'154 print state_description # for debugging155 change_state(0) # find wall: turn CW and move ahead156 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] > d and regions['left'] < d and regions['right'] > d:157 state_description = 'case 22 - obstacle sensed in front, front-left and left'158 print state_description # for debugging159 change_state(1) # turn left160 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] < d and regions['left'] < d and regions['right'] > d:161 state_description = 'case 23 - obstacle sensed in front, front-left, front-right and left'162 print state_description # for debugging163 change_state(1) # turn left164 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] < d and regions['left'] < d and regions['right'] > d:165 state_description = 'case 24 - obstacle sensed in front-left, front-right and left'166 print state_description # for debugging167 change_state(3) # move slow straight ahead168# logic block 4: 169 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] > d and regions['left'] < d and regions['right'] < d:170 state_description = 'case 25 - obstacle sensed in left and right'171 print state_description # for debugging172 change_state(3) # move slow straight ahead173 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] > d and regions['left'] < d and regions['right'] < d:174 state_description = 'case 26 - obstacle sensed in front, left and right'175 print state_description # for debugging176 change_state(1) # turn left177 elif regions['front'] > d and regions['fleft'] > d and regions['fright'] < d and regions['left'] < d and regions['right'] < d:178 state_description = 'case 27 - obstacle sensed in front-right, left and right'179 print state_description # for debugging180 change_state(1) # turn left181 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] > d and regions['left'] < d and regions['right'] < d:182 state_description = 'case 28 - obstacle sensed in front-left, left and right'183 print state_description # for debugging184 change_state(0) # find wall: turn CW and move ahead185 elif regions['front'] < d and regions['fleft'] > d and regions['fright'] < d and regions['left'] < d and regions['right'] < d:186 state_description = 'case 29 - obstacle sensed in front, front-right, left and right'187 print state_description # for debugging188 change_state(1) # turn left189 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] > d and regions['left'] < d and regions['right'] < d:190 state_description = 'case 30 - obstacle sensed in front, front-left, left and right'191 print state_description # for debugging192 change_state(0) # find wall: turn CW and move ahead193 elif regions['front'] < d and regions['fleft'] < d and regions['fright'] < d and regions['left'] < d and regions['right'] < d:194 state_description = 'case 31 - obstacle sensed in front, front-left, front-right, left and right'195 print state_description # for debugging196 change_state(4) # reverse turning left197 elif regions['front'] > d and regions['fleft'] < d and regions['fright'] < d and regions['left'] < d and regions['right'] < d:198 state_description = 'case 32 - obstacle sensed in front-left, front-right, left and right'199 print state_description # for debugging200 change_state(3) # move slow straight ahead201 202 else:203 state_description = 'unknown case'204 print 'unknown case' # for debugging205 rospy.loginfo(regions)206def find_wall():207 twistmsg = Twist()208 twistmsg.linear.x = 0.2209 twistmsg.angular.z = -0.2 # negative value equals turning CW210 return twistmsg211def drive_straight_ahead():212 twistmsg = Twist()213 twistmsg.linear.x = 0.15 214 return twistmsg215def turn_left():216 twistmsg = Twist()217 twistmsg.angular.z = 0.2 # positive value equals turning CCW218 return twistmsg219def follow_the_wall():220 global regions_221 222 twistmsg = Twist()223 twistmsg.linear.x = 0.25224 return twistmsg225def reverse_left():226 twistmsg = Twist()227 twistmsg.linear.x = -0.2228 twistmsg.angular.z = 0.2 # positive value equals turning CCW229 return twistmsg230def main():231 global pub_, active_ # to use this global variables inside main()232 233 rospy.init_node('reading_laser')234 235 pub_ = rospy.Publisher('/cmd_vel', Twist, queue_size=1)236 237 sub = rospy.Subscriber('/scan', LaserScan, clbk_laser)238 239 srv = rospy.Service('wall_follower_switch', SetBool, wall_follower_switch)240 241 rate = rospy.Rate(20)242 while not rospy.is_shutdown():243 #if not active_:244 # rate.sleep()245 # continue246 247 msg = Twist()248 if state_ == 0:249 msg = find_wall()250 print 'find wall: turn CW and move ahead'251 elif state_ == 1:252 msg = turn_left()253 print 'turn left'254 elif state_ == 2:255 msg = follow_the_wall()256 print 'follow the wall: keep moving straight ahead'257 elif state_ == 3:258 msg = drive_straight_ahead()259 print 'move slow straight ahead'260 elif state_ == 4:261 msg = reverse_left()262 print 'reverse turning left'263 pass264 265 else:266 rospy.logerr('Unknown state!')267 268 pub_.publish(msg)269 rate.sleep()270if __name__ == '__main__':...

Full Screen

Full Screen

clean_data.py

Source:clean_data.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import pandas as pd 3import os4import pickle as pkl5import csv6files = os.listdir("newdata/Health")7countries_in_edu = []8for file in files:9 if file == '.DS_Store':10 continue11 df = pd.read_csv("newdata/Health/"+file,encoding = 'utf-8')12 cols = df.columns.values13 rows = list(set(df[cols[0]].values))14 countries_in_edu = countries_in_edu +rows15countries_in_edu = list(set(countries_in_edu))16countries = []17cunt2id = {}18regions = {}19regions['Least Developed Countries (LDC)'] = []20regions['Pacific'] = []21regions['Europe'] = []22df1 = pd.read_csv("./UNSD-Methodology.csv", encoding = 'utf-8')23cols = df1.columns.values24for j,i in enumerate(df1[cols[3]].values):25 if i == 'Eswatini':26 i = 'Swaziland'27 if i == 'United States of America':28 i = 'United States'29 if i == 'Cabo Verde':30 i = 'Cape Verde'31 if i == 'Czechia':32 i = 'Czech Republic'33 if i == 'United Kingdom of Great Britain and Northern Ireland':34 i = 'United Kingdom'35 if i == u"Côte d’Ivoire":36 i = "C\xc3\xb4te d'Ivoire".decode('utf-8')37 if i not in countries_in_edu:38 continue39 countries.append(i)40 cunt2id[i]=j41 if df1.iloc[j,1] not in regions:42 regions[df1.iloc[j,1]] = [i]43 else:44 regions[df1.iloc[j,1]].append(i)45 if df1.iloc[j,4] == 'x':46 regions['Least Developed Countries (LDC)'].append(i)47 if df1.iloc[j,0] == 'Europe':48 regions['Europe'].append(i)49 if df1.iloc[j,2] == df1.iloc[j,2]:50 if df1.iloc[j,2] not in regions:51 regions[df1.iloc[j,2]] = [i]52 else:53 regions[df1.iloc[j,2]].append(i)54 if df1.iloc[j,0]=='Oceania':55 regions['Pacific'].append(i)56regions['Eastern and Southern Africa'] = regions ['Eastern Africa'] + regions ['Southern Africa']57regions['Western and Central Africa'] = regions['Western Africa'] + regions['Middle Africa']58regions['Middle East and North Africa'] = regions['Northern Africa'] + regions['Western Asia']59regions['East Asia and Pacific'] = regions['South-eastern Asia'] + regions['Eastern Asia'] +regions['Pacific']60regions['CEE/CIS'] =regions['Europe'] + regions['Central Asia']61regions ['South Asia'] =regions['Southern Asia']62regions['Least Developed Countries/Territories']=regions['Least Developed Countries (LDC)']63regions['Latin America and Caribbean']=regions['Latin America and the Caribbean']64for file in files:65 if file == '.DS_Store':66 continue67 print file68 df = pd.read_csv("newdata/Health/"+file,encoding = 'utf-8')69 cols = df.columns.values70 rows = list(set(df[cols[0]].values))71 cunt = [i for i in rows if i in countries]72 rgns = [i for i in rows if i in regions.keys()]73 chut = [i for i in rows if i not in rgns and i not in cunt]74 print len(df.index.values)75 for region in rgns:76 region_arr = df.loc[df["Country or Area"]==region].values77 region_arr = region_arr[0][1:]78 for value in regions[region]:79 if value in cunt:80 continue81 cunt.append(value)82 new_Ar = [value]83 for v in region_arr:84 new_Ar.append(v)85 df.loc[len(df.index.values)] = new_Ar86 df = df.sort_values(by=cols[0])87 df = df.reset_index(drop=True)88 rows =df[cols[0]].values89 final = []90 todrop = []91 for j,row in enumerate(rows):92 if row not in countries or row in final:93 todrop.append(j)94 else:95 final.append(row)96 df = df.drop(todrop)97 print len(df.index.values),'done'98 df.to_csv("newdata/health2/"+file,encoding = 'utf-8',index=False)99# countries = sorted(countries,key=str.lower)[9:]100# for i in countries:...

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 localstack 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