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)
Exemple #2
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)
Exemple #3
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_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)
Exemple #6
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)