当前位置: 首页>>代码示例>>Python>>正文


Python IonObject.computed_list方法代码示例

本文整理汇总了Python中pyon.public.IonObject.computed_list方法的典型用法代码示例。如果您正苦于以下问题:Python IonObject.computed_list方法的具体用法?Python IonObject.computed_list怎么用?Python IonObject.computed_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyon.public.IonObject的用法示例。


在下文中一共展示了IonObject.computed_list方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_computed_events

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import computed_list [as 别名]
    def _get_computed_events(self, events, add_usernames=True, include_events=False):
        """
        Get events for use in extended resource computed attribute
        @retval ComputedListValue with value list of 4-tuple with Event objects
        """
        events = events or []

        ret = IonObject(OT.ComputedEventListValue)
        ret.value = events
        ret.computed_list = [get_event_computed_attributes(event, include_event=include_events) for event in events]
        ret.status = ComputedValueAvailability.PROVIDED

        if add_usernames:
            try:
                actor_ids = {evt.actor_id for evt in events if evt.actor_id}
                log.debug("Looking up UserInfo for actors: %s" % actor_ids)
                if actor_ids:
                    userinfo_list, assoc_list = self.clients.resource_registry.find_objects_mult(actor_ids,
                                                                                                 predicate=PRED.hasInfo,
                                                                                                 id_only=False)
                    actor_map = {assoc.s: uinfo for uinfo, assoc in zip(userinfo_list, assoc_list)}

                    for evt, evt_cmp in zip(events, ret.computed_list):
                        ui = actor_map.get(evt.actor_id, None)
                        if ui:
                            evt_cmp["event_summary"] += " [%s %s]" % (ui.contact.individual_names_given, ui.contact.individual_name_family)

            except Exception as ex:
                log.exception("Cannot find user names for event actor_ids")

        return ret
开发者ID:MatthewArrott,项目名称:coi-services,代码行数:33,代码来源:user_notification_service.py

示例2: get_events

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import computed_list [as 别名]
    def get_events(self, resource_id='', limit=10, offset=0):
        """
        Get events for use in extended resource computed attribute
        @param resource_id str
        @param limit int
        @param offset int
        @retval ComputedListValue with value list of 4-tuple with Event objects
        """
        now = get_ion_ts()
        events = self.find_events(origin=resource_id, limit=limit, max_datetime=now, descending=True, offset=offset)
        ret = IonObject(OT.ComputedEventListValue)
        if events:
            ret.value = events
            ret.computed_list = [get_event_computed_attributes(event) for event in events]
            ret.status = ComputedValueAvailability.PROVIDED
        else:
            ret.status = ComputedValueAvailability.NOTAVAILABLE

        return ret
开发者ID:Bobfrat,项目名称:coi-services,代码行数:21,代码来源:user_notification_service.py

示例3: get_events

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import computed_list [as 别名]
    def get_events(self, resource_id='', limit=10, offset=0):
        """
        Get events for use in extended resource computed attribute
        @param resource_id str
        @param limit int
        @param offset int
        @retval ComputedListValue with value list of 4-tuple with Event objects
        """
        now = get_ion_ts()
        events = self.find_events(origin=resource_id, limit=limit, max_datetime=now, descending=True, offset=offset)
        ret = IonObject(OT.ComputedEventListValue)
        if events:
            ret.value = events
            ret.computed_list = [get_event_computed_attributes(event) for event in events]
            ret.status = ComputedValueAvailability.PROVIDED

            try:
                actor_ids = {evt.actor_id for evt in events if evt.actor_id}
                log.debug("Looking up UserInfo for actors: %s" % actor_ids)
                if actor_ids:
                    #userinfo_list, assoc_list = self.clients.resource_registry.find_objects_mult(actor_ids, id_only=False)
                    actor_map = {}
                    for actor_id in actor_ids:
                        # NOTE: This is an O(n) algorithm. Cannot use find_subjects_mult because it does not support
                        # filter by predicate. Would get too many results
                        uinfo_list, _ = self.clients.resource_registry.find_objects(actor_id, predicate=PRED.hasInfo, id_only=False)
                        if uinfo_list:
                            actor_map[actor_id] = uinfo_list[0]

                    for evt, evt_cmp in zip(events, ret.computed_list):
                        ui = actor_map.get(evt.actor_id, None)
                        if ui:
                            evt_cmp["event_summary"] += " [%s %s]" % (ui.contact.individual_names_given, ui.contact.individual_name_family)

            except Exception as ex:
                log.exception("Cannot find user names for event actor_ids")

        else:
            ret.status = ComputedValueAvailability.NOTAVAILABLE

        return ret
开发者ID:caseybryant,项目名称:coi-services,代码行数:43,代码来源:user_notification_service.py


注:本文中的pyon.public.IonObject.computed_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。