def component(self):
     return BuiltForm.resolve_built_form(self.placetype_component)
 def aggregate(self):
     return BuiltForm.resolve_built_form(self.placetype)
 def component(self):
     return BuiltForm.resolve_built_form(self.placetype_component)
 def aggregate(self):
     return BuiltForm.resolve_built_form(self.placetype)
예제 #5
0
    def collect_built_form_attributes(self):
        """
        Navigates the relational model describing built form and collects the critical data into a flat dictionary
        describing all the attributes of a single built form, in a way that parallels the data required by the core v1
        :return: dict of built form attributes
        """
        built_form = BuiltForm.resolve_built_form_by_id(self.built_form_id)
        built_form_uses = built_form.building_attribute_set.buildingusepercent_set.all(
        )

        type = built_form.__class__.__name__
        key_prepend = 'b__' if type == 'Building' else 'bt__' if type == "BuildingType" else "pt__"
        building_attribute_set = built_form.building_attribute_set
        if not building_attribute_set:
            raise Exception("No attributes for " + built_form)
        built_form_dict = {
            'basic_attributes': {
                'name':
                built_form.name,
                'key':
                key_prepend + slugify(built_form.name).replace('-', '_'),
                'built_form_type':
                type,
                'gross_net_ratio':
                building_attribute_set.gross_net_ratio,
                'intersection_density':
                built_form.intersection_density if isinstance(
                    built_form, UrbanPlacetype) else 0
            },
            'density': defaultdict(float),
            'parcel_acres': defaultdict(float),
            'building_square_feet': defaultdict(float),
            'irrigation': defaultdict(float),
            'residential_attributes': {
                'hh_avg_size': building_attribute_set.household_size,
                'vacancy_rate': building_attribute_set.vacancy_rate
            }
        }
        built_form_uses = list(
            built_form_uses.values_list('building_use_definition__name',
                                        flat=True))

        if built_form.__class__ == Building:
            parcel_acres_dict = self.create_parcel_acres_dict(
                built_form, built_form_uses)
            building_sqft_dict = self.create_bldg_sqft_dict(
                built_form, built_form_uses)
            density_sqft_dict = self.create_density_dict(
                built_form, built_form_uses)

            for key, value in parcel_acres_dict.items():
                built_form_dict['parcel_acres'][key] += float(value)

            for key, value in building_sqft_dict.items():
                built_form_dict['building_square_feet'][key] += value

            for key, value in density_sqft_dict.items():
                built_form_dict['density'][key] += value

        if built_form.__class__ == BuildingType:

            for component_percent in built_form.primarycomponentpercent_set.all(
            ):
                component = component_percent.component()
                uses = component.building_attribute_set.buildingusepercent_set.all(
                )
                component_use_names = list(
                    uses.values_list('building_use_definition__name',
                                     flat=True))
                component_parcel_acres_dict = self.create_parcel_acres_dict(
                    component, component_use_names)
                component_building_sqft_dict = self.create_bldg_sqft_dict(
                    component, component_use_names)
                component_density_sqft_dict = self.create_density_dict(
                    component, component_use_names)

                for key, value in component_parcel_acres_dict.items():
                    built_form_dict['parcel_acres'][key] += float(
                        value) * float(component_percent.percent)

                for key, value in component_building_sqft_dict.items():
                    built_form_dict['building_square_feet'][key] += float(
                        value) * float(component_percent.percent)

                for key, value in component_density_sqft_dict.items():
                    built_form_dict['density'][key] += float(value) * float(
                        component_percent.percent)

        if built_form.__class__ == UrbanPlacetype:

            for component_percent in built_form.placetypecomponentpercent_set.all(
            ):
                component = component_percent.component()
                uses = component.building_attribute_set.buildingusepercent_set.all(
                )
                component_use_names = list(
                    uses.values_list('building_use_definition__name',
                                     flat=True))
                component_parcel_acres_dict = self.create_parcel_acres_dict(
                    component, component_use_names)
                component_building_sqft_dict = self.create_bldg_sqft_dict(
                    component, component_use_names)
                component_density_sqft_dict = self.create_density_dict(
                    component, component_use_names)

                for key, value in component_parcel_acres_dict.items():
                    built_form_dict['parcel_acres'][key] += float(
                        value) * float(component_percent.percent)

                for key, value in component_building_sqft_dict.items():
                    built_form_dict['building_square_feet'][key] += float(
                        value) * float(component_percent.percent)

                for key, value in component_density_sqft_dict.items():
                    built_form_dict['density'][key] += float(value) * float(
                        component_percent.percent)

        irrigation_dict = built_form_dict['irrigation']

        irrigation_dict[
            'irrigated_percent'] = building_attribute_set.irrigated_percent
        irrigation_dict[
            'residential_irrigated_square_feet'] = building_attribute_set.residential_irrigated_square_feet or 0
        irrigation_dict[
            'commercial_irrigated_square_feet'] = building_attribute_set.commercial_irrigated_square_feet or 0

        return built_form, built_form_dict
