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


Python PubsubManagementServiceProcessClient.find_stream_definition方法代码示例

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


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

示例1: LastUpdateCache

# 需要导入模块: from interface.services.dm.ipubsub_management_service import PubsubManagementServiceProcessClient [as 别名]
# 或者: from interface.services.dm.ipubsub_management_service.PubsubManagementServiceProcessClient import find_stream_definition [as 别名]
class LastUpdateCache(TransformDataProcess):
    def __init__(self, *args, **kwargs):
        super(LastUpdateCache, self).__init__()
        self.def_cache = {}


    def on_start(self):

        super(LastUpdateCache, self).on_start()


        self.couch_config = self.CFG.get('couch_storage')

        #self.datastore_name = self.couch_config.get('datastore_name','dm_cache')
        self.datastore_name = CACHE_DATASTORE_NAME


        try:
            self.datastore_profile = getattr(DataStore.DS_PROFILE,self.couch_config.get('datastore_profile','SCIDATA'))
        except AttributeError:
            self.datastore_profile = DataStore.DS_PROFILE.SCIDATA

        self.db = self.container.datastore_manager.get_datastore(ds_name=self.datastore_name,
            profile=self.datastore_profile)

        self.ps_cli = PubsubManagementServiceProcessClient(process=self)



    def process(self, packet):

        if isinstance(packet,StreamGranuleContainer):
            granule = packet
            lu = self.db._ion_object_to_persistence_dict(self.get_last_value(granule))
            try:
                doc = self.db.read_doc(granule.stream_resource_id)
                doc_id = doc.id
                doc_rev = doc.rev

            except NotFound:
                log.debug('Creating...')
                doc_id, doc_rev = self.db.create_doc(lu,object_id=granule.stream_resource_id)
            lu['_id'] = doc_id
            lu['_rev'] = doc_rev

            self.db.update_doc(lu)


        else:
            log.info('Unknown packet type %s' % str(type(packet)))

        return

    def get_last_value(self,granule):

        stream_resource_id = granule.stream_resource_id
        if not self.def_cache.has_key(stream_resource_id):
            stream_def = self.ps_cli.find_stream_definition(stream_id=stream_resource_id, id_only=False)
            self.def_cache[stream_resource_id] = stream_def.container

        definition = self.def_cache[stream_resource_id]

        psp = PointSupplementStreamParser(stream_definition=definition, stream_granule=granule)
        fields = psp.list_field_names()


        lu = LastUpdate()
        lu.timestamp = granule.identifiables[granule.data_stream_id].timestamp.value
        for field in fields:
            range_id = definition.identifiables[field].range_id
            lu.variables[field] = Variable()
            if definition.identifiables.has_key(field):
                lu.variables[field].definition = definition.identifiables[field].definition
            if definition.identifiables.has_key(range_id):
                lu.variables[field].units = definition.identifiables[range_id].unit_of_measure.code
            lu.variables[field].value = float(psp.get_values(field_name=field)[-1])
        return lu
开发者ID:seman,项目名称:coi-services,代码行数:79,代码来源:last_update_cache.py


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