Exemplo n.º 1
0
    def test_same_distribution_after_business_addition_control_for_business(
            self):
        """Add 1,750 new businesses of sector 1 and 1000 businesses of sector 2.
        Test that the total number of businesses in each sector after the addition matches the totals specified
        in annual_business_control_totals.
        Ensure that the number of unplaced businesses after the addition is exactly 2,750 because this model
        is not responsible for placing jobs, only for creating them.
        NOTE: unplaced businesses are indicated by building_id <= 0
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_set_table_name = 'business_set'
        storage.write_table(
            table_name=business_set_table_name,
            table_data=self.business_data,
        )
        business_set = BusinessDataset(in_storage=storage,
                                       in_table_name=business_set_table_name)

        annual_employment_control_totals_data = self.annual_business_control_totals_data
        annual_employment_control_totals_data[
            "total_number_of_businesses"] = array([8750, 4000, 3000])

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=annual_employment_control_totals_data,
        )
        ect_set = EmploymentControlTotalDataset(
            in_storage=storage, in_table_name=ect_set_table_name)

        # run model
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)

        #check the total
        results = business_set.size()
        should_be = [15750]
        self.assertEqual(ma.allequal(should_be, results), True,
                         "Error in total number of businesses.")

        #check that total #businesses within each sector are close to what was set in the control_totals
        results = self.get_count_all_sectors(business_set)
        should_be = [8750.0, 4000, 3000]
        self.assertEqual(ma.allclose(results, should_be, rtol=0.00001), True)

        #check that the number of unplaced businesses is the number of new businesses created (2750)
        results = where(business_set.get_attribute("building_id") <= 0)[0].size
        should_be = [2750.0]
        self.assertEqual(ma.allclose(results, should_be, rtol=0.00001), True)
    def test_unplaced_jobs_after_job_addition_control_for_business(self):
        """The initial business table is now adjusted to include 2000 unplaced businesses.
        Add 1,750 new businesses and ensure that the number of unplaced businesses after the addition
        is exactly 3,750 because this model is not responsible for placing jobs, only for creating them.
        """
        # create and populate jobs table for model input
        add_business_data = {
            "business_id": arange(13001, 15001),
            "building_id": array(2000*[0]),
            "sector_id": array(2000*[1]),
            "activity_id": array(2000*[1]),
            "sqft": array(2000*[10]),
            "employment": array(2000*[100])
            }
        annual_employment_control_totals_data = self.annual_business_control_totals_data
        annual_employment_control_totals_data["total_number_of_businesses"] = array([10750, 3000, 3000])

        storage = StorageFactory().get_storage('dict_storage')

        business_set_table_name = 'business_set'
        storage.write_table(
            table_name=business_set_table_name,
            table_data=self.business_data
            )
        business_set = BusinessDataset(in_storage=storage, in_table_name=business_set_table_name)

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=annual_employment_control_totals_data,
            )
        ect_set = EmploymentControlTotalDataset(in_storage=storage, in_table_name=ect_set_table_name)

        business_set.add_elements(add_business_data)

        # run model with input databases
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)

        #check that there are indeed 16750 total businesses after running the model
        results = business_set.size()
        should_be = [16750]
        self.assertEqual(ma.allequal(should_be, results), True, "Error")

        #check that the number of unplaced businesses is the number of new businesses created + number of unplaced business before running model
        results = where(business_set.get_attribute("building_id")<=0)[0].size
        should_be = [3750.0]

        self.assertEqual(ma.allclose(results, should_be, rtol=0.00001), True)
    def test_same_distribution_after_business_subtraction_control_for_jobs(self):
        """Removes sector_1 and sector 15 businesses while controlling for total number of jobs.
        Test that the distribution (in %) of sector 1 and sector 15 employment across buildings before and after the subtraction are
        relatively equal.
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_table_name = 'business_set'
        storage.write_table(table_name=business_table_name, table_data=self.business_data)
        business_set = BusinessDataset(in_storage=storage, in_table_name=business_table_name)

        ect_set_table_name = 'ect_set'
        storage.write_table(table_name=ect_set_table_name, table_data=self.annual_job_control_totals_data)
        ect_set = EmploymentControlTotalDataset(in_storage=storage, in_table_name=ect_set_table_name)

        #run model 
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)
        #Check the overall employment
        results = [business_set.get_attribute('employment').sum()]
        should_be = [542000] # 140000+222000+180000 = 542000
        self.assertEqual(results[0] >= should_be[0], True, 
                         "Error in total number of jobs. Should be >= %s, is %s " % (should_be[0], results[0]))
        #The difference should be not larger than the sum of maximum business employment over sectors (-> 100 + 200 + 150) 
        self.assertEqual(ma.allclose(should_be, results, atol=450), True, 
                         "Error in total number of jobs. Should be %s (up to 450), is %s " % (should_be[0], results[0]))

        def run_model():
            storage = StorageFactory().get_storage('dict_storage')

            business_set_table_name = 'business_set'
            storage.write_table(
                table_name=business_set_table_name,
                table_data=self.business_data,
                )

            business_set = BusinessDataset(in_storage=storage, in_table_name=business_set_table_name)

            model = BusinessTransitionModel()
            model.run(year=2000, business_set=business_set, control_totals=ect_set)
            # check that the distribution of businesses is the same before and after subtracting businesses
            results = self.get_job_count_all_sectors_and_buildings(business_set)
            return results
        expected_results = array([4000.0*10/142000.0*140000, 1000*20, 1000.0*150/195000.0*180000, 2000.0/142000.0*140000, 1000*2,
                                  1000*15/195000.0*180000, 1000.0*100/142000.0*140000, 1000*200, 1000*30/195000.0*180000])


        self.run_stochastic_test(__file__, run_model, expected_results, 10)