예제 #6
0
    def collect_built_form_attributes(self):
        """
        Navigates the relational model describing built form and collects the critical data into a flat dictionary
        describing all the attributes of a single built form, in a way that parallels the data required by the core v1
        :return: dict of built form attributes
        """
        built_form = BuiltForm.resolve_built_form_by_id(self.built_form_id)
        built_form_uses = built_form.building_attribute_set.buildingusepercent_set.all()

        type = built_form.__class__.__name__
        key_prepend = 'b__' if type == 'Building' else 'bt__' if type == "BuildingType" else "pt__"
        building_attribute_set = built_form.building_attribute_set
        if not building_attribute_set:
            raise Exception("No attributes for " + built_form)
        built_form_dict = {
            'basic_attributes': {
                'name': built_form.name,
                'key': key_prepend + slugify(built_form.name).replace('-', '_'),
                'built_form_type': type,
                'gross_net_ratio': building_attribute_set.gross_net_ratio,
                'intersection_density': built_form.intersection_density if isinstance(built_form, UrbanPlacetype) else 0
            },
            'density': defaultdict(float),
            'parcel_acres': defaultdict(float),
            'building_square_feet': defaultdict(float),
            'irrigation': defaultdict(float),
            'residential_attributes': {
                'hh_avg_size': building_attribute_set.household_size,
                'vacancy_rate': building_attribute_set.vacancy_rate}
        }
        built_form_uses = list(built_form_uses.values_list('building_use_definition__name', flat=True))

        if built_form.__class__ == Building:
            parcel_acres_dict = self.create_parcel_acres_dict(built_form, built_form_uses)
            building_sqft_dict = self.create_bldg_sqft_dict(built_form, built_form_uses)
            density_sqft_dict = self.create_density_dict(built_form, built_form_uses)

            for key, value in parcel_acres_dict.items():
                built_form_dict['parcel_acres'][key] += float(value)

            for key, value in building_sqft_dict.items():
                built_form_dict['building_square_feet'][key] += value

            for key, value in density_sqft_dict.items():
                built_form_dict['density'][key] += value

        if built_form.__class__ == BuildingType:

            for component_percent in built_form.primarycomponentpercent_set.all():
                component = component_percent.component()
                uses = component.building_attribute_set.buildingusepercent_set.all()
                component_use_names = list(uses.values_list('building_use_definition__name', flat=True))
                component_parcel_acres_dict = self.create_parcel_acres_dict(component, component_use_names)
                component_building_sqft_dict = self.create_bldg_sqft_dict(component, component_use_names)
                component_density_sqft_dict = self.create_density_dict(component, component_use_names)

                for key, value in component_parcel_acres_dict.items():
                    built_form_dict['parcel_acres'][key] += float(value) * float(component_percent.percent)

                for key, value in component_building_sqft_dict.items():
                    built_form_dict['building_square_feet'][key] += float(value) * float(component_percent.percent)

                for key, value in component_density_sqft_dict.items():
                    built_form_dict['density'][key] += float(value) * float(component_percent.percent)

        if built_form.__class__ == UrbanPlacetype:

            for component_percent in built_form.placetypecomponentpercent_set.all():
                component = component_percent.component()
                uses = component.building_attribute_set.buildingusepercent_set.all()
                component_use_names = list(uses.values_list('building_use_definition__name', flat=True))
                component_parcel_acres_dict = self.create_parcel_acres_dict(component, component_use_names)
                component_building_sqft_dict = self.create_bldg_sqft_dict(component, component_use_names)
                component_density_sqft_dict = self.create_density_dict(component, component_use_names)

                for key, value in component_parcel_acres_dict.items():
                    built_form_dict['parcel_acres'][key] += float(value) * float(component_percent.percent)

                for key, value in component_building_sqft_dict.items():
                    built_form_dict['building_square_feet'][key] += float(value) * float(component_percent.percent)

                for key, value in component_density_sqft_dict.items():
                    built_form_dict['density'][key] += float(value) * float(component_percent.percent)

        irrigation_dict = built_form_dict['irrigation']

        irrigation_dict['irrigated_percent'] = building_attribute_set.irrigated_percent
        irrigation_dict['residential_irrigated_square_feet'] = building_attribute_set.residential_irrigated_square_feet or 0
        irrigation_dict['commercial_irrigated_square_feet'] = building_attribute_set.commercial_irrigated_square_feet or 0

        return built_form, built_form_dict
