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)
                    ]))
        ]
    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
Exemple #4
0
    def scenarios(self, project=None, region_keys=None, project_keys=None, scenario_keys=None, class_scope=None):

        # 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 FixtureList([
            {
                'class_scope': BaseScenario,
                'key': '{0}_s'.format(project.key),
                'scope': project.schema(),
                'name': '{0}'.format(project.name),
                'description': '{0} layers {1}'.format('2014', project.name),
                'year': 2014,
                'behavior': get_behavior('base_scenario'),
                'categories': [Category(key='category', value='base_year')]
            }]).matching_keys(region_key=region_keys, project_key=project.key if project else project_keys, key=scenario_keys).\
           matching_scope(class_scope=class_scope)
    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)
                ])
        ]
Exemple #6
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)
                         ]))
        ])
Exemple #7
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__))
    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)
                    ])),
        ])
    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__))
    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)
                         ])),
        ]