Ejemplo n.º 1
0
    def default_db_entities(self, **kwargs):
        """
        Project specific SACOG additional db_entities
        :param default_dict:
        :return:
        """

        project = self.config_entity
        # The DbEntity keyspace. These keys have no prefix
        Key = ScagDmDbEntityKey
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate

        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return super(ScagDmProjectFixture, self).default_db_entities() + [
            update_or_create_db_entity(
                project,
                DbEntity(
                    name='SCAG Existing Land Use Parcels 2012',
                    key=Key.EXISTING_LAND_USE_PARCELS_2012,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=ExistingLandUseParcel,
                        import_from_db_entity_key=Key.
                        REGION_EXISTING_LAND_USE_PARCELS,
                        filter_query=dict(city=project.name),
                        fields=dict(),
                        related_fields=dict(land_use_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                            related_class_join_field_name='land_use',
                            source_class_join_field_name='scag_lu'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                project,
                DbEntity(
                    key=Key.CITY_BOUNDARY,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=CityBoundary,
                        import_from_db_entity_key=Key.REGION_CITY_BOUNDARY,
                        filter_query=dict(city=project.name),
                        use_for_bounds=True),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_centroid
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ]))
        ]
Ejemplo n.º 2
0
    def import_db_entity_configurations(self, **kwargs):
        project = self.config_entity

        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return map(
            lambda db_entity_dict: update_or_create_db_entity(project, db_entity_dict['value']),
            FixtureList([
                # This fixtures tests uploading a layer that came from UF by exporting to GDB
                # It verifies that we can handle an existing id column, which gets renamed to id_1
                # so that we can add a new primary key
                dict(
                    value=DbEntity(
                        name='RPLines0414',
                        key='rplines0414_1111',
                        url='file:///srv/calthorpe_media/test_uploads/dataset_57180_ed0d4399083743dbbc607a2d6a92c330.sql.zip',
                        creator=get_user_model().objects.get(username=UserGroupKey.SUPERADMIN),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('reference'),
                            intersection=GeographicIntersection.polygon_to_polygon
                        ),
                        _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
                )),
                # This fixture tests a largish dataset
                dict(
                    value=DbEntity(
                        name='CPAD',
                        key='cpad_1454089444918',
                        url='file:///tmp/dataset_48424_45cbd88ea090485f93c72df2fd905701.sql.zip',
                        creator=get_user_model().objects.get(username=UserGroupKey.SUPERADMIN),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('reference'),
                            intersection=GeographicIntersection.polygon_to_polygon
                        ),
                        _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
                )),
                # This fixture tests a small dataset
                dict(
                    value=DbEntity(
                        name='Lightrail',
                        key='lightrail_111111',
                        url='dataset_48708_d60bf2da001a44e8ab534dced4fb7478.sql.zip',
                        creator=get_user_model().objects.get(username=UserGroupKey.SUPERADMIN),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('reference'),
                            intersection=GeographicIntersection.polygon_to_polygon
                        ),
                        _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
                )),
            ]))
    def default_remote_db_entities(self):
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        mapbox_layers = {
            'Aerial Photo': {
                "id": "elevan.kib62d92",
                "key": "mapbox_aerial"
            },
            'Simple Streets': {
                "id": "elevan.e53fa071",
                "key": "mapbox_streets"
            }
        }

        mapbox_base_url = "https://api.mapbox.com/v4/{id}/{{z}}/{{x}}/{{y}}.png?access_token={api_key}"

        mapbox_setups = map_dict(
            lambda name, attrs: DbEntity(
                key="mapbox_" + attrs['key'],
                name="Mapbox: " + name,
                url=mapbox_base_url.format(id=attrs['id'],
                                           api_key=settings.MAPBOX_API_KEY),
                hosts=["a", "b", "c", "d"],
                schema=self.config_entity,
                no_feature_class_configuration=True,
                feature_behavior=FeatureBehavior(behavior=get_behavior(
                    'remote_imagery')),
                _categories=[
                    Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                             value=DbEntityCategoryKey.BASEMAPS)
                ]), mapbox_layers)

        cloudmade_setups = [
            DbEntity(key='osm_default',
                     name='OpenStreetMap: Base Layer',
                     url="http://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
                     schema=self.config_entity,
                     no_feature_class_configuration=True,
                     feature_behavior=FeatureBehavior(
                         behavior=get_behavior('remote_imagery')),
                     _categories=[
                         Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                  value=DbEntityCategoryKey.BASEMAPS)
                     ])
        ]
        return mapbox_setups + cloudmade_setups