Exemplo n.º 4
0
    def test_same_distribution_after_business_addition_and_subtraction_control_for_jobs(
            self):
        """Add new businesses of sector 1 and sector 2. Subtract all businesses of sector 15. The model
        is adding and subtracting businesses while controlling for total number of jobs.
        Test that the total number of jobs in each sector after the modification matches the totals specified
        in annual_jobs_control_totals.
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_set_table_name = 'business_set'
        storage.write_table(
            table_name=business_set_table_name,
            table_data=self.business_data,
        )
        business_set = BusinessDataset(in_storage=storage,
                                       in_table_name=business_set_table_name)

        annual_employment_control_totals_data = self.annual_job_control_totals_data
        annual_employment_control_totals_data["total_number_of_jobs"] = array(
            [150000, 500000, 0])

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=annual_employment_control_totals_data,
        )
        ect_set = EmploymentControlTotalDataset(
            in_storage=storage, in_table_name=ect_set_table_name)

        # run model
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)

        #check the total
        results = [business_set.get_attribute('employment').sum()]
        should_be = [650000]

        self.assertEqual(
            ma.allclose(should_be, results, atol=450), True,
            "Error in total number of jobs. Should be about %s, is %s." %
            (should_be[0], results[0]))

        #check that total # jobs within each sector are close to what was set in the control_totals
        results = self.get_job_count_all_sectors(business_set)
        should_be = [150000, 500000, 0]
        self.assertEqual(ma.allclose(results, should_be, atol=200), True)
    def test_same_distribution_after_business_addition_control_for_business(self):
        """Add 1,750 new businesses of sector 1 and 1000 businesses of sector 2.
        Test that the total number of businesses in each sector after the addition matches the totals specified
        in annual_business_control_totals.
        Ensure that the number of unplaced businesses after the addition is exactly 2,750 because this model
        is not responsible for placing jobs, only for creating them.
        NOTE: unplaced businesses are indicated by building_id <= 0
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_set_table_name = 'business_set'
        storage.write_table(
            table_name=business_set_table_name,
            table_data=self.business_data,
            )
        business_set = BusinessDataset(in_storage=storage, in_table_name=business_set_table_name)

        annual_employment_control_totals_data = self.annual_business_control_totals_data
        annual_employment_control_totals_data["total_number_of_businesses"] = array([8750, 4000, 3000])

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=annual_employment_control_totals_data,
            )
        ect_set = EmploymentControlTotalDataset(in_storage=storage, in_table_name=ect_set_table_name)

        # run model
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)

        #check the total
        results = business_set.size()
        should_be = [15750]
        self.assertEqual(ma.allequal(should_be, results), True, "Error in total number of businesses.")

        #check that total #businesses within each sector are close to what was set in the control_totals
        results = self.get_count_all_sectors(business_set)
        should_be = [8750.0, 4000, 3000]
        self.assertEqual(ma.allclose(results, should_be, rtol=0.00001), True)

        #check that the number of unplaced businesses is the number of new businesses created (2750)
        results = where(business_set.get_attribute("building_id")<=0)[0].size
        should_be = [2750.0]
        self.assertEqual(ma.allclose(results, should_be, rtol=0.00001), True)
    def test_same_distribution_after_business_subtraction_control_for_business(self):
        """Removes 1,750 sector_1 businesses and 500 sector 15 businesses.
        Test that the distribution (in %) of sector 1 businesses and sector 15 businesses across buildings before and after the subtraction are
        relatively equal.
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_table_name = 'business_set'
        storage.write_table(table_name=business_table_name, table_data=self.business_data)
        business_set = BusinessDataset(in_storage=storage, in_table_name=business_table_name)

        ect_set_table_name = 'ect_set'
        storage.write_table(table_name=ect_set_table_name, table_data=self.annual_business_control_totals_data)
        ect_set = EmploymentControlTotalDataset(in_storage=storage, in_table_name=ect_set_table_name)

        # unplace half of the  businesses
        business_set.modify_attribute(name="building_id", data=zeros(int(business_set.size()/2)), index=arange(int(business_set.size()/2)))
        #run model 
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)
        results = business_set.size()
        should_be = [10750]
        self.assertEqual(ma.allequal(should_be, results), True, "Error in total number of businesses.")

        def run_model():
            storage = StorageFactory().get_storage('dict_storage')

            business_set_table_name = 'business_set'
            storage.write_table(
                table_name=business_set_table_name,
                table_data=self.business_data,
                )

            business_set = BusinessDataset(in_storage=storage, in_table_name=business_set_table_name)

            model = BusinessTransitionModel()
            model.run(year=2000, business_set=business_set, control_totals=ect_set)
            # check that the distribution of businesses is the same before and after subtracting businesses
            results = self.get_count_all_sectors_and_buildings(business_set)
            return results

        expected_results = array([4000.0/7000.0*5250.0, 1000, 1000.0/3000.0*2500, 2000.0/7000.0*5250.0, 1000,
                                  1000/3000.0*2500, 1000.0/7000.0*5250.0, 1000, 1000/3000.0*2500])

        self.run_stochastic_test(__file__, run_model, expected_results, 10)
    def test_same_distribution_after_business_addition_and_subtraction_control_for_jobs(self):
        """Add new businesses of sector 1 and sector 2. Subtract all businesses of sector 15. The model
        is adding and subtracting businesses while controlling for total number of jobs.
        Test that the total number of jobs in each sector after the modification matches the totals specified
        in annual_jobs_control_totals.
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_set_table_name = 'business_set'
        storage.write_table(
            table_name=business_set_table_name,
            table_data=self.business_data,
            )
        business_set = BusinessDataset(in_storage=storage, in_table_name=business_set_table_name)

        annual_employment_control_totals_data = self.annual_job_control_totals_data
        annual_employment_control_totals_data["total_number_of_jobs"] = array([150000,500000, 0])

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=annual_employment_control_totals_data,
            )
        ect_set = EmploymentControlTotalDataset(in_storage=storage, in_table_name=ect_set_table_name)

        # run model
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)

        #check the total
        results = [business_set.get_attribute('employment').sum()]
        should_be = [650000]
        
        self.assertEqual(ma.allclose(should_be, results, atol=450), True, 
                         "Error in total number of jobs. Should be about %s, is %s." % (should_be[0],results[0]))

        #check that total # jobs within each sector are close to what was set in the control_totals
        results = self.get_job_count_all_sectors(business_set)
        should_be = [150000, 500000, 0]
        self.assertEqual(ma.allclose(results, should_be, atol=200), True)
