How to use mapcat method in tox

Best Python code snippet using tox_python

self_driving.py

Source:self_driving.py Github

copy

Full Screen

...23 -1, # my_car.steering_torque24 0, # my_car.score25 0, # my_car.crash_energy26 ),27 mapcat(lambda _: (28 -1, # other_car.position_angle29 0, # other_car.position_length30 -1, # other_car.angle31 -1, # other_car.velocity_angle32 0, # other_car.velocity_length33 -1, # other_car.steering_angle34 0, # other_car.score35 0, # other_car.crash_energy36 ), range(7)),37 mapcat(lambda _: (38 -1, # obstacle.position_angle39 0 # obstacle.position_length40 ), range(OBSTACLE_COUNT)),41 mapcat(lambda _: (42 -1, # star.position_angle43 0 # star.position_length44 ), range(STAR_COUNT)),45 )), dtype=np.float32),46 np.array(tuple(concat(47 (48 1, # my_car.position.x49 1, # my_car.position.y50 1, # my_car.angle51 1, # my_car.velocity_angle52 1, # my_car.velocity_length53 1, # my_car.steering_angle54 1, # my_car.steering_torque55 1, # my_car.score56 1, # my_car.crash_energy57 ),58 mapcat(lambda _: (59 1, # other_car.position_angle60 1, # other_car.position_length61 1, # other_car.angle62 1, # other_car.velocity_angle63 1, # other_car.velocity_length64 1, # other_car.steering_angle65 1, # other_car.score66 1, # other_car.crash_energy67 ), range(7)),68 mapcat(lambda _: (69 1, # obstacle.position_angle70 1 # obstacle.position_length71 ), range(OBSTACLE_COUNT)),72 mapcat(lambda _: (73 1, # star.position_angle74 1 # star.position_length75 ), range(STAR_COUNT)),76 )), dtype=np.float32),77 dtype=np.float3278 )79 self.screen = None80 self.reset()81 @classmethod82 def _create_observation(cls, game):83 def get_values(observation):84 return concat(85 flatten(observation['my_car'].values()), # Vec2dにはxとyの2要素があるので、flattenしておきます。86 mapcat(methodcaller('values'), sorted(observation['other_cars'], key=itemgetter('position_length'))), # 距離が近い順にソートします。前後も分けたほうが良い?87 mapcat(methodcaller('values'), sorted(observation['obstacles' ], key=itemgetter('position_length'))), # noqa: E20288 mapcat(methodcaller('values'), sorted(observation['stars' ], key=itemgetter('position_length'))) # noqa: E20289 )90 observation = (91 np.array(tuple(get_values(game.create_observation(game.cars[0]))), np.float32) / # noqa: W50492 np.array(tuple(concat(93 (94 1000, # my_car.position.x95 1000, # my_car.position.y96 np.pi, # my_car.angle97 np.pi, # my_car.velocity_angle98 MAX_SPEED / FPS, # my_car.velocity_length99 np.pi, # my_car.steering_angle100 10, # my_car.steering_torque101 30, # my_car.score102 10 * FPS, # my_car.crash_energy103 ),104 mapcat(lambda _: (105 np.pi, # other_car.position_angle106 1000, # other_car.position_length107 np.pi, # other_car.angle108 np.pi, # other_car.velocity_angle109 MAX_SPEED / FPS * 2, # other_car.velocity_length110 np.pi, # other_car.steering_angle111 30, # other_car.score112 10 * FPS, # other_car.crash_energy113 ), range(7)),114 mapcat(lambda _: (115 np.pi, # obstacle.position_angle116 1000 # obstacle.position_length117 ), range(OBSTACLE_COUNT)),118 mapcat(lambda _: (119 np.pi, # star.position_angle120 1000 # star.position_length121 ), range(STAR_COUNT)),122 )), dtype=np.float32)123 )124 observation[observation < -1] = -1125 observation[observation > 1] = 1 # noqa: E222126 return observation127 def reset(self):128 self.game = Game((self,), self._seed)129 return self._create_observation(self.game)130 @classmethod131 def _calc_car_and_star_distance(cls, game, car):132 return min(map(lambda star: (star.position - car.position).length, game.stars))...

Full Screen

Full Screen

self_driving_2.py

Source:self_driving_2.py Github

copy

Full Screen