Ejemplo n.º 4
0
    def update_or_create_feature_behavior(self,
                                          configured_feature_behavior,
                                          cloned_intersection=None):
        """
            Used when creating or updating the db_entity for a ConfigEntity.
            This will update or create the the Behavior associated with the FeatureBehavior
            and then update or create the FeatureBehavior associating it to the DbEntity
            and Behavior
        """

        try:
            # This is a oneToOne, so will throw if it doesn't exist
            existing_feature_behavior = self.feature_behavior
        except:
            existing_feature_behavior = None

        logger.debug(
            "For DbEntity %s, update_or_create_feature_behavior. Existing feature behavior: %s, feature behavior: %s"
            % (self.name, existing_feature_behavior,
               configured_feature_behavior))

        if not configured_feature_behavior:
            if not self.feature_behavior:
                # Set a sensible default
                from footprint.main.models.geospatial.feature_behavior import FeatureBehavior
                configured_feature_behavior = FeatureBehavior(
                    behavior=Behavior.objects.get(
                        key=BehaviorKey.Fab.ricate('reference')))
            else:
                # If we have one but nothing is passed in return the existing one
                return existing_feature_behavior

        # First find the stored Behavior represented by feature_behavior.behavior
        # If given a persisted instance use that, otherwise resolve by key
        try:
            behavior = configured_feature_behavior.behavior if \
                configured_feature_behavior.behavior.id else \
                Behavior.objects.get(key=configured_feature_behavior.behavior.key)
        except Exception, e:
            raise Exception(
                "Could not find Behavior with key %s. Exception message %s" %
                (configured_feature_behavior.behavior.key, e.message))
Ejemplo n.º 5
0
    def update_or_create_db_entity_interest(self, config_entity,
                                            existing_db_entity_interest):
        """
            Clone the DbEntity from the increments DbEntity
            This means the queryset is run on the Increments class manager
        :param config_entity:
        :param the existing_db_entity_interest if one exists
        :return: Return the DbEntity
        """

        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))
        return self.clone_db_entity_and_interest_for_result(
            config_entity,
            existing_db_entity_interest,
            self.source_db_entity_key,
            key=self.result_db_entity_key,
            name=titleize(self.name),
            query=self.create_query(self),
            feature_behavior=FeatureBehavior(behavior=get_behavior('result')))
Ejemplo n.º 6
0
    def default_remote_db_entities(self):
        """
            Add the SACOG background. This function is called from default_db_entities so it doesn't
            need to call the parent_fixture's method
        """
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return [
            DbEntity(
                key='sacog_background',
                url=
                "http://services.sacog.org/arcgis/rest/services/Imagery_DigitalGlobe_2012WGS/MapServer/tile/{Z}/{Y}/{X}",
                no_feature_class_configuration=True,
                feature_behavior=FeatureBehavior(
                    behavior=get_behavior('remote_imagery')),
                _categories=[
                    Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                             value=DbEntityCategoryKey.BASEMAPS)
                ])
        ]