Exemplo n.º 8
0
        def run_model():
            storage = StorageFactory().get_storage('dict_storage')

            business_set_table_name = 'business_set'
            storage.write_table(
                table_name=business_set_table_name,
                table_data=self.business_data,
            )

            business_set = BusinessDataset(
                in_storage=storage, in_table_name=business_set_table_name)

            model = BusinessTransitionModel()
            model.run(year=2000,
                      business_set=business_set,
                      control_totals=ect_set)
            # check that the distribution of businesses is the same before and after subtracting businesses
            results = self.get_count_all_sectors_and_buildings(business_set)
            return results
Exemplo n.º 9
0
    def test_unplaced_jobs_after_job_addition_control_for_business(self):
        """The initial business table is now adjusted to include 2000 unplaced businesses.
        Add 1,750 new businesses and ensure that the number of unplaced businesses after the addition
        is exactly 3,750 because this model is not responsible for placing jobs, only for creating them.
        """
        # create and populate jobs table for model input
        add_business_data = {
            "business_id": arange(13001, 15001),
            "building_id": array(2000 * [0]),
            "sector_id": array(2000 * [1]),
            "activity_id": array(2000 * [1]),
            "sqft": array(2000 * [10]),
            "employment": array(2000 * [100])
        }
        annual_employment_control_totals_data = self.annual_business_control_totals_data
        annual_employment_control_totals_data[
            "total_number_of_businesses"] = array([10750, 3000, 3000])

        storage = StorageFactory().get_storage('dict_storage')

        business_set_table_name = 'business_set'
        storage.write_table(table_name=business_set_table_name,
                            table_data=self.business_data)
        business_set = BusinessDataset(in_storage=storage,
                                       in_table_name=business_set_table_name)

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=annual_employment_control_totals_data,
        )
        ect_set = EmploymentControlTotalDataset(
            in_storage=storage, in_table_name=ect_set_table_name)

        business_set.add_elements(add_business_data)

        # run model with input databases
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)

        #check that there are indeed 16750 total businesses after running the model
        results = business_set.size()
        should_be = [16750]
        self.assertEqual(ma.allequal(should_be, results), True, "Error")

        #check that the number of unplaced businesses is the number of new businesses created + number of unplaced business before running model
        results = where(business_set.get_attribute("building_id") <= 0)[0].size
        should_be = [3750.0]

        self.assertEqual(ma.allclose(results, should_be, rtol=0.00001), True)
