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


Python StaticDataSourceConfiguration.by_id方法代码示例

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


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

示例1: handle

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
    def handle(self, file_path, *args, **options):
        domain = 'icds-cas'

        data_source_id = StaticDataSourceConfiguration.get_doc_id(domain, PERSON_TABLE_ID)
        config = StaticDataSourceConfiguration.by_id(data_source_id)
        adapter = get_indicator_adapter(config)
        session_helper = connection_manager.get_session_helper(adapter.engine_id)
        person_table_name = get_table_name(domain, PERSON_TABLE_ID)
        awc_location_table_name = get_table_name(domain, AWC_LOCATION_TABLE_ID)
        session = session_helper.Session

        with open(
            os.path.join(os.path.dirname(__file__), 'sql_scripts', 'nos_of_deaths.sql'),
            encoding='utf-8'
        ) as f:
            sql_script = f.read()
            rows = session.execute(
                sql_script % {
                    'person_table_name': person_table_name,
                    'awc_location_table_name': awc_location_table_name
                }
            )

            with open(file_path, 'w', encoding='utf-8') as file_object:
                writer = csv.writer(file_object)
                writer.writerow([
                    'State',
                    'District',
                    'AWC',
                    'Month',
                    'Deaths',
                ])
                writer.writerows(rows)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:35,代码来源:nos_of_deaths.py

示例2: rebuild_indicators

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
def rebuild_indicators(indicator_config_id):
    is_static = indicator_config_id.startswith(StaticDataSourceConfiguration._datasource_id_prefix)
    if is_static:
        config = StaticDataSourceConfiguration.by_id(indicator_config_id)
    else:
        config = DataSourceConfiguration.get(indicator_config_id)
        # Save the start time now in case anything goes wrong. This way we'll be
        # able to see if the rebuild started a long time ago without finishing.
        config.meta.build.initiated = datetime.datetime.utcnow()
        config.save()

    adapter = IndicatorSqlAdapter(config)
    adapter.rebuild_table()

    couchdb = _get_db(config.referenced_doc_type)
    relevant_ids = get_doc_ids(config.domain, config.referenced_doc_type, database=couchdb)

    for doc in iter_docs(couchdb, relevant_ids, chunksize=500):
        try:
            # save is a noop if the filter doesn't match
            adapter.save(doc)
        except DataError as e:
            logging.exception("problem saving document {} to table. {}".format(doc["_id"], e))

    if not is_static:
        config.meta.build.finished = True
        config.save()
开发者ID:johan--,项目名称:commcare-hq,代码行数:29,代码来源:tasks.py

示例3: copy_ucr_datasources

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
    def copy_ucr_datasources(self):
        datasource_map = {}
        datasources = get_datasources_for_domain(self.existing_domain)
        for datasource in datasources:
            datasource.meta.build.finished = False
            datasource.meta.build.initiated = None

            old_id, new_id = self.save_couch_copy(datasource, self.new_domain)
            datasource_map[old_id] = new_id
        for static_datasource in StaticDataSourceConfiguration.by_domain(self.existing_domain):
            table_id = static_datasource.get_id.replace(
                StaticDataSourceConfiguration._datasource_id_prefix + self.existing_domain + "-", ""
            )
            new_id = StaticDataSourceConfiguration.get_doc_id(self.new_domain, table_id)
            # check that new datasource is in new domain's list of static datasources
            StaticDataSourceConfiguration.by_id(new_id)
            datasource_map[static_datasource.get_id] = new_id
        return datasource_map
开发者ID:dimagi,项目名称:commcare-hq,代码行数:20,代码来源:clone_domain.py

示例4: rebuild_indicators

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
def rebuild_indicators(indicator_config_id):
    is_static = indicator_config_id.startswith(StaticDataSourceConfiguration._datasource_id_prefix)
    if is_static:
        config = StaticDataSourceConfiguration.by_id(indicator_config_id)
        rev = 'static'
    else:
        config = DataSourceConfiguration.get(indicator_config_id)
        rev = config._rev
        # Save the start time now in case anything goes wrong. This way we'll be
        # able to see if the rebuild started a long time ago without finishing.
        config.meta.build.initiated = datetime.datetime.utcnow()
        config.save()

    adapter = IndicatorSqlAdapter(config)

    couchdb = _get_db(config.referenced_doc_type)
    client = get_redis_client().client.get_client()
    redis_key = 'ucr_queue-{}:{}'.format(indicator_config_id, rev)

    if len(client.smembers(redis_key)) > 0:
        relevant_ids = client.smembers(redis_key)
    else:
        adapter.rebuild_table()
        relevant_ids = get_doc_ids_in_domain_by_type(config.domain, config.referenced_doc_type,
                                   database=couchdb)
        if relevant_ids:
            client.sadd(redis_key, *relevant_ids)

    for doc in iter_docs(couchdb, relevant_ids, chunksize=500):
        try:
            # save is a noop if the filter doesn't match
            adapter.save(doc)
            client.srem(redis_key, doc.get('_id'))
        except DataError as e:
            logging.exception('problem saving document {} to table. {}'.format(doc['_id'], e))

    if not is_static:
        client.delete(redis_key)
        config.meta.build.finished = True
        config.save()
开发者ID:nnestle,项目名称:commcare-hq,代码行数:42,代码来源:tasks.py

示例5: get_asha_table

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
 def get_asha_table(self, metadata):
     config = StaticDataSourceConfiguration.by_id(
         StaticDataSourceConfiguration.get_doc_id(DOMAIN, TABLE_ID)
     )
     return get_indicator_table(config, custom_metadata=metadata)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:7,代码来源:sql_data.py

示例6: _get_config_by_id

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
def _get_config_by_id(indicator_config_id):
    if is_static(indicator_config_id):
        return StaticDataSourceConfiguration.by_id(indicator_config_id)
    else:
        return DataSourceConfiguration.get(indicator_config_id)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:7,代码来源:tasks.py

示例7: get_asha_table_name

# 需要导入模块: from corehq.apps.userreports.models import StaticDataSourceConfiguration [as 别名]
# 或者: from corehq.apps.userreports.models.StaticDataSourceConfiguration import by_id [as 别名]
 def get_asha_table_name(self):
     config = StaticDataSourceConfiguration.by_id(
         StaticDataSourceConfiguration.get_doc_id(DOMAIN, TABLE_ID)
     )
     return get_table_name(config.domain, config.table_id)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:7,代码来源:sql_data.py


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