Ejemplo n.º 7
0
    def default_db_entities(self):
        """
            Region specific db_entity_setups
        :param default_dict:
        :return:
        """

        config_entity = self.config_entity
        parent_region_fixture = self.parent_fixture
        default_db_entities = parent_region_fixture.default_db_entities()
        # The DbEntity keyspace. These keys have no prefix
        Key = ScagDmDbEntityKey
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        if isinstance(self.config_entity.parent_config_entity_subclassed,
                      GlobalConfig):
            # Block the client-level region. We just want real regions
            return []

        return default_db_entities + FixtureList([
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    name='2016 SCAG Existing Land Use Parcels',
                    key=Key.REGION_EXISTING_LAND_USE_PARCELS,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=ExistingLandUseParcel,
                        primary_geography=True,
                        primary_key='source_id',
                        primary_key_type='int',
                        fields=dict(),
                        related_fields=dict(land_use_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                            related_class_join_field_name='land_use',
                            source_class_join_field_name='scag_lu16'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.FLOOD_ZONES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=FloodZones),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.ENDANGERED_SPECIES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=EndangeredSpecies),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CPAD_HOLDINGS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CpadHoldings),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.HABITAT_CONSERVATION_AREA,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=HabitatConservationAreas),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.COUNTY_BOUNDARY,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CountyBoundary),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(name='2040 High Quality Transit Areas',
                         key=Key.HIGH_QUALITY_TRANSIT_AREAS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=HighQualityTransitAreas),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(name='2040 High Quality Transit Corridors',
                         key=Key.HIGH_QUALITY_TRANSIT_CORRIDORS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=HighQualityTransitCorridors),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(name='2040 Major Transit Stops',
                         key=Key.MAJOR_TRANSIT_STOPS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=MajorTransitStops),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(name='2040 Transit Priority Areas',
                         key=Key.TRANSIT_PRIORITY_AREAS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=TransitPriorityAreas),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.FARMLAND,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=Farmland,
                        related_fields=dict(farmland_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.scag_dm.built_form.scag_dm_farmland_definition.ScagDmFarmlandDefinition',
                            related_class_join_field_name='farmland_code',
                            source_class_join_field_name='scag_type'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior(
                            'reference_layers_editable_attribute'),
                        intersection=GeographicIntersection.polygon_to_centroid
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.REGION_GENERAL_PLAN_PARCELS,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=GeneralPlanParcels,
                        primary_key='source_id',
                        primary_key_type='int',
                        fields=dict(),
                        related_fields=dict(land_use_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                            # Use this for the resource type, since we don't want a client-specific resource URL
                            # TODO not wired up yet
                            resource_model_class_name=
                            'footprint.main.models.built_form.ClientLandUseDefinition',
                            related_class_join_field_name='land_use',
                            source_class_join_field_name='scag_gp_code16'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=AttributeIntersection()),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.REGION_SPECIFIC_PLAN_PARCELS,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SpecificPlanParcels,
                        primary_key='source_id',
                        primary_key_type='int',
                        fields=dict(),
                        related_fields=dict(land_use_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                            resource_model_class_name=
                            'footprint.main.models.built_form.ClientLandUseDefinition',
                            related_class_join_field_name='land_use',
                            source_class_join_field_name='scag_sp_code16'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=AttributeIntersection()),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.REGION_ZONING_PARCELS,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=ZoningParcels,
                        primary_key='source_id',
                        primary_key_type='int',
                        fields=dict(),
                        related_fields=dict(land_use_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                            resource_model_class_name=
                            'footprint.main.models.built_form.ClientLandUseDefinition',
                            related_class_join_field_name='land_use',
                            source_class_join_field_name='scag_zn_code16'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=AttributeIntersection()),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.REGION_ENTITLEMENT_PARCELS_2016,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=EntitlementParcels,
                             primary_key='source_id',
                             primary_key_type='int',
                             fields=dict()),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=AttributeIntersection()),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.REGION_SCENARIO_PLANNING_ZONES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=ScenarioPlanningZones, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(name='Sphere of Influence',
                         key=Key.REGION_SPHERE_OF_INFLUENCE,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SphereOfInfluence, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.REGION_TIER2_TAZ,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=Tier2Taz, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_TRACTS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusTracts, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.SUB_REGION,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SubRegion, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.REGION_CITY_BOUNDARY,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CityBoundary, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('editable_feature'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            # update_or_create_db_entity(config_entity, DbEntity(
            #     key=Key.BIKE_LANE,
            #     feature_class_configuration=FeatureClassConfiguration(
            #         abstract_class=BikeLane,
            #     ),
            #     feature_behavior=FeatureBehavior(
            #         behavior=get_behavior('reference_layers_editable_attribute'),
            #         intersection=GeographicIntersection.polygon_to_centroid
            #     ),
            #     _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
            # )),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.SEA_LEVEL_RISE,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SeaLevelRise, ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior(
                                 'reference_layers_editable_attribute'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ]))
        ])