...23 -1, # my_car.steering_torque24 0, # my_car.score25 0, # my_car.crash_energy26 ),27 mapcat(lambda _: (28 -1, # other_car.position_angle29 0, # other_car.position_length30 -1, # other_car.angle31 -1, # other_car.velocity_angle32 0, # other_car.velocity_length33 -1, # other_car.steering_angle34 0, # other_car.score35 0, # other_car.crash_energy36 ), range(7)),37 mapcat(lambda _: (38 -1, # obstacle.position_angle39 0 # obstacle.position_length40 ), range(OBSTACLE_COUNT)),41 mapcat(lambda _: (42 -1, # star.position_angle43 0 # star.position_length44 ), range(STAR_COUNT)),45 )), dtype=np.float32),46 np.array(tuple(concat(47 (48 1, # my_car.position.x49 1, # my_car.position.y50 1, # my_car.angle51 1, # my_car.velocity_angle52 1, # my_car.velocity_length53 1, # my_car.steering_angle54 1, # my_car.steering_torque55 1, # my_car.score56 1, # my_car.crash_energy57 ),58 mapcat(lambda _: (59 1, # other_car.position_angle60 1, # other_car.position_length61 1, # other_car.angle62 1, # other_car.velocity_angle63 1, # other_car.velocity_length64 1, # other_car.steering_angle65 1, # other_car.score66 1, # other_car.crash_energy67 ), range(7)),68 mapcat(lambda _: (69 1, # obstacle.position_angle70 1 # obstacle.position_length71 ), range(OBSTACLE_COUNT)),72 mapcat(lambda _: (73 1, # star.position_angle74 1 # star.position_length75 ), range(STAR_COUNT)),76 )), dtype=np.float32),77 dtype=np.float3278 )79 self.screen = None80 self.reset()81 @classmethod82 def _create_observation(cls, game):83 def get_values(observation):84 return flatten(concat(85 observation['my_car'].values(),86 mapcat(methodcaller('values'), sorted(observation['other_cars'], key=itemgetter('position_length'))), # 距離が近い順にソートします。前後も分けたほうが良い?87 mapcat(methodcaller('values'), sorted(observation['obstacles' ], key=itemgetter('position_length'))), # noqa: E20288 mapcat(methodcaller('values'), sorted(observation['stars' ], key=itemgetter('position_length'))) # noqa: E20289 ))90 observation = (91 np.array(tuple(get_values(game.create_observation(game.cars[0]))), np.float32) / # noqa: W50492 np.array(tuple(concat(93 (94 1000, # my_car.position.x95 1000, # my_car.position.y96 np.pi, # my_car.angle97 np.pi, # my_car.velocity_angle98 MAX_SPEED / FPS, # my_car.velocity_length99 np.pi, # my_car.steering_angle100 10, # my_car.steering_torque101 30, # my_car.score102 10 * FPS, # my_car.crash_energy103 ),104 mapcat(lambda _: (105 np.pi, # other_car.position_angle106 1000, # other_car.position_length107 np.pi, # other_car.angle108 np.pi, # other_car.velocity_angle109 MAX_SPEED / FPS * 2, # other_car.velocity_length110 np.pi, # other_car.steering_angle111 30, # other_car.score112 10 * FPS, # other_car.crash_energy113 ), range(7)),114 mapcat(lambda _: (115 np.pi, # obstacle.position_angle116 1000 # obstacle.position_length117 ), range(OBSTACLE_COUNT)),118 mapcat(lambda _: (119 np.pi, # star.position_angle120 1000 # star.position_length121 ), range(STAR_COUNT)),122 )), dtype=np.float32)123 )124 observation[observation < -1] = -1125 observation[observation > 1] = 1 # noqa: E222126 return observation127 def reset(self):128 self.game = Game((self,), self._seed)129 return self._create_observation(self.game)130 @classmethod131 def _calc_car_and_star_distance(cls, game, car):132 return min(map(lambda star: (star.position - car.position).length, game.stars))...

Full Screen

Full Screen

dependencies_visitors.py

Source:dependencies_visitors.py Github

copy

Full Screen

...25 assert deep_level >= 0, deep_level26 return result27# Specific visitors28def visit_boolean_expression(node):29 return mapcat(visit_node, node['operands'])30def visit_comparaison(node):31 return mapcat(visit_node, (node['left_operand'], node['right_operand']))32def visit_dans(node):33 return visit_node(node['expression'])34def visit_float(node):35 return []36def visit_formula(node):37 formula_name = node['name']38 dependencies = pipe(39 visit_node(node['expression']),40 unique,41 list,42 )43 return (formula_name, dependencies)44def visit_function_call(node):45 return mapcat(visit_node, node['arguments'])46def visit_integer(node):47 return []48def visit_loop_expression(node):49 return mapcat(visit_node, iter_unlooped_nodes(50 loop_variables_nodes=node['loop_variables'],51 node=node['expression'],52 ))53def visit_pour_formula(node):54 return map(visit_node, iter_unlooped_nodes(55 loop_variables_nodes=node['loop_variables'],56 node=node['formula'],57 unloop_keys=['name'],58 ))59def visit_product_expression(node):60 return mapcat(visit_node, node['operands'])61def visit_regle(node):62 return mapcat(63 lambda node1: visit_node(node1) if node1['type'] == 'pour_formula' else [visit_node(node1)],64 node['formulas'],65 )66def visit_sum_expression(node):67 return mapcat(visit_node, node['operands'])68def visit_symbol(node):69 return [node['value']]70def visit_ternary_operator(node):71 return pipe([72 visit_node(node['value_if_true']),73 visit_node(node['condition']),74 visit_node(node['value_if_false']) if 'value_if_false' in node else None,75 ],76 filter(None),77 concat,78 )79def visit_unary(node):...

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