Exemplo n.º 10
0
    def test_same_distribution_after_business_subtraction_control_for_jobs(
            self):
        """Removes sector_1 and sector 15 businesses while controlling for total number of jobs.
        Test that the distribution (in %) of sector 1 and sector 15 employment across buildings before and after the subtraction are
        relatively equal.
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_table_name = 'business_set'
        storage.write_table(table_name=business_table_name,
                            table_data=self.business_data)
        business_set = BusinessDataset(in_storage=storage,
                                       in_table_name=business_table_name)

        ect_set_table_name = 'ect_set'
        storage.write_table(table_name=ect_set_table_name,
                            table_data=self.annual_job_control_totals_data)
        ect_set = EmploymentControlTotalDataset(
            in_storage=storage, in_table_name=ect_set_table_name)

        #run model
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)
        #Check the overall employment
        results = [business_set.get_attribute('employment').sum()]
        should_be = [542000]  # 140000+222000+180000 = 542000
        self.assertEqual(
            results[0] >= should_be[0], True,
            "Error in total number of jobs. Should be >= %s, is %s " %
            (should_be[0], results[0]))
        #The difference should be not larger than the sum of maximum business employment over sectors (-> 100 + 200 + 150)
        self.assertEqual(
            ma.allclose(should_be, results, atol=450), True,
            "Error in total number of jobs. Should be %s (up to 450), is %s " %
            (should_be[0], results[0]))

        def run_model():
            storage = StorageFactory().get_storage('dict_storage')

            business_set_table_name = 'business_set'
            storage.write_table(
                table_name=business_set_table_name,
                table_data=self.business_data,
            )

            business_set = BusinessDataset(
                in_storage=storage, in_table_name=business_set_table_name)

            model = BusinessTransitionModel()
            model.run(year=2000,
                      business_set=business_set,
                      control_totals=ect_set)
            # check that the distribution of businesses is the same before and after subtracting businesses
            results = self.get_job_count_all_sectors_and_buildings(
                business_set)
            return results

        expected_results = array([
            4000.0 * 10 / 142000.0 * 140000, 1000 * 20,
            1000.0 * 150 / 195000.0 * 180000, 2000.0 / 142000.0 * 140000,
            1000 * 2, 1000 * 15 / 195000.0 * 180000,
            1000.0 * 100 / 142000.0 * 140000, 1000 * 200,
            1000 * 30 / 195000.0 * 180000
        ])

        self.run_stochastic_test(__file__, run_model, expected_results, 10)
Exemplo n.º 11
0
    def test_same_distribution_after_business_subtraction_control_for_business(
            self):
        """Removes 1,750 sector_1 businesses and 500 sector 15 businesses.
        Test that the distribution (in %) of sector 1 businesses and sector 15 businesses across buildings before and after the subtraction are
        relatively equal.
        """
        storage = StorageFactory().get_storage('dict_storage')

        business_table_name = 'business_set'
        storage.write_table(table_name=business_table_name,
                            table_data=self.business_data)
        business_set = BusinessDataset(in_storage=storage,
                                       in_table_name=business_table_name)

        ect_set_table_name = 'ect_set'
        storage.write_table(
            table_name=ect_set_table_name,
            table_data=self.annual_business_control_totals_data)
        ect_set = EmploymentControlTotalDataset(
            in_storage=storage, in_table_name=ect_set_table_name)

        # unplace half of the  businesses
        business_set.modify_attribute(name="building_id",
                                      data=zeros(int(business_set.size() / 2)),
                                      index=arange(int(business_set.size() /
                                                       2)))
        #run model
        model = BusinessTransitionModel()
        model.run(year=2000, business_set=business_set, control_totals=ect_set)
        results = business_set.size()
        should_be = [10750]
        self.assertEqual(ma.allequal(should_be, results), True,
                         "Error in total number of businesses.")

        def run_model():
            storage = StorageFactory().get_storage('dict_storage')

            business_set_table_name = 'business_set'
            storage.write_table(
                table_name=business_set_table_name,
                table_data=self.business_data,
            )

            business_set = BusinessDataset(
                in_storage=storage, in_table_name=business_set_table_name)

            model = BusinessTransitionModel()
            model.run(year=2000,
                      business_set=business_set,
                      control_totals=ect_set)
            # check that the distribution of businesses is the same before and after subtracting businesses
            results = self.get_count_all_sectors_and_buildings(business_set)
            return results

        expected_results = array([
            4000.0 / 7000.0 * 5250.0, 1000, 1000.0 / 3000.0 * 2500,
            2000.0 / 7000.0 * 5250.0, 1000, 1000 / 3000.0 * 2500,
            1000.0 / 7000.0 * 5250.0, 1000, 1000 / 3000.0 * 2500
        ])

        self.run_stochastic_test(__file__, run_model, expected_results, 10)