Ejemplo n.º 8
0
    def default_db_entities(self):
        """
            Scenarios define DbEntities specific to the Scenario. Creates a list a dictionary of configuration functionality.
            These are filtered based on whether the given scenario matches the scope in the configuration
        :return:
        """
        project = self.config_entity.parent_config_entity_subclassed

        scenario = self.config_entity
        # The DbEntity keyspace. These keys have no prefix
        Key = ScagDmDbEntityKey
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return super(ScagDmScenarioFixture, self).default_db_entities() + map(
            lambda db_entity_dict: update_or_create_db_entity(
                scenario, db_entity_dict['value']),
            FixtureList([
                dict(
                    class_scope=BaseScenario,
                    value=DbEntity(
                        name='2016 SCAG Existing Land Use Parcels',
                        key=Key.EXISTING_LAND_USE_PARCELS_2016,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=ExistingLandUseParcel,
                            import_from_db_entity_key=Key.
                            REGION_EXISTING_LAND_USE_PARCELS,
                            filter_query=dict(city=project.name),
                            # primary_geography=True,
                            # primary_key='source_id',
                            # primary_key_type='int',
                            fields=dict(),
                            related_fields=dict(land_use_definition=dict(
                                single=True,
                                related_class_name=
                                'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                                related_class_join_field_name='land_use',
                                source_class_join_field_name='scag_lu16'))),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('editable_feature')),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.EDITABLE_LAYER)
                        ])),
                dict(
                    class_scope=BaseScenario,
                    value=DbEntity(
                        name='2016 SCAG General Plan Parcels',
                        key=Key.GENERAL_PLAN_PARCELS,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=GeneralPlanParcels,
                            primary_key='source_id',
                            primary_key_type='int',
                            import_from_db_entity_key=Key.
                            REGION_GENERAL_PLAN_PARCELS,
                            filter_query=dict(city=project.name),
                            fields=dict(),
                            related_fields=dict(land_use_definition=dict(
                                single=True,
                                related_class_name=
                                'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                                # Use this for the resource type, since we don't want a client-specific resource URL
                                # TODO not wired up yet
                                resource_model_class_name=
                                'footprint.main.models.built_form.ClientLandUseDefinition',
                                related_class_join_field_name='land_use',
                                source_class_join_field_name='scag_gp_code16')
                                                )),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('editable_feature'),
                            intersection=AttributeIntersection()),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.EDITABLE_LAYER)
                        ])),
                dict(
                    class_scope=BaseScenario,
                    value=DbEntity(
                        name='2016 SCAG Specific Plan Parcels',
                        key=Key.SPECIFIC_PLAN_PARCELS,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=SpecificPlanParcels,
                            primary_key='source_id',
                            primary_key_type='int',
                            import_from_db_entity_key=Key.
                            REGION_SPECIFIC_PLAN_PARCELS,
                            filter_query=dict(city=project.name),
                            fields=dict(),
                            related_fields=dict(land_use_definition=dict(
                                single=True,
                                related_class_name=
                                'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                                resource_model_class_name=
                                'footprint.main.models.built_form.ClientLandUseDefinition',
                                related_class_join_field_name='land_use',
                                source_class_join_field_name='scag_sp_code16')
                                                )),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('editable_feature'),
                            intersection=AttributeIntersection()),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.EDITABLE_LAYER)
                        ])),
                dict(class_scope=BaseScenario,
                     value=DbEntity(
                         name='2016 SCAG Infill Parcels',
                         key=Key.INFILL_PARCELS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=InfillParcels,
                             import_from_db_entity_key=Key.
                             REGION_INFILL_PARCELS,
                             filter_query=dict(city=project.name),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('editable_feature'),
                             intersection=AttributeIntersection()),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.EDITABLE_LAYER)
                         ])),
                dict(
                    class_scope=BaseScenario,
                    value=DbEntity(
                        name='2016 SCAG Zoning Parcels',
                        key=Key.ZONING_PARCELS,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=ZoningParcels,
                            primary_key='source_id',
                            primary_key_type='int',
                            import_from_db_entity_key=Key.
                            REGION_ZONING_PARCELS,
                            filter_query=dict(city=project.name),
                            fields=dict(),
                            related_fields=dict(land_use_definition=dict(
                                single=True,
                                related_class_name=
                                'footprint.client.configuration.scag_dm.built_form.scag_dm_land_use_definition.ScagDmLandUseDefinition',
                                resource_model_class_name=
                                'footprint.main.models.built_form.ClientLandUseDefinition',
                                related_class_join_field_name='land_use',
                                source_class_join_field_name='scag_zn_code16')
                                                )),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('editable_feature'),
                            intersection=AttributeIntersection()),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.EDITABLE_LAYER)
                        ])),
                dict(class_scope=BaseScenario,
                     value=DbEntity(
                         name='2016 SCAG Entitlement Parcels',
                         key=Key.ENTITLEMENT_PARCELS_2016,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=EntitlementParcels,
                             primary_key='source_id',
                             primary_key_type='int',
                             import_from_db_entity_key=Key.
                             REGION_ENTITLEMENT_PARCELS_2016,
                             filter_query=dict(city=project.name),
                             fields=dict()),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('editable_feature'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.EDITABLE_LAYER)
                         ])),
                dict(class_scope=BaseScenario,
                     value=DbEntity(
                         key=Key.SCENARIO_PLANNING_ZONES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=ScenarioPlanningZones,
                             import_from_db_entity_key=Key.
                             REGION_SCENARIO_PLANNING_ZONES,
                             filter_query=dict(city=project.name),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('editable_feature'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=BaseScenario,
                     value=DbEntity(
                         name='City/Tier2 TAZ',
                         key=Key.TIER2_TAZ,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=Tier2Taz,
                             import_from_db_entity_key=Key.REGION_TIER2_TAZ,
                             filter_query=dict(city=project.name),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('sed_editor_tool'),
                             intersection=AttributeIntersection()),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.EDITABLE_LAYER)
                         ]))
            ]).matching_scope(class_scope=self.config_entity
                              and self.config_entity.__class__))
