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)
                    ]))
        ]
Example #2
0
 def create_layer_from_layer_selection(self, params):
     """
         Used to create a new Layer from the current LayerSelection features
     :param params:
     :return:
     """
     # Resolve the source layer from the layer_selection__id
     source_layer = self.resolve_layer(params)
     config_entity = source_layer.config_entity
     db_entity = source_layer.db_entity_interest.db_enitty
     feature_class = FeatureClassCreator(config_entity,
                                         db_entity).dynamic_model_class()
     layer = Layer.objects.get(presentation__config_entity=config_entity,
                               db_entity_key=db_entity.key)
     layer_selection = get_or_create_layer_selection_class_for_layer(
         layer, config_entity, False).objects.all()[0]
     # TODO no need to do geojson here
     feature_dict = dict(type="Feature")
     feature_dicts = map(
         lambda feature:
         deep_merge(feature_dict,
                    {"geometry": geojson.loads(feature.wkb_geometry.json)}),
         layer_selection.selected_features or feature_class.objects.all())
     json = dict({"type": "FeatureCollection", "features": feature_dicts})
     db_entity_configuration = update_or_create_db_entity(
         config_entity,
         **dict(class_scope=FutureScenario,
                name='Import From Selection Test',
                key='import_selection_test',
                url='file://notusingthis'))
     self.make_geojson_db_entity(config_entity,
                                 db_entity_configuration,
                                 data=json)
Example #3
0
 def create_layer_from_layer_selection(self, params):
     """
         Used to create a new Layer from the current LayerSelection features
     :param params:
     :return:
     """
     # Resolve the source layer from the layer_selection__id
     source_layer = self.resolve_layer(params)
     config_entity = source_layer.config_entity
     db_entity = source_layer.db_entity_interest.db_enitty
     feature_class = FeatureClassCreator(config_entity, db_entity).dynamic_model_class()
     layer = Layer.objects.get(presentation__config_entity=config_entity, db_entity_key=db_entity.key)
     layer_selection = get_or_create_layer_selection_class_for_layer(layer, config_entity, False).objects.all()[0]
     # TODO no need to do geojson here
     feature_dict = dict(
         type="Feature"
     )
     feature_dicts = map(lambda feature:
                         deep_merge(feature_dict, {"geometry":geojson.loads(feature.wkb_geometry.json)}),
                         layer_selection.selected_features or feature_class.objects.all())
     json = dict({"type": "FeatureCollection", "features": feature_dicts})
     db_entity_configuration = update_or_create_db_entity(config_entity, **dict(
         class_scope=FutureScenario,
         name='Import From Selection Test',
         key='import_selection_test',
         url='file://notusingthis'
     ))
     self.make_geojson_db_entity(config_entity, db_entity_configuration, data=json)
 def default_db_entities(self):
     """
         Only the remote imagery DbEntities belong to the GlobalConfig
     :return:
     """
     config_entity = self.config_entity
     remote_db_entity_configurations = self.default_remote_db_entities()
     return map(
         lambda remote_db_entity_configuration: update_or_create_db_entity(
             config_entity, remote_db_entity_configuration),
         remote_db_entity_configurations)
    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)]
                )),
            ]))
Example #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)
                         ]))
        ])
Example #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__))
Example #8
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)
                    ])),
        ])
    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__))
Example #10
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)
                         ])),
        ]
