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


Python Dependency.call_find_entities_raw方法代码示例

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


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

示例1: CustomAnalyticsLoader

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import call_find_entities_raw [as 别名]

#.........这里部分代码省略.........
            for company_id_2 in company_sql_ids:

                # add a competition record for every away company with the away company's weight
                competitors.append(Competitor.simple_init(company_id_1, company_id_2, company_weights[company_id_2], datetime.datetime(1900, 1, 1), None))

        # map companies to itself
        map(add_competitor_map, company_sql_ids)

        # insert the competitors
        company_competition_handler.insert_company_competition(competitors, self.target_db_name)



    # ---------------------------- Private ---------------------------- #


    def _get_normalized_store_dates(self, opened_date, closed_date, sorted_company_time_periods, time_period_dates):

        # init the store has being opened on the first date and never closed
        new_opened_date = None
        new_closed_date = None

        # if the passed in opened date is null, just assume it was open in the first time period
        if opened_date is None:
            new_opened_date = time_period_dates[sorted_company_time_periods[0]["label"]]

        # loop through all the company's time periods
        for index, tp in enumerate(sorted_company_time_periods):

            # get date helpers
            current_date = tp["date"]

            # if new opened date hasn't been set and it's before this time period, set it
            if new_opened_date is None and opened_date <= current_date:
                new_opened_date = time_period_dates[tp["label"]]

                # if we set the opened date, and closed date is null, than just break
                if closed_date is None:
                    break

                # this is an edge case.  If end_date is also before the current date, than something is wrong and this store doesn't belong
                # in that case, return null's for both
                elif closed_date <= current_date:
                    return None, None

            # if store closed before or on this date, than mark this date as the closed date
            elif closed_date and current_date >= closed_date:
                new_closed_date = time_period_dates[tp["label"]]

                # assume that this is it, no need to continue the loop
                break


        # this is a check to fix a bug that was found (RET 3476)
        if new_opened_date == new_closed_date:

            # this should never happen and making it none will make sure the store doesn't get inserted
            return None, None

        return new_opened_date, new_closed_date


    def _get_non_null_sorted_dates(self, time_period_dates):

        # filter out None values
        time_period_dates = filter(lambda value: value, time_period_dates)

        # make them into dates
        time_period_dates = [self._fast_date_parser.parse_date(date_str) for date_str in time_period_dates]

        # sort by date and return
        return sorted(time_period_dates)


    def _get_date_query(self, time_period_dates):

        # get sorted, non null dates
        time_period_dates = self._get_non_null_sorted_dates(time_period_dates)

        # if there's only one value, find all live stores during that time
        if len(time_period_dates) == 1:

            return time_interval_helper.active_as_of_analytics_date(time_period_dates[0])

        # otherwise, return the range of the first-last date
        else:
            dates = [time_period_dates[0], time_period_dates[-1]]
            return { "$or": time_interval_helper.live_entity_filter(dates, "interval", "$lte", "$gte") }


    def _query_stores(self, query):

        # create mds params
        entity_fields = ["_id", "data.street_number", "data.street", "data.city", "data.state", "data.zip", "data.suite", "data.phone",
                         "data.latitude", "data.longitude", "data.shopping_center", "data.store_opened_date", "data.store_closed_date",
                         "data.store_id"]
        params = self.mds_params.create_params(resource = "find_entities_raw", query = query, entity_fields = entity_fields)["params"]

        # run query
        return self.mds_access.call_find_entities_raw("trade_area", params)
开发者ID:erezrubinstein,项目名称:aa,代码行数:104,代码来源:custom_analytics_loader.py


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