Ejemplo n.º 9
0
    def default_db_entities(self, **kwargs):
        """
        Region specific SACOG db_entity_setups
        :param default_dict:
        :return:
        """

        config_entity = self.config_entity
        parent_region_fixture = self.parent_fixture
        default_db_entities = parent_region_fixture.default_db_entities()
        Key = SacogDbEntityKey

        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        if self.config_entity.key == 'sacog':
            # Block the client-level region. We just want real regions
            return []

        remote_db_entity_setups = FixtureList(
            map(
                lambda db_entity: update_or_create_db_entity(
                    config_entity, db_entity),
                self.default_remote_db_entities()))

        # TODO: Disabled the 'sacog_background' 'remote db entity' b/c it is throwing errors (2016-07-06)
        # return default_db_entities + remote_db_entity_setups + FixtureList([
        return default_db_entities + FixtureList([
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=DbEntityKey.REGION_PRIMARY_GEOGRAPHY,
                    # Override. If a name override is supplied, put it in. Otherwise leave null to derive it from the key
                    name='Urban Base Canvas (UF)',
                    # name=get_property_path(kwargs, 'overrides.%s.name' % Key.BASE),
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=CanvasFeature,
                        # The Base Feature is normally considered a primary_geography unless overridden
                        primary_geography=True,
                        primary_key='geography_id',
                        primary_key_type='int',
                        # The Base Feature is normally associated to a subclass of Geography unless overridden
                        geography_class_name=get_property_path(
                            kwargs, 'overrides.%s.geography_class_name' %
                            Key.BASE_CANVAS)
                        or 'footprint.main.models.geographies.parcel.Parcel',
                        # Create a built_form ForeignKey to a single BuiltForm,
                        # by initially joining our 'built_form_key' attribute to its 'key' attribute
                        related_fields=dict(built_form=dict(
                            single=True,
                            related_class_name=uf_model(
                                'built_form.built_form.BuiltForm'),
                            source_class_join_field_name='built_form_key',
                            related_class_join_field_name='key',
                        ))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('base_feature'), ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_TRACTS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusTract),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_BLOCKGROUPS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusBlockgroup),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_BLOCK,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusBlock),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.LIGHT_RAIL,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SacogLightRailFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.LIGHT_RAIL_STOPS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SacogLightRailStopsFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.LIGHT_RAIL_STOPS_ONE_MILE,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogLightRailStopsOneMileFeature, ),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_polygon
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.LIGHT_RAIL_STOPS_HALF_MILE,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogLightRailStopsHalfMileFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_polygon
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.LIGHT_RAIL_STOPS_QUARTER_MILE,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogLightRailStopsQuarterMileFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_polygon
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.VERNAL_POOL,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogVernalPoolFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('environmental_constraint')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.WETLAND,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogWetlandFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('environmental_constraint')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.STREAM,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogStreamFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('environmental_constraint')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
        ])
