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


Python Dependency.create_params方法代码示例

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


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

示例1: CustomAnalyticsLoader

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import create_params [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

示例2: MDSParamsBuilderTests

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import create_params [as 别名]
class MDSParamsBuilderTests(MoxTestBase):
    def setUp(self):
        # call super init
        super(MDSParamsBuilderTests, self).setUp()
        
        # register mox dependencies
        register_common_mox_dependencies(self.mox)

        # get mocked params builder
        self.mds_params_builder = Dependency("CoreAPIParamsBuilder").value.mds


    def tearDown(self):
        dependencies.clear()


    def test_mds_params_interval_filter__one_date(self):
        # get params with one date
        date = datetime(2013, 1, 1)
        interval_filter = {
            "dates": [date]
        }
        params = self.mds_params_builder.create_params(resource = "find_entities_raw", interval_filter = interval_filter)

        # verify it gets created correctly
        self.assertEqual(params["params"]["interval_filter"], interval_filter)

        # make sure you get an error if the field isn't a date
        self.assertRaises(ServiceParamsError, self.mds_params_builder.create_params, resource = "find_entities_raw", interval_filter = str(date))


    def test_mds_params_interval_filter__two_date(self):
        # get params with one date
        date = datetime(2013, 1, 1)
        interval_filter = {
            "dates": [date, date]
        }
        params = self.mds_params_builder.create_params(resource = "find_entities_raw", interval_filter = interval_filter)

        # verify it gets created correctly
        self.assertEqual(params["params"]["interval_filter"], interval_filter)

        # make sure you get an error if the field isn't a date
        self.assertRaises(ServiceParamsError, self.mds_params_builder.create_params, resource = "find_entities_raw", interval_filter = str(date))


    def test_mds_params_interval_filter__date_range(self):
        # get params with two dates
        date_from = datetime(2012, 1, 1)
        date_to = datetime(2013, 1, 1)
        interval_filter = {
            "date_range": [date_from, date_to]
        }
        params = self.mds_params_builder.create_params(resource = "find_entities_raw", interval_filter = interval_filter)

        # verify it gets created correctly
        self.assertEqual(params["params"]["interval_filter"], interval_filter)

        # make sure you get an error if there are more or less than 2 parameters
        interval_filter["date_range"] = [date_from, date_to, date_from]
        self.assertRaises(ServiceParamsError, self.mds_params_builder.create_params, resource = "find_entities_raw", interval_filter = interval_filter)
        interval_filter["date_range"] = [date_from]
        self.assertRaises(ServiceParamsError, self.mds_params_builder.create_params, resource = "find_entities_raw", interval_filter = interval_filter)

        # make sure you get an error if either of the parameters is not a date
        interval_filter["date_range"] = [str(date_from), date_to]
        self.assertRaises(ServiceParamsError, self.mds_params_builder.create_params, resource = "find_entities_raw", interval_filter = [str(date_from), date_to])
        interval_filter["date_range"] = [date_from, str(date_to)]
        self.assertRaises(ServiceParamsError, self.mds_params_builder.create_params, resource = "find_entities_raw", interval_filter = [date_from, str(date_to)])
开发者ID:erezrubinstein,项目名称:aa,代码行数:71,代码来源:test_mds_params_builder.py

示例3: MainTestCollection

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import create_params [as 别名]
class MainTestCollection(ServiceTestCollection):

    def initialize(self):

        self.user_id = '[email protected]'
        self.source = "main_test_collection.py"
        self.context = {"user_id": self.user_id, "source": self.source}
        self.remote_dirs = ['integration_test_files/', 'integration_test_files/chuck_norris/']
        self.local_dir = 'implementation/data/'
        self.main_params = Dependency("CoreAPIParamsBuilder").value
        self.store_helper = StoreHelper()

    def setUp(self):
        if "MAIN" in self.test_case.apps:
            self.main_access.call_delete_reset_database()
        if "MDS" in self.test_case.apps:
            self.mds_access.call_delete_reset_database()
        if "RDS" in self.test_case.apps:
            self.rds_access.call_delete_reset_database()
        if "WFS" in self.test_case.apps:
            self.wfs_access.call_delete_reset_database()

    def tearDown(self):
        pass

    ##------------------------------------------------##

    def main_test_get_entity_type_summary(self):

        company_id1 = insert_test_company()
        company_id2 = insert_test_company()
        company_id3 = insert_test_company()
        company_id4 = insert_test_company()

        main_summary = self.main_access.call_get_entity_type_summary("company")
        mds_summary = self.mds_access.call_get_entity_type_summary("company")
        self.test_case.assertEqual(main_summary, mds_summary)

    def main_test_get_entity_summary(self):

        company_id = insert_test_company()

        main_summary = self.main_access.call_get_entity_summary("company", company_id)
        mds_summary = self.mds_access.call_get_entity_summary("company", company_id)
        self.test_case.assertEqual(main_summary, mds_summary)

    def main_test_get_data_entities(self):

        company_ids = [insert_test_company(), insert_test_company(), insert_test_company(), insert_test_company()]

        fields = ["_id", "entity_type", "name", "data.ticker"]
        params = self.main_params.create_params(resource = "get_data_entities", fields = fields)
        companies = self.main_access.call_get_data_entities("company", params = params["params"])["rows"]

        self.test_case.assertEqual(len(companies), 4)
        for company in companies:
            self.test_case.assertIn(company["_id"], company_ids)
            self.test_case.assertEqual(company["name"], "UNITTESTCOMPANY")
            self.test_case.assertEqual(company["entity_type"], "company")
            self.test_case.assertEqual(company["data.ticker"], "")

    def main_test_get_data_entity_relationships(self):

        company_ids = [insert_test_company(), insert_test_company(), insert_test_company(), insert_test_company()]
        rir_ids = [insert_test_rir(self.context, company_id) for company_id in company_ids]

        for i in range(4):
            self.mds_access.call_add_link("company", company_ids[i], "company", "retail_input_record", rir_ids[i], "retail_input_record",
                                          "retail_input", self.context)

        fields = ["to._id", "to.entity_type", "to.name", "to.data.ticker",
                  "from._id", "from.entity_type", "from.name", "from.data.company_id"]
        params = self.main_params.create_params(resource = "get_data_entity_relationships", fields = fields)
        rels = self.main_access.call_get_data_entity_relationships("retail_input_record", "company", params = params["params"])["rows"]

        self.test_case.assertEqual(len(rels), 4)
        for rel in rels:
            self.test_case.assertIn(rel["to._id"], company_ids)
            self.test_case.assertEqual(rel["to.name"], "UNITTESTCOMPANY")
            self.test_case.assertEqual(rel["to.entity_type"], "company")
            self.test_case.assertEqual(rel["to.data.ticker"], "")
            self.test_case.assertIn(rel["from._id"], rir_ids)
            self.test_case.assertEqual(rel["from.name"], "UNIT_TEST_RIR")
            self.test_case.assertEqual(rel["from.entity_type"], "retail_input_record")
            self.test_case.assertIn(rel["from.data.company_id"], company_ids)

    def main_test_timing_1(self):

        self.logger.info("** Running main_test_timing_1")

        # Timing test 1: N entities, each linked to N entities of the same type

        # Get the original number of entities of the chosen type
        entity_type = self.test_case.tests["MDS"].entity_types[1]
        num_entities_orig = self.test_case.tests["MDS"].count_entities(entity_type)
        self.logger.info("Number of entities: %d", num_entities_orig)

        # Generate a complete graph of new entities
        num_entities = 20
        entity_ids = self.test_case.tests["MDS"].generate_complete_entity_graph(entity_type, num_entities)
#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:main_test_collection.py


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