Example #11
0
def on_db_entity_interest_post_save(sender, **kwargs):
    """
        Called after a DbEntityInterest saves, but not when a config_entity is running post_save publishers
        In other words, this is only called after a direct DbEntityInterest save/update.
        This does the same as post_save_config_entity, but starts with the 'post_save_config_entity_db_entities'
        signal to do only DbEntity dependent presentation.
    """
    db_entity_interest = kwargs['instance']
    config_entity = ConfigEntity._subclassed(db_entity_interest.config_entity)
    db_entity = db_entity_interest.db_entity
    # TODO The default user should be the admin
    user = db_entity.updater if db_entity.updater else get_user_model(
    ).objects.get(username=UserGroupKey.SUPERADMIN)
    # post_save_db_entity presentation should always be disabled if we are saving a ConfigEntity
    logger.info(
        "Handler: post_save_db_entity_interest for config_entity {config_entity}, db_entity {db_entity}, "
        "and user {username}.".format(config_entity=config_entity,
                                      db_entity=db_entity_interest.db_entity,
                                      username=user.username))

    if kwargs.get('created', None):
        db_entity = db_entity_interest.db_entity
        # TODO
        # While we test upload, just delete the previous DbEntitys with the same key name
        # in the ConfigEntity.
        db_entity_interest.config_entity.db_entities.filter(
            key=db_entity.key).exclude(id=db_entity.id).delete()

        # Make sure the db_entity's schema matches the config_entity's if not set
        # TODO we assume that the schema should match the config_entity, rather than
        # an ancestor or the config_entity (like the project or a scenario). There
        # are many cases where the schema should not be that of the config_entity, so
        # we might want to remove this default and force the saver to set it
        if not db_entity.schema or not db_entity.table:
            db_entity.schema = db_entity.schema or db_entity_interest.config_entity.schema(
            )
            # Always base the table name on the key
            db_entity.table = db_entity.key
            db_entity_interest.db_entity.save()

    if db_entity_interest.config_entity.deleted:
        # Do nothing for deleted config_entities
        return

    # Define the data_importer if not already set
    if not (db_entity.feature_class_configuration
            and db_entity.feature_class_configuration.data_importer):
        feature_class_configuration = db_entity.feature_class_configuration = db_entity.feature_class_configuration or FeatureClassConfiguration(
        )
        # Choose the correct importer, if any, to set up the feature_class_configuration and features
        if db_entity.origin_instance:
            # Import from the origin_instance. This could be a full copy or from the current layer selection features
            feature_class_configuration.data_importer = full_module_path(
                OriginDbEntityProcessor)
        elif '.json' in db_entity.url.lower():
            # Import it using the geojson importer
            feature_class_configuration.data_importer = full_module_path(
                GeoJsonProcessor)
            # Indicate that the feature class configuration was generated not fixture based
            feature_class_configuration.generated = True
        elif '.zip' in db_entity.url.lower():
            feature_class_configuration.data_importer = full_module_path(
                ZippedSqlFileProcessor)
            # Indicate that the feature class configuration was generated not fixture based
            feature_class_configuration.generated = True
        elif not db_entity.no_feature_class_configuration:
            feature_class_configuration.data_importer = full_module_path(
                DefaultImportProcessor)
        previous = DbEntityInterest._no_post_save_publishing
        DbEntityInterest._no_post_save_publishing = True
        db_entity.feature_class_configuration = feature_class_configuration
        db_entity.save()
        DbEntityInterest._no_post_save_publishing = previous

    # Post save presentation section
    # Quit if the publishers were turned off outside this method
    if DbEntityInterest._no_post_save_publishing or db_entity_interest._no_post_save_publishing:
        return

    # Use this to initialize the FeatureBehavior and other stuff that might not be set
    update_or_create_db_entity(config_entity, db_entity)

    starting_signal_path = resolvable_module_attr_path(
        __name__, 'post_save_db_entity_initial')

    return post_save_publishing(
        starting_signal_path,
        config_entity,
        user,
        instance=db_entity_interest,
        instance_class=DbEntity,
        client_instance_path='db_entity',
        instance_key=db_entity_interest.db_entity.key,
        signal_proportion_lookup=signal_proportion_lookup,
        dependent_signal_paths=dependent_signal_paths,
        signal_prefix='post_save_db_entity',
        # Update the setup_percent_complete instance attribute for new instances
        # of classes with this attribute (currently only DbEntity)
        update_setup_percent_complete=db_entity_interest.db_entity.
        setup_percent_complete == 0,
        **filter_keys(kwargs, ['created']))