Ejemplo n.º 10
0
    def default_db_entities(self):
        """
            Scenarios define DbEntities specific to the Scenario. Creates a list a dictionary of configuration
            functionality. These are filtered based on whether the given scenario matches the scope in the
            configuration
        :return:
        """
        scenario = self.config_entity
        project = self.config_entity.parent_config_entity
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return super(SacogScenarioFixture, self).default_db_entities() + map(
            lambda db_entity_dict: update_or_create_db_entity(
                scenario, db_entity_dict['value']),
            FixtureList([
                dict(
                    class_scope=FutureScenario,
                    value=DbEntity(
                        key=DbEntityKey.INCREMENT,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=CoreIncrementFeature,
                            import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                            import_ids_only=True,
                            related_fields=dict(built_form=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'built_form.built_form.BuiltForm')))),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('scenario_increment'),
                            intersection=AttributeIntersection(
                                from_attribute='id', to_attribute='id')),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.FUTURE_SCENARIO)
                        ]),
                ),
                dict(
                    class_scope=FutureScenario,
                    value=DbEntity(
                        key=DbEntityKey.END_STATE,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=CanvasFeature,
                            import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                            related_fields=dict(built_form=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'built_form.built_form.BuiltForm')))),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('scenario_end_state'),
                            intersection=AttributeIntersection(
                                from_attribute='id', to_attribute='id')),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.FUTURE_SCENARIO)
                        ]),
                ),
                dict(class_scope=FutureScenario,
                     value=DbEntity(
                         key=DbEntityKey.FUTURE_AGRICULTURE_CANVAS,
                         name='Scenario Agriculture End State',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=AgricultureFeature,
                             import_from_db_entity_key=DbEntityKey.
                             BASE_AGRICULTURE_CANVAS,
                             import_ids_only=False,
                             related_fields=dict(built_form=dict(
                                 single=True,
                                 related_class_name=uf_model(
                                     'built_form.built_form.BuiltForm'),
                                 related_class_join_field_name='key',
                                 source_class_join_field_name='built_form_key')
                                                 )),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('agriculture_scenario'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.FUTURE_SCENARIO)
                         ])),
                dict(class_scope=FutureScenario,
                     value=DbEntity(
                         key=DbEntityKey.FISCAL,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=FiscalFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.VMT_VARIABLES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=VmtVariablesFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.VMT,
                         name='Vehicle Miles Traveled Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=VmtFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.ENERGY,
                         name='Energy Demand Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=EnergyFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.WATER,
                         name='Water Demand Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=WaterFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_VARIABLES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhVariablesFeature,
                             import_from_db_entity_key=DbEntityKey.GRID_150M,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_GRID_OUTCOMES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhGridOutcomesFeature,
                             import_from_db_entity_key=DbEntityKey.GRID_150M,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_BLOCK_GROUP_OUTCOMES,
                         name='Public Health Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhBlockGroupOutcomesFeature,
                             import_from_db_entity_key=DbEntityKey.GRID_150M,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_OUTCOMES_SUMMARY,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhOutcomesSummary,
                             no_table_associations=True,
                             empty_table=True,
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ]))
            ]).matching_scope(class_scope=self.config_entity
                              and self.config_entity.__class__))