예제 #7
0
 def component(self):
     return BuiltForm.resolve_built_form(self.primary_component)
예제 #8
0
    def collect_built_form_attributes(self):
        """
        Navigates the relational model describing built form and collects the critical data into a flat dictionary
        describing all the attributes of a single built form, in a way that parallels the data required by the core v1
        :return: dict of built form attributes
        """
        built_form = BuiltForm.resolve_built_form_by_id(self.built_form_id)
        built_form_uses = built_form.building_attribute_set.buildingusepercent_set.all()

        type = built_form.__class__.__name__
        key_prepend = "b__" if type == "Building" else "bt__" if type == "BuildingType" else "pt__"
        building_attribute_set = built_form.building_attribute_set
        if not building_attribute_set:
            raise Exception("No attributes for " + built_form)
        built_form_dict = {
            "basic_attributes": {
                "name": built_form.name,
                "key": key_prepend + slugify(built_form.name).replace("-", "_"),
                "built_form_type": type,
                "gross_net_ratio": building_attribute_set.gross_net_ratio,
                "intersection_density": built_form.intersection_density
                if isinstance(built_form, UrbanPlacetype)
                else 0,
            },
            "density": defaultdict(float),
            "parcel_acres": defaultdict(float),
            "building_square_feet": defaultdict(float),
            "irrigation": defaultdict(float),
            "residential_attributes": {
                "hh_avg_size": building_attribute_set.household_size,
                "vacancy_rate": building_attribute_set.vacancy_rate,
            },
        }
        built_form_uses = list(built_form_uses.values_list("building_use_definition__name", flat=True))

        if built_form.__class__ == Building:
            parcel_acres_dict = self.create_parcel_acres_dict(built_form, built_form_uses)
            building_sqft_dict = self.create_bldg_sqft_dict(built_form, built_form_uses)
            density_sqft_dict = self.create_density_dict(built_form, built_form_uses)

            for key, value in parcel_acres_dict.items():
                built_form_dict["parcel_acres"][key] += float(value)

            for key, value in building_sqft_dict.items():
                built_form_dict["building_square_feet"][key] += value

            for key, value in density_sqft_dict.items():
                built_form_dict["density"][key] += value

        if built_form.__class__ == BuildingType:

            for component_percent in built_form.primarycomponentpercent_set.all():
                component = component_percent.component()
                uses = component.building_attribute_set.buildingusepercent_set.all()
                component_use_names = list(uses.values_list("building_use_definition__name", flat=True))
                component_parcel_acres_dict = self.create_parcel_acres_dict(component, component_use_names)
                component_building_sqft_dict = self.create_bldg_sqft_dict(component, component_use_names)
                component_density_sqft_dict = self.create_density_dict(component, component_use_names)

                for key, value in component_parcel_acres_dict.items():
                    built_form_dict["parcel_acres"][key] += float(value) * float(component_percent.percent)

                for key, value in component_building_sqft_dict.items():
                    built_form_dict["building_square_feet"][key] += float(value) * float(component_percent.percent)

                for key, value in component_density_sqft_dict.items():
                    built_form_dict["density"][key] += float(value) * float(component_percent.percent)

        if built_form.__class__ == UrbanPlacetype:

            for component_percent in built_form.placetypecomponentpercent_set.all():
                component = component_percent.component()
                uses = component.building_attribute_set.buildingusepercent_set.all()
                component_use_names = list(uses.values_list("building_use_definition__name", flat=True))
                component_parcel_acres_dict = self.create_parcel_acres_dict(component, component_use_names)
                component_building_sqft_dict = self.create_bldg_sqft_dict(component, component_use_names)
                component_density_sqft_dict = self.create_density_dict(component, component_use_names)

                for key, value in component_parcel_acres_dict.items():
                    built_form_dict["parcel_acres"][key] += float(value) * float(component_percent.percent)

                for key, value in component_building_sqft_dict.items():
                    built_form_dict["building_square_feet"][key] += float(value) * float(component_percent.percent)

                for key, value in component_density_sqft_dict.items():
                    built_form_dict["density"][key] += float(value) * float(component_percent.percent)

        irrigation_dict = built_form_dict["irrigation"]

        irrigation_dict["irrigated_percent"] = building_attribute_set.irrigated_percent
        irrigation_dict["residential_irrigated_square_feet"] = (
            building_attribute_set.residential_irrigated_square_feet or 0
        )
        irrigation_dict["commercial_irrigated_square_feet"] = (
            building_attribute_set.commercial_irrigated_square_feet or 0
        )

        return built_form, built_form_dict
예제 #9
0
 def component(self):
     return BuiltForm.resolve_built_form(self.primary_component)