How to use put_record method in localstack

Best Python code snippet using localstack_python

game.py

Source:game.py Github

copy

Full Screen

...142 record = []143 time_left = app.game_round_time144 p1.reset_with(0, app.game_p1_initial_position)145 p2.reset_with(1, app.game_p2_initial_position)146 def put_record(action: str, **kwargs):147 record.append({148 'action': action, 'time': time_left,149 'p1': {'health': p1.health, 'position': p1.position},150 'p2': {'health': p2.health, 'position': p2.position},151 **kwargs})152 while time_left >= 0:153 try:154 p1a = p1.get_action(p2, match_records, time_left)155 except ScriptException:156 if raise_:157 raise158 p1_failed = True159 else:160 p1_failed = False161 try:162 p2a = p2.get_action(p1, match_records, time_left)163 except ScriptException:164 if raise_:165 raise166 p2_failed = True167 else:168 p2_failed = False169 if p1_failed and p2_failed:170 put_record('both_error')171 return None, record172 elif p1_failed:173 put_record('p1_error')174 return 1, record175 elif p2_failed:176 put_record('p2_error')177 return 0, record178 p1.last_inflicted_damage = 0179 p2.last_inflicted_damage = 0180 p1_idle = True181 p2_idle = True182 if p1a is Action.forward:183 if p2.position > p1.position:184 p1.position += 1185 put_record('p1_forward')186 p1_idle = False187 elif p1a is Action.backward:188 if p1.position >= p1.initial_position - 2:189 p1.position -= 1190 put_record('p1_backward')191 p1_idle = False192 if p2a is Action.forward:193 if p2.position > p1.position:194 p2.position -= 1195 put_record('p2_forward')196 p2_idle = False197 elif p2a is Action.backward:198 if p2.position <= p2.initial_position + 2:199 p2.position += 1200 put_record('p2_backward')201 p2_idle = False202 if p1a is Action.punch:203 if p1.distance(p2) > 0:204 put_record('p1_punch_unreachable')205 elif p2a is Action.crouch:206 p2.guard_count += 2207 put_record('p1_punch_avoid')208 elif p2a is Action.guard:209 damage = random.randrange(*app.game_hit_point_guard_range)210 p2.guard_count += 1211 p1.inflict_damage(p2, damage)212 put_record('p1_punch_guard', damage=damage)213 else:214 damage = random.randrange(*app.game_hit_point_range)215 p1.inflict_damage(p2, damage)216 put_record('p1_punch', damage=damage)217 p1_idle = False218 elif p1a is Action.kick:219 if p1.distance(p2) > 0:220 put_record('p1_kick_unreachable')221 elif p2a is Action.jump:222 p2.guard_count += 2223 put_record('p1_kick_avoid')224 elif p2a is Action.guard:225 damage = random.randrange(*app.game_hit_point_guard_range)226 p2.guard_count += 1227 p1.inflict_damage(p2, damage)228 put_record('p1_kick_guard', damage=damage)229 else:230 damage = random.randrange(*app.game_hit_point_range)231 p1.inflict_damage(p2, damage)232 put_record('p1_kick', damage=damage)233 p1_idle = False234 if p2.health <= 0:235 put_record('p1_victory_ko')236 return 0, record237 if p2a is Action.punch:238 if p2.distance(p1) > 0:239 put_record('p2_punch_unreachable')240 elif p1a is Action.crouch:241 p1.guard_count += 2242 put_record('p2_punch_avoid')243 elif p1a is Action.guard:244 damage = random.randrange(*app.game_hit_point_guard_range)245 p1.guard_count += 1246 p2.inflict_damage(p1, damage)247 put_record('p2_punch_guard', damage=damage)248 else:249 damage = random.randrange(*app.game_hit_point_range)250 p2.inflict_damage(p1, damage)251 put_record('p2_punch', damage=damage)252 p2_idle = False253 elif p2a is Action.kick:254 if p2.distance(p1) > 0:255 put_record('p2_kick_unreachable')256 elif p1a is Action.jump:257 p1.guard_count += 2258 put_record('p2_kick_avoid')259 elif p1a is Action.guard:260 damage = random.randrange(*app.game_hit_point_guard_range)261 p1.guard_count += 1262 p2.inflict_damage(p1, damage)263 put_record('p2_kick_guard', damage=damage)264 else:265 damage = random.randrange(*app.game_hit_point_range)266 p2.inflict_damage(p1, damage)267 put_record('p2_kick', damage=damage)268 p2_idle = False269 if p1.health <= 0:270 put_record('p2_victory_ko')271 return 1, record272 if p1_idle and p2_idle:273 put_record('idle')274 time_left -= 1275 if time_left < 0:276 time_left = 0277 if p1.health == p2.health:278 put_record('draw')279 return None, record280 elif p1.health > p2.health:281 put_record('p1_victory_time_over')282 return 0, record283 else:284 put_record('p2_victory_time_over')285 return 1, record286def run_matches(app: App,287 p1: typing.Union[Agent, str],288 p2: typing.Union[Agent, str],289 raise_: bool=False):290 data = []291 wins = [0, 0]292 if isinstance(p1, str):293 p1a = ExternalScriptAgent(app, p1)294 elif not isinstance(p1, Agent):295 raise TypeError('p1 should be an agent or a string')296 else:297 p1a = p1298 if isinstance(p2, str):...

Full Screen

Full Screen

put_to_firehose.py

Source:put_to_firehose.py Github

copy

Full Screen

1import boto32import json3from fake_web_events import Simulation4client = boto3.client("firehose")5def put_record(event):6 data = json.dumps(event) + "\n"7 response = client.put_record(8 DeliveryStreamName="firehose-production-raw-delivery-stream",9 Record={"Data": data},10 )11 print(event)12 return response13simulation = Simulation(user_pool_size=100, sessions_per_day=1000)14events = simulation.run(duration_seconds=10000)15for event in events:...

Full Screen

Full Screen

put_resources_in_kinesys.py

Source:put_resources_in_kinesys.py Github

copy

Full Screen

1import boto32import json3from fake_web_events import Simulation4client = boto3.client('firehose')5def put_record(ev):6 data = json.dumps(ev) + "\n"7 response = client.put_record(8 DeliveryStreamName='kinesis-firehose-tony',9 Record={"Data": data}10 )11 print(ev)12 return response13simulation = Simulation(user_pool_size=100, sessions_per_day=10000)14events = simulation.run(duration_seconds=300)15for event in events:...

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