Ejemplo n.º 11
0
    def default_db_entities(self, **kwargs):
        """
        Project specific SACOG additional db_entities
        :param default_dict:
        :return:
        """
        project = self.config_entity
        # The DbEntity keyspace. These keys have no prefix
        Key = SacogDbEntityKey

        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return super(SacogProjectFixture, self).default_db_entities() + [
            update_or_create_db_entity(
                project,
                DbEntity(
                    key=DbEntityKey.BASE_CANVAS,
                    # Override. If a name override is supplied, put it in. Otherwise leave null to derive it from the key
                    name='UF Urban Base Canvas',
                    # name=get_property_path(kwargs, 'overrides.%s.name' % Key.BASE),
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=CanvasFeature,
                        # The Base Feature is normally considered a primary_geography unless overridden
                        primary_geography=get_property_path(
                            kwargs, 'overrides.%s.primary_geography' %
                            Key.BASE_CANVAS) or True,
                        primary_key='geography_id',
                        primary_key_type='int',
                        # The Base Feature is normally associated to a subclass of Geography unless overridden
                        geography_class_name=get_property_path(
                            kwargs, 'overrides.%s.geography_class_name' %
                            Key.BASE_CANVAS)
                        or 'footprint.main.models.geographies.parcel.Parcel',
                        # Create a built_form ForeignKey to a single BuiltForm,
                        # by initially joining our 'built_form_key' attribute to its 'key' attribute
                        related_fields=dict(built_form=dict(
                            single=True,
                            related_class_name=uf_model(
                                'built_form.built_form.BuiltForm'),
                            source_class_join_field_name='built_form_key',
                            related_class_join_field_name='key',
                        ))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('base_feature'), ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                project,
                DbEntity(
                    key=Key.EXISTING_LAND_USE_PARCELS,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogExistingLandUseParcelFeature,
                        primary_key='geography_id',
                        primary_key_type='int',
                        fields=dict(),
                        related_fields=dict(land_use_definition=dict(
                            single=True,
                            related_class_name=
                            'footprint.client.configuration.sacog.built_form.sacog_land_use_definition.SacogLandUseDefinition',
                            resource_model_class_name=
                            'footprint.main.models.built_form.ClientLandUseDefinition',
                            related_class_join_field_name='land_use',
                            source_class_join_field_name='land_use'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=AttributeIntersection(from_attribute='id',
                                                           to_attribute='id')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                project,
                DbEntity(
                    key=DbEntityKey.BASE_AGRICULTURE_CANVAS,
                    name='UF Agriculture Base Canvas (RUCS)',
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=AgricultureFeature,
                        primary_key='geography_id',
                        primary_key_type='varchar',
                        # Create a built_form ForeignKey to a single BuiltForm,
                        # by initially joining our 'built_form_key' attribute to its 'key' attribute
                        related_fields=dict(built_form=dict(
                            single=True,
                            related_class_name=
                            'footprint.main.models.built_form.built_form.BuiltForm',
                            related_class_join_field_name='key',
                            source_class_join_field_name='built_form_key'))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('base_agriculture'),
                        intersection=AttributeIntersection(
                            join_type='attribute')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=Key.ELK_GROVE_LAND_USE_PARCELS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=ElkGroveLandUseParcel),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             centroid_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=Key.CENSUS_RATES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusRatesFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=Key.GRID_150M,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhGridFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                project,
                DbEntity(
                    key=DbEntityKey.CLIMATE_ZONES,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=ClimateZoneFeature,
                        related_fields=dict(
                            evapotranspiration_zone=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'policy.water.evapotranspiration_baseline.EvapotranspirationBaseline'
                                ),
                                related_class_join_field_name='zone',
                                source_class_join_field_name=
                                'evapotranspiration_zone_id'),
                            forecasting_climate_zone=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'policy.energy.commercial_energy_baseline.CommercialEnergyBaseline'
                                ),
                                related_class_join_field_name='zone',
                                source_class_join_field_name=
                                'forecasting_climate_zone_id'),
                            title_24_zone=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'policy.energy.residential_energy_baseline.ResidentialEnergyBaseline'
                                ),
                                related_class_join_field_name='zone',
                                source_class_join_field_name='title_24_zone_id'
                            ))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('internal_analysis'),
                        intersection=GeographicIntersection.polygon_to_centroid
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=DbEntityKey.VMT_FUTURE_TRIP_LENGTHS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=VmtTripLengthsFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=DbEntityKey.VMT_BASE_TRIP_LENGTHS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=VmtTripLengthsFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=Key.BASE_TRANSIT_STOPS,
                         name='GTFS Transit Stops: 2014',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=TransitStopFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                project,
                DbEntity(key=Key.FUTURE_TRANSIT_STOPS,
                         name='GTFS and Future Transit Stops: 2040',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=TransitStopFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
        ]
Ejemplo n.º 12
0
def clone_or_update_db_entity_and_interest(config_entity,
                                           source_db_entity,
                                           db_entity,
                                           existing_db_entity_interest=None,
                                           override_on_update=False):
    """
        Clones or updates the source_db_entity modified with the given kwargs (including possibly the key) into this ConfigEntity.
        This is used for a duplicate clone from one ConfigEntity (same DbEntity key) to another and also for
        creating a modified DbEntity for a Result from a non-Result DbEntity (different DbEntity key). A third case for this
        method is cloning a DbEntity within a ConfigEntity, which is not yet implemented.

        If the kwargs['override_on_update'] is True, the kwargs should override the target DbEntity attribute values on update.
        This is useful for the Result clone case where we want to pick up updates to the source DbEntity. But in the straight
        clone case we want to make the target DbEntity independent of the source once it is created.
        Returns the DbEntityInterest

        :param: config_entity. The config_entity of the DbEntities
        :param: Optional source_db_entity. The source of the clone
        :param: db_entity. DbEntity of attributes matching the DbEntity that need to override those of the source_db_entity. This might be the
        key, schema, etc.
        Also for db_entity.feature_class_owner, default None, is passed in for Results that are copying
        a reference DbEntity's feature_class_configuration with the db_entity key of the onwer. We don't want the result version of the feature_class_configuration
        to be used to create the feature_class tables, because that would make foreign key references point to the
        wrong feature class parents (which are named by the DbEntity id). phwewww!
        :param: existing_db_entity_interest: Optional DbEntityInterest if it already exists for the clone
        :param: override_on_update: Default False, optional and is described above.
    """

    # Do a forced adoption of DbEntityInterests from the parent ConfigEntity. This makes sure that ConfigEntity has
    # the parent's DbEntityInterests before adding any of its own. Otherwise the parent's are never adopted and
    # are created from the db_entity_configurations instead, which is minimally less efficient
    # See _adopt_from_donor docs for an explanation.
    config_entity._adopt_from_donor('db_entities', True)

    # TODO Update to newer cleaner configuration style
    # key is always resolved by the db_entity or else the source DbEntity key
    key = db_entity.key or source_db_entity.key

    feature_behavior = db_entity._feature_behavior
    if existing_db_entity_interest:
        # Merge existing DbEntity data, including the id. Manually merge feature_behavior since it's not a real
        # property
        db_entity.__dict__.update(
            merge(
                model_dict(existing_db_entity_interest.db_entity,
                           include_primary_key=True),
                dict(_feature_behavior=existing_db_entity_interest.db_entity.
                     feature_behavior)))
    if not db_entity._feature_behavior:
        from footprint.main.publishing.config_entity_initialization import get_behavior
        # If we don't already have a feature_behavior get it from the source DbEntity but 0 the id to make a copy
        # We'll also 0 out the Intersection of the FeatureBehavior and pass it to the FeatureBehavior creator
        # If we don't have a source_db_entity then create a default FeatureBehavior
        feature_behavior = source_db_entity.feature_behavior if \
            source_db_entity else  \
            FeatureBehavior(
                behavior=get_behavior('reference')
            )
        feature_behavior.id = None

    # Prefer the db_entity values over those of the source_db_entity
    db_entity.__dict__.update(merge(
        # Start with the source attributes
        model_dict(source_db_entity) if source_db_entity else {},
        # Copy the feature_behavior by assigning it to the temp property _feature_behavior
        # Prefer the FeatureBehavior of the new DbEntity (for the Result case)
        dict(_feature_behavior=feature_behavior),
        # Override with the initial clone overrides or existing clone values.
        model_dict(db_entity),
        # If update_on_override then overwrite the clone with the source values
        # This is for the case of updating the source configuration and wanting to mirror changes to the Result DbEntities
        remove_keys(model_dict(source_db_entity), ['key', 'schema', 'name']) if source_db_entity and override_on_update else {},
        # Set the clone source key if different than the target key
        dict(source_db_entity_key=source_db_entity.key) if source_db_entity and source_db_entity.key != key else {},
        dict(
             # Override feature_class_configuration keys if specified in the kwargs and create_or_update_on_override is True
             feature_class_configuration=FeatureClassConfiguration(**merge(
                # start with the source's attributes
                source_db_entity.feature_class_configuration.__dict__ if source_db_entity else {},
                # override with all those present on the clone if create_or_update_on_override is false, if true add only those unspecified on the source
                # The only exception is abstract_class_name, which must always come from the source
                remove_keys(db_entity.feature_class_configuration.__dict__,
                            source_db_entity.feature_class_configuration.__dict__.keys() if \
                                source_db_entity and override_on_update else \
                                ['abstract_class_name']
                            ),
                # feature_class_owner is set to the owning db_entity key for a Result DbEntity creation so that
                # the result feature_class_configuration doesn't create feature classes/tables
                # We either copy this value from the source feature_class_configuration (clone case) or get it from the kwargs (create Result DbEntity case)
                dict(
                    feature_class_owner=source_db_entity.feature_class_configuration.feature_class_owner if \
                        source_db_entity else \
                        db_entity.feature_class_configuration.feature_class_owner,
                )
             ))
        )
    ))
    # There must be a creator of a new DbEntity. The updater is that of the source DbEntity or simply the creator
    try:
        db_entity.creator = db_entity.creator
    except:
        db_entity.creator = source_db_entity.creator
    logger.debug(db_entity.creator.__class__)
    try:
        db_entity.updater = db_entity.updater
    except:
        db_entity.updater = db_entity.creator
    # Persist the feature_behavior
    FeatureBehavior._no_post_save_publishing = True
    db_entity.update_or_create_feature_behavior(db_entity._feature_behavior)
    # # save to persist the db_entity's knowledge of its behavior
    # db_entity.save()
    FeatureBehavior._no_post_save_publishing = False

    # This will trigger DbEntity post-save publishing, but the only thing that actually
    # runs is UserPublishing in order to give users permission to the DbEntity
    # The other publishers detect that the DbEntity has a source_db_entity_key and quit
    db_entity_interest = update_or_create_db_entity_and_interest(
        config_entity, db_entity)[0]

    # Copy the categories from the source if it exists
    if source_db_entity:
        db_entity_interest.db_entity.categories.add(
            *source_db_entity.categories.all())

    return db_entity_interest