def enum_envs(): '''Enumerate all the env names of the latest version''' envs = [es.id for es in gym.envs.registration.registry.all()] def get_name(s): return s.split('-')[0] # filter out the old stuff envs = ps.reverse(ps.uniq_by(ps.reverse(envs), get_name)) # filter out the excluded envs envs = ps.difference_by(envs, EXCLUDE_ENVS, get_name) envs += INCLUDE_ENVS return envs
def s_get(cls, attr_path): ''' Method to get attribute across space via inferring agent <-> env paths. @example self.agent.agent_space.aeb_space.clock # equivalently util.s_get(self, 'aeb_space.clock') ''' from_class_name = get_class_name(cls, lower=True) from_idx = ps.find_index( SPACE_PATH, lambda s: from_class_name in (s, s.replace('_', ''))) from_idx = max(from_idx, 0) attr_path = attr_path.split('.') to_idx = SPACE_PATH.index(attr_path[0]) assert -1 not in (from_idx, to_idx) if from_idx < to_idx: path_link = SPACE_PATH[from_idx:to_idx] else: path_link = ps.reverse(SPACE_PATH[to_idx:from_idx]) res = cls for attr in path_link + attr_path: if not (get_class_name(res, lower=True) in (attr, attr.replace( '_', ''))): res = getattr(res, attr) return res
def get_channel_messages(self, channel_id: str) -> List[Dict]: channel_messages: Dict = \ self.driver.api['posts'].get_posts_for_channel(channel_id) def message_transformer(post_id: str) -> Dict: return { 'userid': channel_messages.get('posts', {}).get(post_id, {}).get('user_id'), 'content': channel_messages.get('posts', {}).get(post_id, {}).get('message'), 'timestamp': datetime.fromtimestamp( float( channel_messages.get('posts', {}).get( post_id, {}).get('create_at')) / 1000) } return sorted(_.map_(_.reverse(channel_messages.get('order')), message_transformer), key=lambda message: message.get('timestamp'))
def test_reverse(case, expected): assert _.reverse(case) == expected