def on_db_entity_interest_post_save(sender, **kwargs):
    """
        Called after a DbEntityInterest saves, but not when a config_entity is running post_save publishers
        In other words, this is only called after a direct DbEntityInterest save/update.
        This does the same as post_save_config_entity, but starts with the 'post_save_config_entity_db_entities'
        signal to do only DbEntity dependent presentation.
    """
    db_entity_interest = kwargs['instance']
    config_entity = ConfigEntity._subclassed(db_entity_interest.config_entity)
    db_entity = db_entity_interest.db_entity
    # TODO The default user should be the admin
    user = db_entity.updater if db_entity.updater else get_user_model().objects.get(username=UserGroupKey.SUPERADMIN)
    # post_save_db_entity presentation should always be disabled if we are saving a ConfigEntity
    logger.info("Handler: post_save_db_entity_interest for config_entity {config_entity}, db_entity {db_entity}, "
                "and user {username}.".format(
        config_entity=config_entity,
        db_entity=db_entity_interest.db_entity,
        username=user.username
    ))

    if kwargs.get('created', None):
        db_entity = db_entity_interest.db_entity
        # TODO
        # While we test upload, just delete the previous DbEntitys with the same key name
        # in the ConfigEntity.
        db_entity_interest.config_entity.db_entities.filter(key=db_entity.key).exclude(id=db_entity.id).delete()

        # Make sure the db_entity's schema matches the config_entity's if not set
        # TODO we assume that the schema should match the config_entity, rather than
        # an ancestor or the config_entity (like the project or a scenario). There
        # are many cases where the schema should not be that of the config_entity, so
        # we might want to remove this default and force the saver to set it
        if not db_entity.schema or not db_entity.table:
            db_entity.schema = db_entity.schema or db_entity_interest.config_entity.schema()
            # Always base the table name on the key
            db_entity.table = db_entity.key
            db_entity_interest.db_entity.save()

    if db_entity_interest.config_entity.deleted:
        # Do nothing for deleted config_entities
        return

    # Define the data_importer if not already set
    if not (db_entity.feature_class_configuration and db_entity.feature_class_configuration.data_importer):
        feature_class_configuration = db_entity.feature_class_configuration = db_entity.feature_class_configuration or FeatureClassConfiguration()
        # Choose the correct importer, if any, to set up the feature_class_configuration and features
        if db_entity.origin_instance:
            # Import from the origin_instance. This could be a full copy or from the current layer selection features
            feature_class_configuration.data_importer = full_module_path(OriginDbEntityProcessor)
        elif '.json' in db_entity.url.lower():
            # Import it using the geojson importer
            feature_class_configuration.data_importer = full_module_path(GeoJsonProcessor)
            # Indicate that the feature class configuration was generated not fixture based
            feature_class_configuration.generated = True
        elif '.zip' in db_entity.url.lower():
            feature_class_configuration.data_importer = full_module_path(ZippedSqlFileProcessor)
            # Indicate that the feature class configuration was generated not fixture based
            feature_class_configuration.generated = True
        elif not db_entity.no_feature_class_configuration:
            feature_class_configuration.data_importer = full_module_path(DefaultImportProcessor)
        previous = DbEntityInterest._no_post_save_publishing
        DbEntityInterest._no_post_save_publishing = True
        db_entity.feature_class_configuration = feature_class_configuration
        db_entity.save()
        DbEntityInterest._no_post_save_publishing = previous

    # Post save presentation section
    # Quit if the publishers were turned off outside this method
    if DbEntityInterest._no_post_save_publishing or db_entity_interest._no_post_save_publishing:
        return

    # Use this to initialize the FeatureBehavior and other stuff that might not be set
    update_or_create_db_entity(config_entity, db_entity)

    starting_signal_path = resolvable_module_attr_path(__name__, 'post_save_db_entity_initial')

    return post_save_publishing(
        starting_signal_path,
        config_entity,
        user,
        instance=db_entity_interest,
        instance_class=DbEntity,
        client_instance_path='db_entity',
        instance_key=db_entity_interest.db_entity.key,
        signal_proportion_lookup=signal_proportion_lookup,
        dependent_signal_paths=dependent_signal_paths,
        signal_prefix='post_save_db_entity',
        # Update the setup_percent_complete instance attribute for new instances
        # of classes with this attribute (currently only DbEntity)
        update_setup_percent_complete=db_entity_interest.db_entity.setup_percent_complete == 0,
        **filter_keys(kwargs, ['created'])
    )