Ejemplo n.º 1
0
def on_config_entity_post_save_layer(sender, **kwargs):
    """
        Sync tilestache to a ConfigEntity class after the latter is saved
        :param **kwargs: optional "db_entity_keys" to limit the layers created to those DbEntities
    """
    from footprint.client.configuration.fixture import LayerConfigurationFixture
    from footprint.client.configuration.utils import resolve_fixture
    # Disable post save publishing on individual layers. The ConfigEntity is controlling publishing
    config_entity = InstanceBundle.extract_single_instance(**kwargs)
    logger.info("Handler: on_config_entity_post_save_layer for %s" %
                config_entity.full_name)

    #    Create LayerLibrary instances based on each LayerLibrary configuration if the configuration's scope
    #    matches that of config_entity
    client_layer_fixture = resolve_fixture("presentation",
                                           "layer",
                                           LayerConfigurationFixture,
                                           config_entity.schema(),
                                           config_entity=config_entity)

    layer_library_configurations = FixtureList(
        client_layer_fixture.layer_libraries()).matching_scope(
            class_scope=config_entity.__class__)
    logger.info("Processing LayerLibrary Configurations %s" % ', '.join(
        map(
            lambda layer_library_configuration: layer_library_configuration.
            key, layer_library_configurations)))

    for layer_library_configuration in layer_library_configurations:
        _update_or_create_layer_library_and_layers(
            config_entity, layer_library_configuration, **kwargs)

    reset_queries()
Ejemplo n.º 2
0
    def built_form_sets(self):
        return FixtureList([
            dict(
                scope=GlobalConfig,
                key='uf_urban_placetypes',
                name='UF Placetypes',
                description='BuiltFormSet containing only placetypes',
                attribute='building_attribute_set',

                clazz=UrbanPlacetype,
                client='default'
            ),
            dict(
                scope=GlobalConfig,
                key='uf_building_types',
                name='UF BuildingTypes',
                description='BuiltFormSet containing only buildingtypes',
                attribute='building_attribute_set',

                clazz=BuildingType,
                client='default'
            )
            # We never present a Building BuiltFormSet
            # dict(
            #     scope=GlobalConfig,
            #     key='uf_buildings',
            #     name='Buildings',
            #     description='BuiltFormSet containing only buildings',
            #     attribute='building_attribute_set',
            #
            #     clazz=Building,
            #     client='default'
            # )
        ]).matching_scope(class_scope=self.config_entity and self.config_entity.__class__)
    def default_analysis_module_configurations(self, class_scope=None):

        config_entity = self.config_entity

        uf_analysis_module = lambda module: 'footprint.main.models.analysis_module.%s' % module
        # 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 configuration: AnalysisModuleConfiguration.
            analysis_module_configuration(config_entity, **configuration),
            FixtureList([
                dict(class_scope=Scenario,
                     key=AnalysisModuleKey.MERGE_MODULE,
                     name='Merge Feature Module',
                     analysis_tools=[
                         dict(class_name=uf_analysis_module(
                             'merge_module.merge_updater_tool.MergeUpdaterTool'
                         ),
                              key=AnalysisToolKey.MERGE_UPDATER_TOOL,
                              behavior=get_behavior('update_tool'))
                     ])
            ]).matching_scope(
                class_scope=config_entity and config_entity.__class__))
 def regions(self, region_keys=None, class_scope=None):
     return FixtureList([
         dict(
             key='scag',
             name='The SCAG Region',
             description='Jurisdictions of the SCAG Region',
             media=[
                 MediumFixture(
                     key=ConfigEntityMediumKey.Fab.ricate('scag_logo'),
                     name='SCAG Logo',
                     url='/static/client/{0}/logos/scag_dm.png'.format(
                         settings.CLIENT))
             ],
             #defaulting to an Irvine view for the moment
             bounds=MultiPolygon([
                 Polygon((
                     (-117.869537353516, 33.5993881225586),
                     (-117.869537353516, 33.7736549377441),
                     (-117.678024291992, 33.7736549377441),
                     (-117.678024291992, 33.5993881225586),
                     (-117.869537353516, 33.5993881225586),
                 ))
             ]))
     ]).matching_keys(key=region_keys).matching_scope(
         class_scope=class_scope)
Ejemplo n.º 5
0
 def default_remote_db_entities(self):
     # A list of simple dictionaries containing a key, url and optional hosts array, that describe how to
     # configure a remote db_entity. If this method is not overridden, it simply delegates to the parent fixture
     is_own_parent = self.parent_fixture.__class__ == self.__class__
     return self.parent_fixture.default_remote_db_entities(
     ) if self.ancestor_config_entity and not is_own_parent else FixtureList(
         [])
Ejemplo n.º 6
0
    def users(self, **kwargs):
        key = self.config_entity.key
        return FixtureList(

            # A Region level user for the county
            [dict(groups=[self.config_entity.user_group_name(UserGroupKey.ADMIN)],
                 class_scope=Region,
                 username='******',
                 password='******',
                 email='*****@*****.**'),

            # A Project manager level user for each city
            dict(groups=[self.config_entity.user_group_name(UserGroupKey.MANAGER)],
                 class_scope=Project,
                 # User name is [city]_manager
                 username='******' % key,
                 password='******' % key,
                 email='*****@*****.**' % key),

            # A Project user level user for each city
            dict(groups=[self.config_entity.user_group_name(UserGroupKey.USER)],
                 class_scope=Project,
                 # User name is [city]_manager
                 username='******' % key,
                 password='******' % key,
                 email='*****@*****.**' % key)]

            # No Scenario level users (although a group for each Scenario does exist)

        ).matching_scope(class_scope=self.config_entity.__class__, delete_scope_keys=True)
    def users(self, **kwargs):
        # A sample user who belongs to the client ConfigEntity's director group
        # This user therefore has full permission to all config_entities of the demo client

        # A Region level user
        region_admin = {
            'groups': [self.config_entity.user_group_name(UserGroupKey.ADMIN)],
            'class_scope': Region,
            'username': '******',
            'password': '******',
            'first_name': 'scag_dm',
            'last_name': 'admin',
            'email': '*****@*****.**'
        }

        # A Project level user for each city
        project_manager = {
            'groups':
            [self.config_entity.user_group_name(UserGroupKey.MANAGER)],
            'class_scope': Project,
            # User name is [city]_manager
            'username': '******' % self.config_entity.key,
            'password': '******' % self.config_entity.key,
            'first_name': self.config_entity.name,
            'last_name': 'Manager',
            'email': '*****@*****.**' % self.config_entity.key,
        }

        # A Scenario level user for each city
        user = {
            # Make sure to include the groups of all sibling scenarios. Even if they haven't all been
            # created yet, the final scenario will capture all scenario groups
            #'groups': [scenario.user_group_name(UserGroupKey.USER) for
            #           scenario in self.config_entity.parent_config_entity.children()],
            #'class_scope': Scenario,
            # User name is [city]_[i]
            #'username': '******' % self.config_entity.parent_config_entity.name.replace(" ", "").lower(),
            #'password': '******' % self.config_entity.parent_config_entity.name.replace(" ", "").strip(),
            #'first_name': self.config_entity.parent_config_entity.name,
            #'last_name': 'Planner',
            #'email': '*****@*****.**' % self.config_entity.parent_config_entity.name.replace(" ", "").lower()
            'groups': [self.config_entity.user_group_name(UserGroupKey.USER)],
            'class_scope': Project,
            'username': '******' % self.config_entity.key,
            'password': '******' % self.config_entity.key,
            'first_name': self.config_entity.name,
            'last_name': 'Planner',
            'email': '*****@*****.**' % self.config_entity.key,
        }

        # TODO:
        #   This is an experiment to not create users that are in the
        #   fixtures in order to test footprint_init performance without
        #   as many users. For now, we simply return pass as emtpty array
        #   to FixtureList()
        return FixtureList([region_admin, project_manager,
                            user]).matching_scope(
                                class_scope=self.config_entity.__class__,
                                delete_scope_keys=True)
Ejemplo n.º 8
0
    def import_db_entity_configurations(self, **kwargs):
        project = self.config_entity

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

        return map(
            lambda db_entity_dict: update_or_create_db_entity(project, db_entity_dict['value']),
            FixtureList([
                # This fixtures tests uploading a layer that came from UF by exporting to GDB
                # It verifies that we can handle an existing id column, which gets renamed to id_1
                # so that we can add a new primary key
                dict(
                    value=DbEntity(
                        name='RPLines0414',
                        key='rplines0414_1111',
                        url='file:///srv/calthorpe_media/test_uploads/dataset_57180_ed0d4399083743dbbc607a2d6a92c330.sql.zip',
                        creator=get_user_model().objects.get(username=UserGroupKey.SUPERADMIN),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('reference'),
                            intersection=GeographicIntersection.polygon_to_polygon
                        ),
                        _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
                )),
                # This fixture tests a largish dataset
                dict(
                    value=DbEntity(
                        name='CPAD',
                        key='cpad_1454089444918',
                        url='file:///tmp/dataset_48424_45cbd88ea090485f93c72df2fd905701.sql.zip',
                        creator=get_user_model().objects.get(username=UserGroupKey.SUPERADMIN),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('reference'),
                            intersection=GeographicIntersection.polygon_to_polygon
                        ),
                        _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
                )),
                # This fixture tests a small dataset
                dict(
                    value=DbEntity(
                        name='Lightrail',
                        key='lightrail_111111',
                        url='dataset_48708_d60bf2da001a44e8ab534dced4fb7478.sql.zip',
                        creator=get_user_model().objects.get(username=UserGroupKey.SUPERADMIN),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('reference'),
                            intersection=GeographicIntersection.polygon_to_polygon
                        ),
                        _categories=[Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION, value=DbEntityCategoryKey.REFERENCE)]
                )),
            ]))
Ejemplo n.º 9
0
    def default_analysis_module_configurations(self, **kwargs):
        config_entity = self.config_entity
        uf_analysis_module = lambda module: 'footprint.main.models.analysis_module.%s' % module

        behavior_key = BehaviorKey.Fab.ricate
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return map(
            lambda configuration:
            AnalysisModuleConfiguration.analysis_module_configuration(config_entity, **configuration),
            FixtureList([]).matching_scope(class_scope=self.config_entity and self.config_entity.__class__)
        )
Ejemplo n.º 10
0
 def built_form_sets(self):
     return self.parent_fixture.built_form_sets() + FixtureList([
         dict(
             scope=Region,
             key='scag_land_uses',
             attribute='scag_land_use_definition',
             name='SCAG Land Uses',
             description='SCAG Land Use Codes',
             client='scag_dm',
             clazz=BuildingType,
         ),
     ]).matching_scope(
         class_scope=self.config_entity and self.config_entity.__class__)
Ejemplo n.º 11
0
 def projects(self,
              region=None,
              region_keys=None,
              project_keys=None,
              class_scope=None):
     return FixtureList([{
         'key': 'elk_grv',
         'import_key': 'elk_grove',
         'name': 'City of Elk Grove',
         'description': "City of Elk Grove",
         'base_year': 2013,
         'region_key': 'sac_cnty',
         'media': [],
     }]).matching_keys(
         region_keys=region_keys,
         key=project_keys).matching_scope(class_scope=class_scope)
Ejemplo n.º 12
0
    def scenarios(self, project=None, region_keys=None, project_keys=None, scenario_keys=None, class_scope=None):

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

        return FixtureList([
            {
                'class_scope': BaseScenario,
                'key': '{0}_s'.format(project.key),
                'scope': project.schema(),
                'name': '{0}'.format(project.name),
                'description': '{0} layers {1}'.format('2014', project.name),
                'year': 2014,
                'behavior': get_behavior('base_scenario'),
                'categories': [Category(key='category', value='base_year')]
            }]).matching_keys(region_key=region_keys, project_key=project.key if project else project_keys, key=scenario_keys).\
           matching_scope(class_scope=class_scope)
Ejemplo n.º 13
0
def update_or_create_layer_library_and_layers(config_entity, **kwargs):
    #    Create LayerLibrary instances based on each LayerLibrary configuration if the configuration's scope
    #    matches that of config_entity
    client_layer_fixture = resolve_fixture("presentation",
                                           "layer",
                                           LayerConfigurationFixture,
                                           config_entity.schema(),
                                           config_entity=config_entity)

    layer_library_configurations = FixtureList(
        client_layer_fixture.layer_libraries()).matching_scope(
            class_scope=config_entity.__class__)
    logger.info("Processing LayerLibrary Configurations %s" % ', '.join(
        map(
            lambda layer_library_configuration: layer_library_configuration.
            key, layer_library_configurations)))

    for layer_library_configuration in layer_library_configurations:
        _update_or_create_layer_library_and_layers(
            config_entity, layer_library_configuration, **kwargs)
Ejemplo n.º 14
0
 def result_libraries(self):
     """
         Used to update or create ResultLibraries per ConfigEntity instance
         Returns the result library(ies) scoped for the class of self.config_entity
     :return:
     """
     return FixtureList(
         map(
             lambda result_library_key: ResultLibraryConfiguration(
                 key=result_library_key,
                 name='{0} %s Result Library' % capitalize(
                     result_library_key),
                 description='The %s result library for {0}' %
                 capitalize(result_library_key)), [
                     ResultLibraryKey.DEFAULT, ResultLibraryKey.APPLICATION,
                     ResultLibraryKey.WATER, ResultLibraryKey.ENERGY,
                     ResultLibraryKey.VMT, ResultLibraryKey.FISCAL,
                     ResultLibraryKey.AGRICULTURE_ANALYSIS,
                     ResultLibraryKey.PUBLIC_HEALTH
                 ]))
Ejemplo n.º 15
0
 def built_form_sets(self):
     return self.parent_fixture.built_form_sets() + FixtureList([
         dict(
             scope=Region,
             key='sacog_building_type',
             attribute='building_attribute_set',
             name='SACOG Buildingtypes',
             description='Built Forms for SACOG',
             client='sacog',
             clazz=BuildingType,
         ),
         dict(
             scope=Region,
             key='sacog_rucs',
             name='RUCS Types',
             attribute='agriculture_attribute_set',
             description='SACOG RUCS types',
             client=False,
             clazz=CropType,
         ),
     ]).matching_scope(
         class_scope=self.config_entity and self.config_entity.__class__)
 def import_scenarios(self, origin_instance):
     return FixtureList([
         dict(
             class_scope=FutureScenario,
             key=origin_instance.key[0:10:]+'_future_clone',
             name=origin_instance.name[0:10]+' Future Clone',
             parent_config_entity=origin_instance.parent_config_entity,
             origin_instance=origin_instance,
             bounds=origin_instance.bounds,
             description=origin_instance.description+' Future Clone',
             year=origin_instance.year
         ),
         dict(
             class_scope=BaseScenario,
             key=origin_instance.key[0:10]+'_base_clone',
             name=origin_instance.name[0:10]+' Base Clone',
             parent_config_entity=origin_instance.parent_config_entity,
             origin_instance=origin_instance,
             bounds=origin_instance.bounds,
             description=origin_instance.description+' Base Clone',
             year=origin_instance.year
         )
     ]).matching_scope(class_scope=origin_instance.__class__)
Ejemplo n.º 17
0
 def regions(self, region_keys=None, class_scope=None):
     return FixtureList([
         {
             'key':
             'sac_cnty',
             'name':
             'Sacramento County',
             'description':
             'Sacramento County',
             'bounds':
             MultiPolygon([
                 Polygon((
                     (-122.719, 37.394),  # bottom left
                     (-122.719, 38.059),  # top left
                     (-121.603, 38.059),  # top right
                     (-121.603, 37.394),  # bottom right
                     (-122.719,
                      37.394),  # bottom leftsample_config_entities
                 ))
             ])
         },
     ]).matching_keys(key=region_keys).matching_scope(
         class_scope=class_scope)
Ejemplo n.º 18
0
    def scenarios(self,
                  project=None,
                  region_keys=None,
                  project_keys=None,
                  scenario_keys=None,
                  class_scope=None):

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

        return FixtureList([
            {
                'class_scope': BaseScenario,
                'key': 'base_condition',
                'scope': project.schema(),
                'name': 'Base Condition',
                'description': '{0} Base Scenario {1}'.format('2012', project.name),
                'year': 2012,
                 # Used on the front-end only.
                'behavior': get_behavior('base_scenario')
            },
            {
                'class_scope': FutureScenario,
                'key': 'scenario_a',
                'scope': project.schema(),
                'name': 'Scenario A',
                'description': 'Future Scenario for {0}'.format(project.name),
                'year': 2050,
                # Used on the front-end only
                'behavior': get_behavior('future_scenario')
            }]).matching_keys(
                    region_key=region_keys,
                    project_key=project.key if project else None,
                    key=scenario_keys).\
                matching_scope(class_scope=class_scope)
Ejemplo n.º 19
0
    def default_db_entities(self):
        """
            Scenarios define DbEntities specific to the Scenario. Creates a list a dictionary of configuration functionality.
            These are filtered based on whether the given scenario matches the scope in the configuration
        :return:
        """
        project = self.config_entity.parent_config_entity_subclassed

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

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

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

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

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

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

        # TODO: Disabled the 'sacog_background' 'remote db entity' b/c it is throwing errors (2016-07-06)
        # return default_db_entities + remote_db_entity_setups + FixtureList([
        return default_db_entities + FixtureList([
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=DbEntityKey.REGION_PRIMARY_GEOGRAPHY,
                    # Override. If a name override is supplied, put it in. Otherwise leave null to derive it from the key
                    name='Urban Base Canvas (UF)',
                    # name=get_property_path(kwargs, 'overrides.%s.name' % Key.BASE),
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=CanvasFeature,
                        # The Base Feature is normally considered a primary_geography unless overridden
                        primary_geography=True,
                        primary_key='geography_id',
                        primary_key_type='int',
                        # The Base Feature is normally associated to a subclass of Geography unless overridden
                        geography_class_name=get_property_path(
                            kwargs, 'overrides.%s.geography_class_name' %
                            Key.BASE_CANVAS)
                        or 'footprint.main.models.geographies.parcel.Parcel',
                        # Create a built_form ForeignKey to a single BuiltForm,
                        # by initially joining our 'built_form_key' attribute to its 'key' attribute
                        related_fields=dict(built_form=dict(
                            single=True,
                            related_class_name=uf_model(
                                'built_form.built_form.BuiltForm'),
                            source_class_join_field_name='built_form_key',
                            related_class_join_field_name='key',
                        ))),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('base_feature'), ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_TRACTS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusTract),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_BLOCKGROUPS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusBlockgroup),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.CENSUS_BLOCK,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=CensusBlock),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_centroid),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.LIGHT_RAIL,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SacogLightRailFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(key=Key.LIGHT_RAIL_STOPS,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=SacogLightRailStopsFeature),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('reference'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.LIGHT_RAIL_STOPS_ONE_MILE,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogLightRailStopsOneMileFeature, ),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_polygon
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.LIGHT_RAIL_STOPS_HALF_MILE,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogLightRailStopsHalfMileFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_polygon
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.LIGHT_RAIL_STOPS_QUARTER_MILE,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogLightRailStopsQuarterMileFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('reference'),
                        intersection=GeographicIntersection.polygon_to_polygon
                    ),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.VERNAL_POOL,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogVernalPoolFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('environmental_constraint')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.WETLAND,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogWetlandFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('environmental_constraint')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
            update_or_create_db_entity(
                config_entity,
                DbEntity(
                    key=Key.STREAM,
                    feature_class_configuration=FeatureClassConfiguration(
                        abstract_class=SacogStreamFeature),
                    feature_behavior=FeatureBehavior(
                        behavior=get_behavior('environmental_constraint')),
                    _categories=[
                        Category(key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                    ])),
        ])
Ejemplo n.º 21
0
 def layers(self, class_scope=None):
     # Combine parent fixture layers with the layers matching the given ConfigEntity scope
     return self.parent_fixture.layers() + FixtureList([
         # LayerConfiguration(
         #     library_keys=[LayerLibraryKey.APPLICATION],
         #     name='Existing Land Use Parcels 2012',
         #     db_entity_key=ScagDmDbEntityKey.EXISTING_LAND_USE_PARCELS_2012,
         #     column_alias_lookup=dict(land_use_definition__id='land_use_definition_id'),
         #     built_form_set_key='scag_land_uses',
         #     layer_style=primary_base_layer_style(ScagDmLandUseDefinition, True)
         # ),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             name='Existing Land Use Parcels 2016',
             db_entity_key=ScagDmDbEntityKey.EXISTING_LAND_USE_PARCELS_2016,
             # visible=True,
             column_alias_lookup=dict(
                 land_use_definition__id='land_use_definition_id'),
             built_form_set_key='scag_land_uses',
             layer_style=primary_base_layer_style(ScagDmLandUseDefinition,
                                                  True)),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.GENERAL_PLAN_PARCELS,
             visible=True,
             column_alias_lookup=dict(
                 land_use_definition__id='land_use_definition_id'),
             built_form_set_key='scag_land_uses',
             layer_style=primary_base_layer_style(ScagDmLandUseDefinition)),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.SPECIFIC_PLAN_PARCELS,
             column_alias_lookup=dict(
                 land_use_definition__id='land_use_definition_id'),
             built_form_set_key='scag_land_uses',
             layer_style=primary_base_layer_style(ScagDmLandUseDefinition)),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.ZONING_PARCELS,
             column_alias_lookup=dict(
                 land_use_definition__id='land_use_definition_id'),
             built_form_set_key='scag_land_uses',
             layer_style=primary_base_layer_style(ScagDmLandUseDefinition)),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.ENTITLEMENT_PARCELS_2016,
             layer_style=dict(
                 geometry_type=GeometryTypeKey.POLYGON,
                 style_attributes=[
                     dict(attribute='is_modified',
                          opacity=0.5,
                          style_type=StyleTypeKey.CATEGORICAL,
                          style_value_contexts=[
                              StyleValueContext(value='true',
                                                symbol='=',
                                                style=Style(
                                                    polygon_fill='#FF530D',
                                                    line_color='#66a0b2',
                                                    line_width=1,
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='false',
                                                symbol='=',
                                                style=Style(
                                                    polygon_fill='#2AE824',
                                                    line_color='#66a0b2',
                                                    line_width=1,
                                                    polygon_opacity=0.4))
                          ])
                 ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.SCENARIO_PLANNING_ZONES,
             layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                              style_attributes=[
                                  dict(style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   line_color='#E60000',
                                                   line_width=3))
                                       ])
                              ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.REGION_SPHERE_OF_INFLUENCE,
             layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                              style_attributes=[
                                  dict(style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   line_color='#FFCC00',
                                                   line_width=5,
                                                   line_opacity=0.8))
                                       ])
                              ])),
         LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                            db_entity_key=ScagDmDbEntityKey.TIER2_TAZ,
                            layer_style=dict(
                                geometry_type=GeometryTypeKey.POLYGON,
                                style_attributes=[
                                    dict(style_type=StyleTypeKey.SINGLE,
                                         style_value_contexts=[
                                             StyleValueContext(
                                                 value=None,
                                                 symbol=None,
                                                 style=Style(
                                                     line_color='#00CC99',
                                                     line_width=4))
                                         ])
                                ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.HABITAT_CONSERVATION_AREA,
             layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                              style_attributes=[
                                  dict(opacity=0.5,
                                       style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   polygon_fill='#009966',
                                                   line_color='#006644',
                                                   line_width=1,
                                                   polygon_opacity=0.4))
                                       ])
                              ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.ENDANGERED_SPECIES,
             layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                              style_attributes=[
                                  dict(style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   line_color='#009929',
                                                   line_opacity=1,
                                                   line_width=3))
                                       ])
                              ])),
         LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                            db_entity_key=ScagDmDbEntityKey.COUNTY_BOUNDARY,
                            layer_style=dict(
                                geometry_type=GeometryTypeKey.POLYGON,
                                style_attributes=[
                                    dict(style_type=StyleTypeKey.SINGLE,
                                         style_value_contexts=[
                                             StyleValueContext(
                                                 value=None,
                                                 symbol=None,
                                                 style=Style(
                                                     line_color='#FFFFCC',
                                                     line_opacity=1,
                                                     line_width=6))
                                         ])
                                ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             name='2040 Transit Priority Areas',
             db_entity_key=ScagDmDbEntityKey.TRANSIT_PRIORITY_AREAS,
             layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                              style_attributes=[
                                  dict(style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   line_color='#CC00FF',
                                                   line_width=2))
                                       ])
                              ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             name='2040 Major Transit Stops',
             db_entity_key=ScagDmDbEntityKey.MAJOR_TRANSIT_STOPS,
             layer_style=dict(
                 geometry_type=GeometryTypeKey.POINT,
                 style_attributes=[
                     dict(style_type=StyleTypeKey.SINGLE,
                          style_value_contexts=[
                              StyleValueContext(
                                  value=None,
                                  symbol=None,
                                  style=Style(marker_fill='#000080',
                                              marker_width=10,
                                              marker_line_color='white',
                                              marker_line_width=1))
                          ])
                 ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             name='2040 High Quality Transit Areas',
             db_entity_key=ScagDmDbEntityKey.HIGH_QUALITY_TRANSIT_AREAS,
             layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                              style_attributes=[
                                  dict(style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   polygon_fill='#CC00FF',
                                                   polygon_opacity=0.15,
                                                   line_color='#CC00FF',
                                                   line_width=4,
                                                   line_opacity=0.5))
                                       ])
                              ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             name='2040 High Quality Transit Corridors',
             db_entity_key=ScagDmDbEntityKey.HIGH_QUALITY_TRANSIT_CORRIDORS,
             layer_style=dict(geometry_type=GeometryTypeKey.LINESTRING,
                              style_attributes=[
                                  dict(style_type=StyleTypeKey.SINGLE,
                                       style_value_contexts=[
                                           StyleValueContext(
                                               value=None,
                                               symbol=None,
                                               style=Style(
                                                   line_color='#660066',
                                                   line_width=6))
                                       ])
                              ])),
         LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                            db_entity_key=ScagDmDbEntityKey.CENSUS_TRACTS,
                            layer_style=dict(
                                geometry_type=GeometryTypeKey.POLYGON,
                                style_attributes=[
                                    dict(style_type=StyleTypeKey.SINGLE,
                                         style_value_contexts=[
                                             StyleValueContext(
                                                 value=None,
                                                 symbol=None,
                                                 style=Style(
                                                     line_color='#990000',
                                                     line_opacity=0.8,
                                                     line_width=3))
                                         ])
                                ])),
         LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                            db_entity_key=ScagDmDbEntityKey.SUB_REGION,
                            layer_style=dict(
                                geometry_type=GeometryTypeKey.POLYGON,
                                style_attributes=[
                                    dict(style_type=StyleTypeKey.SINGLE,
                                         style_value_contexts=[
                                             StyleValueContext(
                                                 value=None,
                                                 symbol=None,
                                                 style=Style(
                                                     line_color='#FFCC00',
                                                     line_width=6,
                                                     line_opacity=0.8))
                                         ])
                                ])),
         LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                            db_entity_key=ScagDmDbEntityKey.CITY_BOUNDARY,
                            visible=True,
                            layer_style=dict(
                                geometry_type=GeometryTypeKey.POLYGON,
                                style_attributes=[
                                    dict(style_type=StyleTypeKey.SINGLE,
                                         style_value_contexts=[
                                             StyleValueContext(
                                                 value=None,
                                                 symbol=None,
                                                 style=Style(
                                                     line_color='#000000',
                                                     line_opacity=1,
                                                     line_width=3))
                                         ])
                                ])),
         LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                            db_entity_key=ScagDmDbEntityKey.SEA_LEVEL_RISE,
                            layer_style=dict(
                                geometry_type=GeometryTypeKey.POLYGON,
                                style_attributes=[
                                    dict(style_type=StyleTypeKey.SINGLE,
                                         style_value_contexts=[
                                             StyleValueContext(
                                                 value=None,
                                                 symbol=None,
                                                 style=Style(
                                                     polygon_fill='#00007f',
                                                     line_color='#808080',
                                                     polygon_opacity=0.1))
                                         ])
                                ])),
         # LayerConfiguration(
         #     library_keys=[LayerLibraryKey.APPLICATION],
         #     db_entity_key=ScagDmDbEntityKey.BIKE_LANE,
         #     layer_style=dict(
         #         geometry_type=GeometryTypeKey.LINESTRING,
         #         style_attributes=[
         #             dict(
         #                 attribute='status',
         #                 style_type=StyleTypeKey.CATEGORICAL,
         #                 style_value_contexts=[
         #                     StyleValueContext(value='Existing', symbol='=', style=Style(
         #                         line_color='#00cc88',
         #                         line_width=4
         #                     )),
         #
         #                     StyleValueContext(value='Proposed', symbol='=', style=Style(
         #                         line_color='#ff9a00',
         #                         line_width=4
         #                     ))
         #                 ]
         #             )
         #         ]
         #     )
         # ),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.FLOOD_ZONES,
             layer_style=dict(
                 geometry_type=GeometryTypeKey.POLYGON,
                 style_attributes=[
                     dict(attribute='scag_fld_zone',
                          style_type=StyleTypeKey.CATEGORICAL,
                          style_value_contexts=[
                              StyleValueContext(
                                  value='100-year Flood Hazard Zone',
                                  symbol='=',
                                  style=Style(
                                      polygon_fill='#A900E6',
                                      line_color='#d3d3d3',
                                      line_width=1,
                                      line_opacity=0.8,
                                      polygon_opacity=0.4,
                                  )),
                              StyleValueContext(
                                  value='500-year Flood Hazard Zone',
                                  symbol='=',
                                  style=Style(
                                      polygon_fill='#73B2FF',
                                      line_color='#d3d3d3',
                                      line_width=1,
                                      line_opacity=0.8,
                                      polygon_opacity=0.4,
                                  ))
                          ])
                 ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.CPAD_HOLDINGS,
             layer_style=dict(
                 global_opacity=0.6,
                 geometry_type=GeometryTypeKey.POLYGON,
                 style_attributes=[
                     dict(
                         attribute='layer_scag',
                         style_type=StyleTypeKey.CATEGORICAL,
                         style_value_contexts=[
                             StyleValueContext(
                                 value=
                                 'California Department of Fish and Wildlife',
                                 symbol='=',
                                 style=Style(
                                     line_color='#594',
                                     line_width=1,
                                     polygon_fill='#1A2E14',
                                 )),
                             StyleValueContext(
                                 value=
                                 'California Department of Parks and Recreation',
                                 symbol='=',
                                 style=Style(
                                     line_color='#594',
                                     line_width=1,
                                     polygon_fill='#00c5ff',
                                 )),
                             StyleValueContext(value="City",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#ff73df',
                                               )),
                             StyleValueContext(value="County",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#a900e6',
                                               )),
                             StyleValueContext(
                                 value="National Park Service",
                                 symbol='=',
                                 style=Style(
                                     line_color='#594',
                                     line_width=1,
                                     polygon_fill='#c89445',
                                 )),
                             StyleValueContext(
                                 value="Non Governmental Organization",
                                 symbol='=',
                                 style=Style(
                                     line_color='#594',
                                     line_width=1,
                                     polygon_fill='#a87000',
                                 )),
                             StyleValueContext(value="Other Federal",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#aaaa66',
                                               )),
                             StyleValueContext(value="Other State",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#6699cd',
                                               )),
                             StyleValueContext(value="Private",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#559944',
                                               )),
                             StyleValueContext(value="Special District",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#ffbee8',
                                               )),
                             StyleValueContext(
                                 value="US Bureau of Land Management",
                                 symbol='=',
                                 style=Style(
                                     line_color='#594',
                                     line_width=1,
                                     polygon_fill='#ffd37f',
                                 )),
                             StyleValueContext(
                                 value="US Fish and Wildlife Service",
                                 symbol='=',
                                 style=Style(
                                     line_color='#594',
                                     line_width=1,
                                     polygon_fill='#aaff00',
                                 )),
                             StyleValueContext(value="US Forest Service",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#7af5ca',
                                               )),
                             StyleValueContext(value="US Military/Defense",
                                               symbol='=',
                                               style=Style(
                                                   line_color='#594',
                                                   line_width=1,
                                                   polygon_fill='#686868',
                                               ))
                         ])
                 ])),
         LayerConfiguration(
             library_keys=[LayerLibraryKey.APPLICATION],
             db_entity_key=ScagDmDbEntityKey.FARMLAND,
             layer_style=dict(
                 geometry_type=GeometryTypeKey.POLYGON,
                 global_opacity=0.6,
                 style_attributes=[
                     dict(attribute='scag_type',
                          style_type=StyleTypeKey.CATEGORICAL,
                          style_value_contexts=[
                              StyleValueContext(value='P',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#8DB359',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='S',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#BED984',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='U',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#E2F7B0',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='G',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#E3DBC5',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='L',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#F9FCDE',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='LP',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#FCF6F2',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='X',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#EBECED',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='CI',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#B37B59',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='nv',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#DBC49A',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='V',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#D3D2D4',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='R',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#F2CED3',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='sAC',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#F5D489',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='D',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#F29DAA',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='W',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#96D0D6',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='I',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#ACC7A5',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='N',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#F0F0C2',
                                                    polygon_opacity=0.4)),
                              StyleValueContext(value='Z',
                                                symbol='=',
                                                style=Style(
                                                    line_color='#594',
                                                    line_width=1,
                                                    polygon_fill='#D4CFC7',
                                                    polygon_opacity=0.4)),
                          ])
                 ]))
     ])
Ejemplo n.º 22
0
 def layer_libraries(self, class_scope=None):
     return self.parent_fixture.layer_libraries(FixtureList(self.layers()))
Ejemplo n.º 23
0
    def results(self):
        """
            Used to update or create Results per ConfigEntity instance
            Returns the result library(ies) scoped for the class of self.config_entity.
            The Result will belong to the ResultLibrary specified by result_library_key
        :return:
        """
        return FixtureList(
            # Basic Core result query that summarizes increments
            self.parent_fixture.results() + [
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_db_entity_key=ResultKey.BASE_EMPLOYMENT_BY_TYPE,
                    source_db_entity_key=DbEntityKey.BASE_CANVAS,
                    name='Base: Employment by Sector',
                    attributes=[
                        'retail', 'office', 'industrial', 'public', 'other'
                    ],
                    db_column_lookup=dict(
                        retail='emp_ret',
                        office='emp_off',
                        industrial='emp_ind',
                        public='emp_pub',
                        other='emp_military',
                    ),
                    labels=[
                        'Retail', 'Office', 'Industrial', 'Public', 'Other'
                    ],
                    stackable=True,
                    is_stacked=False,
                    create_query=lambda result_config: self.
                    employment_breakdown_query(DbEntityKey.BASE_CANVAS),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_db_entity_key=ResultKey.BASE_DWELLING_UNITS_BY_TYPE,
                    source_db_entity_key=DbEntityKey.BASE_CANVAS,
                    name='Base: Dwelling Units by Type',
                    attributes=['single_family', 'attached', 'multifamily'],
                    db_column_lookup=dict(single_family='du_detsf',
                                          attached='du_attsf',
                                          multifamily='du_mf'),
                    labels=['Single Family', 'Attached', 'Multifamily'],
                    stackable=True,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_type='bar_graph',
                    result_db_entity_key=ResultKey.INCREMENTS,
                    source_db_entity_key=DbEntityKey.INCREMENT,
                    name='Increments: All Metrics',
                    attributes=['population', 'dwelling_units', 'employment'],
                    db_column_lookup=dict(population='pop',
                                          dwelling_units='du',
                                          employment='emp'),
                    extent_lookup=dict(
                        population=dict(min=-25000, max=25000),
                        dwelling_units=dict(min=-2500, max=2500),
                        employment=dict(min=-2500, max=2500),
                    ),
                    labels=['Population', 'Dwelling Units', 'Employment'],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE),

                # DB Entity Core result query that summarizes dwellings by type
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_type='bar_graph',
                    result_db_entity_key=ResultKey.
                    INCREMENTS_DWELLING_UNITS_BY_TYPE,
                    source_db_entity_key=DbEntityKey.INCREMENT,
                    name='Increments: Dwelling Units by Type',
                    attributes=[
                        'single_family_large_lot', 'single_family_small_lot',
                        'multifamily', 'attached_single_family'
                    ],
                    db_column_lookup=dict(
                        single_family_large_lot='du_detsf_ll',
                        single_family_small_lot='du_detsf_sl',
                        multifamily='du_mf',
                        attached_single_family='du_attsf',
                    ),
                    labels=[
                        'SF Large Lot', 'SF Small Lot', 'MF', 'Attached SF'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_type='bar_graph',
                    result_db_entity_key=ResultKey.
                    END_STATE_DWELLING_UNITS_BY_TYPE,
                    source_db_entity_key=DbEntityKey.END_STATE,
                    name='End State: Dwelling Units by Type',
                    attributes=[
                        'single_family_large_lot', 'single_family_small_lot',
                        'multifamily', 'attached_single_family'
                    ],
                    db_column_lookup=dict(
                        single_family_large_lot='du_detsf_ll',
                        single_family_small_lot='du_detsf_sl',
                        multifamily='du_mf',
                        attached_single_family='du_attsf',
                    ),
                    labels=[
                        'SF Large Lot', 'SF Small Lot', 'MF', 'Attached SF'
                    ],
                    stackable=True,
                    is_stacked=False,
                    show_attrs_as_percents=True,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_type='bar_graph',
                    result_db_entity_key=ResultKey.
                    INCREMENTS_EMPLOYMENT_BY_TYPE,
                    source_db_entity_key=DbEntityKey.INCREMENT,
                    name='Increments: Employment by Sector',
                    attributes=[
                        'retail', 'office', 'industrial', 'public', 'other'
                    ],
                    db_column_lookup=dict(
                        retail='emp_ret',
                        office='emp_off',
                        industrial='emp_ind',
                        public='emp_pub',
                        other='emp_military',
                    ),
                    labels=[
                        'Retail', 'Office', 'Industrial', 'Public', 'Other'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config: self.
                    employment_breakdown_query(DbEntityKey.INCREMENT),
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_type='bar_graph',
                    result_db_entity_key=ResultKey.
                    END_STATE_EMPLOYMENT_BY_TYPE,
                    source_db_entity_key=DbEntityKey.END_STATE,
                    name='End State: Employment by Sector',
                    attributes=[
                        'retail', 'office', 'industrial', 'public', 'other'
                    ],
                    db_column_lookup=dict(
                        retail='emp_ret',
                        office='emp_off',
                        industrial='emp_ind',
                        public='emp_pub',
                        other='emp_military',
                    ),
                    labels=[
                        'Retail', 'Office', 'Industrial', 'Public', 'Other'
                    ],
                    stackable=True,
                    is_stacked=False,
                    create_query=lambda result_config: self.
                    employment_breakdown_query(DbEntityKey.END_STATE),
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_type='analytic_bars',
                    result_db_entity_key=ResultKey.INCREMENTS_BARS,
                    source_db_entity_key=DbEntityKey.END_STATE,
                    name='Results Increments',
                    attributes=['population', 'dwelling_units', 'employment'],
                    db_column_lookup=dict(population='pop',
                                          dwelling_units='du',
                                          employment='emp'),
                    extent_lookup=dict(population=dict(min=0, max=5000000),
                                       dwelling_units=dict(min=0, max=1000000),
                                       employment=dict(min=0, max=1000000)),
                    labels=['Population', 'Dwelling Units', 'Employment'],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    library_keys=[ResultLibraryKey.FISCAL],
                    result_type='analytic_result',
                    result_db_entity_key=ResultKey.FISCAL,
                    source_db_entity_key=DbEntityKey.FISCAL,
                    name='Fiscal',
                    attributes=[
                        'capital_costs', 'operations_maintenance', 'revenue'
                    ],
                    db_column_lookup=dict(
                        capital_costs='residential_capital_costs',
                        operations_maintenance=
                        'residential_operations_maintenance_costs',
                        revenue='residential_revenue'),
                    labels=[
                        'capital_costs', 'operations_maintenance', 'revenue'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    result_type='analytic_result',
                    library_keys=[ResultLibraryKey.VMT],
                    result_db_entity_key=ResultKey.VMT,
                    source_db_entity_key=DbEntityKey.VMT,
                    name='VMT',
                    attributes=[
                        'annual_vmt', 'daily_vmt', 'daily_vmt_per_hh',
                        'annual_vmt_per_capita'
                    ],
                    db_column_lookup=dict(
                        annual_vmt='vmt_annual_w_trucks',
                        daily_vmt='vmt_daily_w_trucks',
                        daily_vmt_per_hh='vmt_daily_per_hh',
                        annual_vmt_per_capita='vmt_annual_per_capita'),
                    labels=[
                        'Annual VMT', 'Daily VMT', 'Daily VMT Per HH',
                        'Annual VMT Per Capita'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(vmt_annual_w_trucks) as annual_vmt__sum, SUM(vmt_daily_w_trucks) as daily_vmt__sum, Case when SUM(hh) > 0 then SUM(vmt_daily_w_trucks) / SUM(hh) else 0 end as daily_vmt_per_hh__sum, Case when SUM(hh) > 0 then SUM(vmt_daily_w_trucks) * 350 / SUM(hh) else 0 end as annual_vmt_per_hh__sum, Case when SUM(pop) > 0 then SUM(vmt_daily_w_trucks) * 350 / SUM(pop) else 0 end as annual_vmt_per_capita__sum, Case when SUM(pop) > 0 then SUM(vmt_daily_w_trucks) / SUM(pop) else 0 end as daily_vmt_per_capita__sum, Case when SUM(emp) > 0 then SUM(vmt_daily_w_trucks) / SUM(emp) else 0 end as daily_vmt_per_emp__sum, Case when SUM(emp) > 0 then SUM(vmt_daily_w_trucks) * 350 / SUM(emp) else 0 end as annual_vmt_per_emp__sum   FROM %({0})s'
                    .format(DbEntityKey.VMT),
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    result_type='analytic_result',
                    library_keys=[ResultLibraryKey.ENERGY],
                    result_db_entity_key=ResultKey.ENERGY,
                    source_db_entity_key=DbEntityKey.ENERGY,
                    name='Energy',
                    attributes=[
                        'total_gas_use', 'total_electricity_use',
                        'residential_gas_use', 'residential_electricity_use',
                        'commercial_gas_use', 'commercial_electricity_use'
                    ],
                    db_column_lookup=dict(
                        total_gas_use='total_gas_use',
                        total_electricity_use='total_electricity_use',
                        residential_gas_use='residential_gas_use',
                        residential_electricity_use=
                        'residential_electricity_use',
                        commercial_gas_use='commercial_gas_use',
                        commercial_electricity_use='commercial_electricity_use'
                    ),
                    labels=[
                        'total_gas_use', 'total_electricity_use',
                        'residential_gas_use', 'residential_electricity_use',
                        'commercial_gas_use', 'commercial_electricity_use'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(total_gas_use) as total_gas_use__sum, SUM(total_electricity_use) as total_electricity_use__sum, SUM(residential_gas_use) as residential_gas_use__sum, SUM(residential_electricity_use) as residential_electricity_use__sum, SUM(commercial_gas_use) as commercial_gas_use__sum, SUM(commercial_electricity_use) as commercial_electricity_use__sum, Case when SUM(hh) > 0 then SUM(residential_gas_use) / SUM(hh) else 0 end as residenital_per_hh_gas_use__sum, Case when SUM(hh) > 0 then SUM(residential_electricity_use) / SUM(hh) else 0 end as residenital_per_hh_electricity_use__sum, Case when SUM(total_commercial_sqft) > 0 then SUM(commercial_gas_use) / SUM(emp) else 0 end as commercial_per_emp_gas_use__sum, Case when SUM(total_commercial_sqft) > 0 then SUM(commercial_electricity_use) / SUM(emp) else 0 end as commercial_per_emp_electricity_use__sum FROM %({0})s'
                    .format(DbEntityKey.ENERGY),
                    sort_priority=ResultSort.FUTURE),
                ResultConfiguration(
                    result_type='analytic_result',
                    library_keys=[ResultLibraryKey.WATER],
                    result_db_entity_key=ResultKey.WATER,
                    source_db_entity_key=DbEntityKey.WATER,
                    name='Water',
                    attributes=[
                        'total_water_use', 'residential_water_use',
                        'commercial_water_use', 'residential_indoor_water_use',
                        'residential_outdoor_water_use',
                        'commercial_indoor_water_use',
                        'commercial_outdoor_water_use'
                    ],
                    db_column_lookup=dict(
                        total_water_use='total_water_use',
                        residential_water_use='residential_water_use',
                        commercial_water_use='commercial_water_use',
                        residential_indoor_water_use=
                        'residential_indoor_water_use',
                        residential_outdoor_water_use=
                        'residential_outdoor_water_use',
                        commercial_indoor_water_use=
                        'commercial_indoor_water_use',
                        commercial_outdoor_water_use=
                        'commercial_outdoor_water_use'),
                    labels=[
                        'total_water_use', 'residential_water_use',
                        'commercial_water_use', 'residential_indoor_water_use',
                        'residential_outdoor_water_use',
                        'commercial_indoor_water_use',
                        'commercial_outdoor_water_use'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE),

                # Aggregate result from the Analytic Bars
                ResultConfiguration(
                    result_type='analytic_bars',
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_db_entity_key=ResultKey.Fab.ricate('base_bars'),
                    source_db_entity_key=DbEntityKey.BASE_CANVAS,
                    name='Base Results',
                    attributes=['employment', 'dwelling_units', 'population'],
                    db_column_lookup=dict(employment='emp',
                                          dwelling_units='du',
                                          population='pop'),
                    extent_lookup=dict(population=dict(min=0, max=5000000),
                                       dwelling_units=dict(min=0, max=1000000),
                                       employment=dict(min=0, max=1000000)),
                    labels=['Employees', 'Dwelling Units', 'Population'],
                    stackable=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),

                #result configurartions for water analysis
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.WATER],
                    result_db_entity_key=ResultKey.WATER_INDOOR_OUTDOOR,
                    source_db_entity_key=DbEntityKey.WATER,
                    name='Water Use (gal): Indoor and Outdoor ',
                    attributes=[
                        'residential_indoor_water_use',
                        'residential_outdoor_water_use',
                        'commercial_indoor_water_use',
                        'commercial_outdoor_water_use'
                    ],
                    db_column_lookup=dict(residential_indoor_water_use=
                                          'residential_indoor_water_use',
                                          residential_outdoor_water_use=
                                          'residential_outdoor_water_use',
                                          commercial_indoor_water_use=
                                          'commercial_indoor_water_use',
                                          commercial_outdoor_water_use=
                                          'commercial_outdoor_water_use'),
                    labels=[
                        'Res-Indoor', 'Res-Outdoor', 'Com-Indoor',
                        'Com-Outdoor'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.WATER],
                    result_db_entity_key=ResultKey.WATER_TOTAL,
                    source_db_entity_key=DbEntityKey.WATER,
                    name='Water Use (gal): Residential and Commercial',
                    attributes=[
                        'residential_water_use', 'commercial_water_use'
                    ],
                    db_column_lookup=dict(
                        residential_water_use='residential_water_use',
                        commercial_water_use='commercial_water_use'),
                    labels=['Residential', 'Commercial'],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.WATER],
                    result_db_entity_key=ResultKey.WATER_COSTS_TOTAL,
                    source_db_entity_key=DbEntityKey.WATER,
                    name='Water Costs ($-2014): Residential and Commercial',
                    attributes=[
                        'residential_water_use', 'commercial_water_use'
                    ],
                    db_column_lookup=dict(
                        residential_water_use='residential_water_use',
                        commercial_water_use='commercial_water_use'),
                    labels=['Residential', 'Commercial'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(residential_water_use) / 325851.431889 * 1349.0 as residential_water_use__sum, SUM(commercial_water_use) / 325851.431889 * 1349.0 as commercial_water_use__sum from %({0})s'
                    .format(DbEntityKey.WATER),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.ENERGY],
                    result_db_entity_key=ResultKey.ENERGY_TOTAL,
                    source_db_entity_key=DbEntityKey.ENERGY,
                    name='Energy Use (MMBTU): Residential and Commercial',
                    attributes=[
                        'residential_energy_use', 'commercial_energy_use'
                    ],
                    db_column_lookup=dict(
                        residential_energy_use='residential_energy_use',
                        commercial_energy_use='commercial_energy_use'),
                    labels=['Residential', 'Commercial'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(residential_electricity_use) * 0.0034095106405145 + sum(residential_gas_use) * 0.1 as residential_energy_use__sum, SUM(commercial_electricity_use) * 0.0034095106405145 + sum(commercial_gas_use) * 0.1 as commercial_energy_use__sum from %({0})s'
                    .format(DbEntityKey.ENERGY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.ENERGY],
                    result_db_entity_key=ResultKey.ENERGY_RES_USE,
                    source_db_entity_key=DbEntityKey.ENERGY,
                    name='Energy Use (MMBTU): Residential by Type',
                    attributes=[
                        'du_detsf_ll_energy_use', 'du_detsf_sl_energy_use',
                        'du_attsf_energy_use', 'du_mf_energy_use'
                    ],
                    db_column_lookup=dict(
                        du_detsf_ll_energy_use='du_detsf_ll_energy_use',
                        du_detsf_sl_energy_use='du_detsf_sl_energy_use',
                        du_attsf_energy_use='du_attsf_energy_use',
                        du_mf_energy_use='du_mf_energy_use'),
                    labels=[
                        'SF Large Lot', 'SF Small Lot', 'Attached SF',
                        'Multifamily'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(du_detsf_ll_electricity_use) * 0.0034095106405145 + sum(du_detsf_ll_gas_use) * 0.1 as du_detsf_ll_energy_use__sum, SUM(du_detsf_sl_electricity_use) * 0.0034095106405145 + sum(du_detsf_sl_gas_use) * 0.1 as du_detsf_sl_energy_use__sum, SUM(du_attsf_electricity_use) * 0.0034095106405145 + sum(du_attsf_gas_use) * 0.1 as du_attsf_energy_use__sum, SUM(du_mf_electricity_use) * 0.0034095106405145 + sum(du_mf_gas_use) * 0.1 as du_mf_energy_use__sum from %({0})s'
                    .format(DbEntityKey.ENERGY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.ENERGY],
                    result_db_entity_key=ResultKey.ENERGY_COM_USE,
                    source_db_entity_key=DbEntityKey.ENERGY,
                    name='Energy Use (MMBTU): Commercial by Type',
                    attributes=[
                        'retail_energy_use', 'office_energy_use',
                        'public_energy_use', 'industrial_energy_use'
                    ],
                    db_column_lookup=dict(
                        retail_energy_use='retail_energy_use',
                        office_energy_use='office_energy_use',
                        public_energy_use='public_energy_use',
                        industrial_energy_use='industrial_energy_use'),
                    labels=['Retail', 'Office', 'Public', '*Industrial'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(retail_services_electricity_use + restaurant_electricity_use + accommodation_electricity_use + other_services_electricity_use) * 0.0034095106405145 + sum(retail_services_gas_use + restaurant_gas_use + accommodation_gas_use + other_services_gas_use) * 0.1 as retail_energy_use__sum, SUM(office_services_electricity_use + medical_services_electricity_use) * 0.0034095106405145 + sum(office_services_gas_use + medical_services_gas_use) * 0.1 as office_energy_use__sum, SUM(public_admin_electricity_use + education_electricity_use) * 0.0034095106405145 + sum(public_admin_gas_use + education_gas_use) * 0.1 as public_energy_use__sum, SUM(wholesale_electricity_use + transport_warehousing_electricity_use) * 0.0034095106405145 + sum(wholesale_gas_use + transport_warehousing_gas_use) * 0.1 as industrial_energy_use__sum from %({0})s'
                    .format(DbEntityKey.ENERGY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.ENERGY],
                    result_db_entity_key=ResultKey.ENERGY_COSTS_TOTAL,
                    source_db_entity_key=DbEntityKey.ENERGY,
                    name='Energy Costs ($-2014): Residential and Commercial',
                    attributes=[
                        'residential_energy_cost', 'commercial_energy_cost'
                    ],
                    db_column_lookup=dict(
                        residential_energy_cost='residential_energy_cost',
                        commercial_energy_cost='commercial_energy_cost'),
                    labels=['Residential', 'Commercial'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(residential_electricity_use) * 0.1802 + sum(residential_gas_use) * 1.203 as residential_energy_cost__sum, SUM(commercial_electricity_use) * 0.1822 + sum(commercial_gas_use) * 0.854 as commercial_energy_cost__sum from %({0})s'
                    .format(DbEntityKey.ENERGY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.ENERGY],
                    result_db_entity_key=ResultKey.ENERGY_EMISSIONS_TOTAL,
                    source_db_entity_key=DbEntityKey.ENERGY,
                    name='Energy Emissions (CO2e): Residential and Commercial',
                    attributes=[
                        'residential_energy_emissions',
                        'commercial_energy_emissions'
                    ],
                    db_column_lookup=dict(residential_energy_emissions=
                                          'residential_energy_emissions',
                                          commercial_energy_emissions=
                                          'commercial_energy_emissions'),
                    labels=['Residential', 'Commercial'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(residential_electricity_use) * 0.69 + sum(residential_gas_use) * 11.7 as residential_energy_emissions__sum, SUM(commercial_electricity_use) * 0.69 + sum(commercial_gas_use) * 11.7 as commercial_energy_emissions__sum from %({0})s'
                    .format(DbEntityKey.ENERGY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.FISCAL],
                    result_db_entity_key=ResultKey.FISCAL_CHART,
                    source_db_entity_key=DbEntityKey.FISCAL,
                    name='Fiscal ($-2012): Residential Costs/Revenue',
                    attributes=[
                        'residential_capital_costs',
                        'residential_operations_maintenance_costs',
                        'residential_revenue'
                    ],
                    db_column_lookup=dict(
                        residential_capital_costs='residential_capital_costs',
                        residential_operations_maintenance_costs=
                        'residential_operations_maintenance_costs',
                        residential_revenue='residential_revenue'),
                    labels=['Capital Costs', 'O&M Costs', 'Revenue'],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.VMT],
                    result_db_entity_key=ResultKey.VMT_PER_CAPITA,
                    source_db_entity_key=DbEntityKey.VMT,
                    name='Annual VMT: Per Capita / Per Employee',
                    attributes=['vmt_annual_per_capita', 'vmt_annual_per_emp'],
                    db_column_lookup=dict(
                        vmt_annual_per_capita='vmt_annual_per_capita',
                        vmt_annual_per_emp='vmt_annual_per_emp'),
                    labels=['Per Capita', 'Per Employee'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT Case when SUM(pop) > 0 then SUM(vmt_annual_w_trucks) / sum(pop) else 0 end as vmt_annual_per_capita__sum, Case when SUM(emp) > 0 then SUM(vmt_annual_w_trucks) / sum(emp) else 0 end as vmt_annual_per_emp__sum from %({0})s'
                    .format(DbEntityKey.VMT),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.VMT],
                    result_db_entity_key=ResultKey.VMT_FUEL,
                    source_db_entity_key=DbEntityKey.VMT,
                    name='Annual Fuel Consumption (gal)',
                    attributes=['annual_gallons'
                                ],
                    db_column_lookup=dict(annual_gallons='annual_gallons'),
                    labels=['Gallons'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(vmt_annual_w_trucks) / 19.4 as annual_gallons__sum from %({0})s'
                    .format(DbEntityKey.VMT),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.VMT],
                    result_db_entity_key=ResultKey.VMT_COSTS,
                    source_db_entity_key=DbEntityKey.VMT,
                    name='Annual Vehicle Costs ($-2014)',
                    attributes=['cost_per_mile'],
                    db_column_lookup=dict(cost_per_mile='cost_per_mile'),
                    labels=['Vehicle Costs'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(vmt_annual_w_trucks) * 0.35 as cost_per_mile__sum from %({0})s'
                    .format(DbEntityKey.VMT),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.VMT],
                    result_db_entity_key=ResultKey.VMT_EMISSIONS,
                    source_db_entity_key=DbEntityKey.VMT,
                    name='Annual Vehicle Emissions (lbs CO2e)',
                    attributes=['vehicle_emissions'],
                    db_column_lookup=dict(
                        vehicle_emissions='vehicle_emissions'),
                    labels=['Emissions'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(vmt_annual_w_trucks) *  0.9061 as vehicle_emissions__sum from %({0})s'
                    .format(DbEntityKey.VMT),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.PUBLIC_HEALTH],
                    result_db_entity_key=ResultKey.PH_WALKING_MINUTES,
                    source_db_entity_key=DbEntityKey.PH_BLOCK_GROUP_OUTCOMES,
                    name='Daily Walking Minutes - Per Capita',
                    attributes=[
                        'seniors_all_walk_minutes', 'adult_all_walk_minutes',
                        'teens_all_walk_minutes', 'children_all_walk_minutes'
                    ],
                    db_column_lookup=dict(
                        seniors_all_walk_minutes='seniors_all_walk_minutes',
                        adult_all_walk_minutes='adult_all_walk_minutes',
                        teens_all_walk_minutes='teens_all_walk_minutes',
                        children_all_walk_minutes='children_all_walk_minutes'),
                    labels=['Seniors', 'Adults', 'Teens', 'Children'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config: '''SELECT
                        CASE WHEN SUM(seniors_all_walk_minutes) > 0 then SUM(pop_senior * seniors_all_walk_minutes) / sum(pop_senior)
                        else 0 end as seniors_all_walk_minutes__sum,
                        CASE WHEN SUM(adult_all_walk_minutes) > 0 then SUM(pop_adult * adult_all_walk_minutes) / sum(pop_adult)
                        else 0 end as adult_all_walk_minutes__sum,
                        CASE WHEN SUM(teens_all_walk_minutes) > 0 then SUM(pop_teen * teens_all_walk_minutes) / sum(pop_teen)
                        else 0 end as teens_all_walk_minutes__sum,
                        CASE WHEN SUM(children_all_walk_minutes) > 0 then SUM(pop_children * children_all_walk_minutes) / sum(pop_children)
                        else 0 end as children_all_walk_minutes__sum from %({0})s'''
                    .format(DbEntityKey.PH_BLOCK_GROUP_OUTCOMES),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.PUBLIC_HEALTH],
                    result_db_entity_key=ResultKey.PH_AUTO_MINUTES,
                    source_db_entity_key=DbEntityKey.PH_BLOCK_GROUP_OUTCOMES,
                    name='Daily Auto Minutes - Per Capita',
                    attributes=[
                        'seniors_all_auto_minutes', 'adult_all_auto_minutes',
                        'teens_all_auto_minutes', 'children_all_auto_minutes'
                    ],
                    db_column_lookup=dict(
                        seniors_all_auto_minutes='seniors_all_auto_minutes',
                        adult_all_auto_minutes='adult_all_auto_minutes',
                        teens_all_auto_minutes='teens_all_auto_minutes',
                        children_all_auto_minutes='children_all_auto_minutes'),
                    labels=['Seniors', 'Adults', 'Teens', 'Children'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config: '''SELECT
                        CASE WHEN SUM(seniors_all_auto_minutes) > 0 then SUM(pop_senior * seniors_all_auto_minutes) / sum(pop_senior)
                        else 0 end as seniors_all_auto_minutes__sum,
                        CASE WHEN SUM(adult_all_auto_minutes) > 0 then SUM(pop_adult * adult_all_auto_minutes) / sum(pop_adult)
                        else 0 end as adult_all_auto_minutes__sum,
                        CASE WHEN SUM(teens_all_auto_minutes) > 0 then SUM(pop_teen * teens_all_auto_minutes) / sum(pop_teen)
                        else 0 end as teens_all_auto_minutes__sum,
                        CASE WHEN SUM(children_all_auto_minutes) > 0 then SUM(pop_children * children_all_auto_minutes) / sum(pop_children)
                        else 0 end as children_all_auto_minutes__sum from %({0})s'''
                    .format(DbEntityKey.PH_BLOCK_GROUP_OUTCOMES),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.PUBLIC_HEALTH],
                    result_db_entity_key=ResultKey.PH_REC_PA_MINUTES,
                    source_db_entity_key=DbEntityKey.PH_BLOCK_GROUP_OUTCOMES,
                    name='Daily Physical Activity Minutes - Per Capita',
                    attributes=[
                        'seniors_all_rec_pa_minutes',
                        'adult_all_rec_pa_minutes', 'teens_all_rec_pa_minutes',
                        'children_all_rec_pa_minutes'
                    ],
                    db_column_lookup=dict(
                        seniors_all_rec_pa_minutes='seniors_all_rec_pa_minutes',
                        adult_all_rec_pa_minutes='adult_all_rec_pa_minutes',
                        teens_all_rec_pa_minutes='teens_all_rec_pa_minutes',
                        children_all_rec_pa_minutes=
                        'children_all_rec_pa_minutes'),
                    labels=['Seniors', 'Adults', 'Teens', 'Children'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config: '''SELECT
                        CASE WHEN SUM(seniors_all_rec_pa_minutes) > 0 then SUM(pop_senior * seniors_all_rec_pa_minutes) / sum(pop_senior)
                        else 0 end as seniors_all_rec_pa_minutes__sum,
                        CASE WHEN SUM(adult_all_rec_pa_minutes) > 0 then SUM(pop_adult * adult_all_rec_pa_minutes) / sum(pop_adult)
                        else 0 end as adult_all_rec_pa_minutes__sum,
                        CASE WHEN SUM(teens_all_rec_pa_minutes) > 0 then SUM(pop_teen * teens_all_rec_pa_minutes) / sum(pop_teen)
                        else 0 end as teens_all_rec_pa_minutes__sum,
                        CASE WHEN SUM(children_all_rec_pa_minutes) > 0 then SUM(pop_children * children_all_rec_pa_minutes) / sum(pop_children)
                        else 0 end as children_all_rec_pa_minutes__sum from %({0})s'''
                    .format(DbEntityKey.PH_BLOCK_GROUP_OUTCOMES),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='summary_table',
                    library_keys=[ResultLibraryKey.PUBLIC_HEALTH],
                    result_db_entity_key=ResultKey.PH_OUTCOMES_TABLE,
                    source_db_entity_key=DbEntityKey.PH_OUTCOMES_SUMMARY,
                    name='Public Health Outcomes Summary',
                    attributes=['outcome', 'result'],
                    db_column_lookup=dict(outcome='outcome', result='result'),
                    labels=['outcome', 'result'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    '''SELECT outcome, result from %({0})s'''.format(
                        DbEntityKey.PH_OUTCOMES_SUMMARY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.AGRICULTURE_ANALYSIS],
                    result_db_entity_key=ResultKey.AGRICULTURE_ROI,
                    source_db_entity_key=DbEntityKey.BASE_AGRICULTURE_CANVAS,
                    name='Agriculture(RUCS): Cost/Gain Comparison',
                    attributes=['production_cost', 'market_value'],
                    db_column_lookup=dict(production_cost='production_cost',
                                          market_value='market_value'),
                    labels=['Total Cost', 'Total Value'],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='bar_graph',
                    library_keys=[ResultLibraryKey.AGRICULTURE_ANALYSIS],
                    result_db_entity_key=ResultKey.AGRICULTURE_ROI,
                    source_db_entity_key=DbEntityKey.FUTURE_AGRICULTURE_CANVAS,
                    name='Agriculture(RUCS): Cost/Gain Comparison',
                    attributes=['production_cost', 'market_value'],
                    db_column_lookup=dict(production_cost='production_cost',
                                          market_value='market_value'),
                    labels=['Total Cost', 'Total Value'],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='analytic_result',
                    library_keys=[ResultLibraryKey.AGRICULTURE_ANALYSIS],
                    result_db_entity_key=ResultKey.AGRICULTURE,
                    source_db_entity_key=DbEntityKey.BASE_AGRICULTURE_CANVAS,
                    name='Agriculture',
                    attributes=[
                        'crop_yield', 'water_consumption', 'labor_force',
                        'truck_trips', 'production_cost', 'market_value'
                    ],
                    db_column_lookup=dict(
                        crop_yield='crop_yield',
                        water_consumption='water_consumption',
                        labor_force='labor_force',
                        truck_trips='truck_trips',
                        production_cost='production_cost',
                        market_value='market_value'),
                    labels=[
                        'crop_yield', 'water_consumption', 'labor_force',
                        'truck_trips', 'production_cost', 'market_value'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='analytic_result',
                    library_keys=[ResultLibraryKey.AGRICULTURE_ANALYSIS],
                    result_db_entity_key=ResultKey.AGRICULTURE,
                    source_db_entity_key=DbEntityKey.FUTURE_AGRICULTURE_CANVAS,
                    name='Agriculture',
                    attributes=[
                        'crop_yield', 'water_consumption', 'labor_force',
                        'truck_trips', 'production_cost', 'market_value'
                    ],
                    db_column_lookup=dict(
                        crop_yield='crop_yield',
                        water_consumption='water_consumption',
                        labor_force='labor_force',
                        truck_trips='truck_trips',
                        production_cost='production_cost',
                        market_value='market_value'),
                    labels=[
                        'crop_yield', 'water_consumption', 'labor_force',
                        'truck_trips', 'production_cost', 'market_value'
                    ],
                    stackable=False,
                    is_stacked=False,
                    create_query=self.simple_aggregate,
                    sort_priority=ResultSort.FUTURE)
            ])
    def projects(self,
                 region=None,
                 region_keys=None,
                 project_keys=None,
                 class_scope=None):
        # All SCAG jurisdictions
        imperial = [
            'Brawley', 'Calexico', 'Calipatria', 'El Centro', 'Holtville',
            'Imperial', 'Unincorporated: Imperial', 'Westmorland'
        ]

        los_angeles = [
            'Agoura Hills', 'Alhambra', 'Arcadia', 'Artesia', 'Avalon',
            'Azusa', 'Baldwin Park', 'Bell', 'Bell Gardens', 'Bellflower',
            'Beverly Hills', 'Bradbury', 'Burbank', 'Calabasas', 'Carson',
            'Cerritos', 'Claremont', 'Commerce', 'Compton', 'Covina', 'Cudahy',
            'Culver City', 'Diamond Bar', 'Downey', 'Duarte', 'El Monte',
            'El Segundo', 'Gardena', 'Glendale', 'Glendora',
            'Hawaiian Gardens', 'Hawthorne', 'Hermosa Beach', 'Hidden Hills',
            'Huntington Park', 'Industry', 'Inglewood', 'Irwindale',
            'La Canada Flintridge', 'La Habra Heights', 'La Mirada',
            'La Puente', 'La Verne', 'Lakewood', 'Lancaster', 'Lawndale',
            'Lomita', 'Long Beach', 'Los Angeles', 'Lynwood', 'Malibu',
            'Manhattan Beach', 'Maywood', 'Monrovia', 'Montebello',
            'Monterey Park', 'Norwalk', 'Palmdale', 'Palos Verdes Estates',
            'Paramount', 'Pasadena', 'Pico Rivera', 'Pomona',
            'Rancho Palos Verdes', 'Redondo Beach', 'Rolling Hills',
            'Rolling Hills Estates', 'Rosemead', 'San Dimas', 'San Fernando',
            'San Gabriel', 'San Marino', 'Santa Clarita', 'Santa Fe Springs',
            'Santa Monica', 'Sierra Madre', 'Signal Hill', 'South El Monte',
            'South Gate', 'South Pasadena', 'Temple City', 'Torrance',
            'Unincorporated: Los Angeles', 'Vernon', 'Walnut', 'West Covina',
            'West Hollywood', 'Westlake Village', 'Whittier'
        ]

        orange = [
            'Aliso Viejo', 'Anaheim', 'Brea', 'Buena Park', 'Costa Mesa',
            'Cypress', 'Dana Point', 'Fountain Valley', 'Fullerton',
            'Garden Grove', 'Huntington Beach', 'Irvine', 'La Habra',
            'La Palma', 'Laguna Beach', 'Laguna Hills', 'Laguna Niguel',
            'Laguna Woods', 'Lake Forest', 'Los Alamitos', 'Mission Viejo',
            'Newport Beach', 'Orange', 'Placentia', 'Rancho Santa Margarita',
            'San Clemente', 'San Juan Capistrano', 'Santa Ana', 'Seal Beach',
            'Stanton', 'Tustin', 'Unincorporated: Orange', 'Villa Park',
            'Westminster', 'Yorba Linda'
        ]

        riverside = [
            'Banning', 'Beaumont', 'Blythe', 'Calimesa', 'Canyon Lake',
            'Cathedral City', 'Coachella', 'Corona', 'Desert Hot Springs',
            'Eastvale', 'Hemet', 'Indian Wells', 'Indio', 'Jurupa Valley',
            'La Quinta', 'Lake Elsinore', 'Menifee', 'Moreno Valley',
            'Murrieta', 'Norco', 'Palm Desert', 'Palm Springs', 'Perris',
            'Rancho Mirage', 'Riverside', 'San Jacinto', 'Temecula',
            'Unincorporated: Riverside', 'Wildomar'
        ]

        san_bernardino = [
            'Adelanto', 'Apple Valley', 'Barstow', 'Big Bear Lake', 'Chino',
            'Chino Hills', 'Colton', 'Fontana', 'Grand Terrace', 'Hesperia',
            'Highland', 'Loma Linda', 'Montclair', 'Needles', 'Ontario',
            'Rancho Cucamonga', 'Redlands', 'Rialto', 'San Bernardino',
            'Twentynine Palms', 'Unincorporated: San Bernardino', 'Upland',
            'Victorville', 'Yucaipa', 'Yucca Valley'
        ]

        ventura = [
            'Camarillo', 'Fillmore', 'Moorpark', 'Ojai', 'Oxnard',
            'Port Hueneme', 'San Buenaventura', 'Santa Paula', 'Simi Valley',
            'Thousand Oaks', 'Unincorporated: Ventura'
        ]

        #jurisdictions = imperial + los_angeles + orange + riverside + san_bernardino + ventura
        #jurisdictions = ['City_%02d' % x for x in xrange(32)]
        jurisdictions = imperial

        # Create only a small subset of jurisdictions for the dev environments
        if settings.USE_SAMPLE_DATA_SETS:
            jurisdictions = ["Anaheim", 'Irvine']

        configurations = map(
            lambda jurisdiction_name: {
                'key':
                project_key(jurisdiction_name),
                'import_key':
                jurisdiction_name.lower().replace(' ', '_').replace(':', ''),
                'name':
                jurisdiction_name,
                'description':
                "City of %s" % jurisdiction_name,
                'base_year':
                2014,
                'region_key':
                'scag',
                'media': [
                    MediumFixture(key=ConfigEntityMediumKey.Fab.ricate(
                        jurisdiction_name.lower().replace(' ', '_') + '_logo'),
                                  name='%s Logo' % jurisdiction_name,
                                  url='/static/client/{0}/logos/{1}_logo.png'.
                                  format(
                                      settings.CLIENT,
                                      jurisdiction_name.lower().replace(
                                          ' ', '_')))
                ]
            }, jurisdictions)

        return FixtureList(configurations).matching_keys(
            region_keys=region_keys,
            key=project_keys).matching_scope(class_scope=class_scope)
Ejemplo n.º 25
0
    def default_db_entities(self):
        """
            Region specific db_entity_setups
        :param default_dict:
        :return:
        """

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

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

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

        return self.parent_fixture.layers() + FixtureList([
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=DbEntityKey.CENSUS_TRACTS,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.POLYGON,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        line_color='#990000',
                                                        line_opacity=0.8,
                                                        line_width=3))
                                            ])
                                   ])),
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=DbEntityKey.CENSUS_BLOCKGROUPS,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.POLYGON,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        line_color='#CD5555',
                                                        line_opacity=0.8,
                                                        line_width=3))
                                            ])
                                   ])),
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=DbEntityKey.CENSUS_BLOCK,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.POLYGON,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        line_color='#E60000',
                                                        line_opacity=0.8,
                                                        line_width=3))
                                            ])
                                   ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.BASE_CANVAS,
                column_alias_lookup=dict(built_form__id='built_form_id'),
                layer_style=built_form_based_layer_style(),
                sort_priority=LayerSort.BASE),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.BASE_AGRICULTURE_CANVAS,
                column_alias_lookup=dict(built_form__id='built_form_id'),
                layer_style=built_form_based_layer_style(),
                sort_priority=LayerSort.BASE),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.ENERGY,
                layer_style=dict(
                    geometry_type=GeometryTypeKey.POLYGON,
                    style_attributes=[
                        dict(attribute='annual_million_btus_per_unit',
                             style_type=StyleTypeKey.QUANTITATIVE,
                             style_value_contexts=[
                                 StyleValueContext(
                                     value=0,
                                     symbol='=',
                                     style=Style(polygon_fill='#909090')),
                                 StyleValueContext(
                                     value=0,
                                     symbol='>',
                                     style=Style(polygon_fill='#97D704')),
                                 StyleValueContext(
                                     value=5,
                                     symbol='>',
                                     style=Style(polygon_fill='#B2D103')),
                                 StyleValueContext(
                                     value=10,
                                     symbol='>',
                                     style=Style(polygon_fill='#CBCA03')),
                                 StyleValueContext(
                                     value=15,
                                     symbol='>',
                                     style=Style(polygon_fill='#C5A703')),
                                 StyleValueContext(
                                     value=20,
                                     symbol='>',
                                     style=Style(polygon_fill='#BF8603')),
                                 StyleValueContext(
                                     value=30,
                                     symbol='>',
                                     style=Style(polygon_fill='#B96602')),
                                 StyleValueContext(
                                     value=40,
                                     symbol='>',
                                     style=Style(polygon_fill='#B34802')),
                                 StyleValueContext(
                                     value=55,
                                     symbol='>',
                                     style=Style(polygon_fill='#AD2C02')),
                                 StyleValueContext(
                                     value=80,
                                     symbol='>',
                                     style=Style(polygon_fill='#A71102')),
                                 StyleValueContext(
                                     value=120,
                                     symbol='>',
                                     style=Style(polygon_fill='#A1020B')),
                             ])
                    ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.WATER,
                layer_style=dict(
                    geometry_type=GeometryTypeKey.POLYGON,
                    style_attributes=[
                        dict(attribute='annual_gallons_per_unit',
                             style_type=StyleTypeKey.QUANTITATIVE,
                             style_value_contexts=[
                                 StyleValueContext(
                                     value=0,
                                     symbol='=',
                                     style=Style(polygon_fill='#909090')),
                                 StyleValueContext(
                                     value=0,
                                     symbol='>',
                                     style=Style(polygon_fill='#B3D8FF')),
                                 StyleValueContext(
                                     value=40,
                                     symbol='>',
                                     style=Style(polygon_fill='#9FC6F0')),
                                 StyleValueContext(
                                     value=60,
                                     symbol='>',
                                     style=Style(polygon_fill='#8BB5E1')),
                                 StyleValueContext(
                                     value=80,
                                     symbol='>',
                                     style=Style(polygon_fill='#77A4D2')),
                                 StyleValueContext(
                                     value=120,
                                     symbol='>',
                                     style=Style(polygon_fill='#6392C3')),
                                 StyleValueContext(
                                     value=160,
                                     symbol='>',
                                     style=Style(polygon_fill='#6392C3')),
                                 StyleValueContext(
                                     value=200,
                                     symbol='>',
                                     style=Style(polygon_fill='#5081B5')),
                                 StyleValueContext(
                                     value=250,
                                     symbol='>',
                                     style=Style(polygon_fill='#3C70A6')),
                                 StyleValueContext(
                                     value=300,
                                     symbol='>',
                                     style=Style(polygon_fill='#285E97')),
                                 StyleValueContext(
                                     value=350,
                                     symbol='>',
                                     style=Style(polygon_fill='#144D88')),
                                 StyleValueContext(
                                     value=400,
                                     symbol='>',
                                     style=Style(polygon_fill='#013C7A')),
                             ])
                    ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.VMT,
                layer_style=dict(
                    geometry_type=GeometryTypeKey.POLYGON,
                    style_attributes=[
                        dict(attribute='vmt_daily_per_hh',
                             style_type=StyleTypeKey.QUANTITATIVE,
                             style_value_contexts=[
                                 StyleValueContext(value=0,
                                                   symbol='=',
                                                   style=Style(
                                                       polygon_fill='#E8E8E8',
                                                       line_color='#909090',
                                                       line_width=.3)),
                                 StyleValueContext(value=0,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#004d1a',
                                                       line_color='#909090',
                                                       line_width=.3)),
                                 StyleValueContext(value=20,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#009933',
                                                       line_color='#909090',
                                                       line_width=.3)),
                                 StyleValueContext(value=30,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#00CC33',
                                                       line_color='#909090',
                                                       line_width=.3)),
                                 StyleValueContext(value=40,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#FFFF00',
                                                       line_color='#909090',
                                                       line_width=.3)),
                                 StyleValueContext(value=60,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#FF9900',
                                                       line_color='#909090',
                                                       line_width=.3)),
                                 StyleValueContext(value=80,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#cc1500',
                                                       line_color='#909090',
                                                       line_width=.3))
                             ])
                    ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.INCREMENT,
                column_alias_lookup=dict(built_form__id='built_form_id'),
                layer_style=built_form_based_layer_style(),
                sort_priority=LayerSort.FUTURE + 1),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.END_STATE,
                visible=True,
                column_alias_lookup=dict(built_form__id='built_form_id'),
                layer_style=built_form_based_layer_style(),
                sort_priority=LayerSort.FUTURE + 2),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.FUTURE_AGRICULTURE_CANVAS,
                visible=True,
                column_alias_lookup=dict(built_form__id='built_form_id'),
                layer_style=built_form_based_layer_style(),
                sort_priority=LayerSort.FUTURE + 3),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=SacogDbEntityKey.EXISTING_LAND_USE_PARCELS,
                visible=True,
                column_alias_lookup=dict(
                    land_use_definition__id='land_use_definition_id'),
                built_form_set_key='sacog_land_use',
                layer_style=primary_base_layer_style(SacogLandUseDefinition)),
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=SacogDbEntityKey.STREAM,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.POLYGON,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        polygon_fill='#00008B',
                                                        polygon_opacity=0.75))
                                            ])
                                   ])),
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=SacogDbEntityKey.VERNAL_POOL,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.POLYGON,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        polygon_fill='#008080',
                                                        polygon_opacity=0.75))
                                            ])
                                   ])),
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=SacogDbEntityKey.WETLAND,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.POLYGON,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        polygon_fill='#00688B',
                                                        polygon_opacity=0.75))
                                            ])
                                   ])),
            LayerConfiguration(library_keys=[LayerLibraryKey.APPLICATION],
                               db_entity_key=SacogDbEntityKey.LIGHT_RAIL,
                               layer_style=dict(
                                   geometry_type=GeometryTypeKey.LINESTRING,
                                   style_attributes=[
                                       dict(style_type=StyleTypeKey.SINGLE,
                                            style_value_contexts=[
                                                StyleValueContext(
                                                    value=None,
                                                    symbol=None,
                                                    style=Style(
                                                        line_color='#660066',
                                                        line_width=6))
                                            ])
                                   ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=SacogDbEntityKey.LIGHT_RAIL_STOPS,
                layer_style=dict(
                    geometry_type=GeometryTypeKey.POINT,
                    style_attributes=[
                        dict(style_type=StyleTypeKey.SINGLE,
                             style_value_contexts=[
                                 StyleValueContext(
                                     value=None,
                                     symbol=None,
                                     style=Style(marker_fill='#000080',
                                                 marker_width=10,
                                                 marker_line_color='white',
                                                 marker_line_width=1))
                             ])
                    ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=SacogDbEntityKey.LIGHT_RAIL_STOPS_ONE_MILE,
                layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                                 style_attributes=[
                                     dict(style_type=StyleTypeKey.SINGLE,
                                          style_value_contexts=[
                                              StyleValueContext(
                                                  value=None,
                                                  symbol=None,
                                                  style=Style(
                                                      line_color='#CC00FF',
                                                      line_width=2))
                                          ])
                                 ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=SacogDbEntityKey.LIGHT_RAIL_STOPS_HALF_MILE,
                layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                                 style_attributes=[
                                     dict(style_type=StyleTypeKey.SINGLE,
                                          style_value_contexts=[
                                              StyleValueContext(
                                                  value=None,
                                                  symbol=None,
                                                  style=Style(
                                                      line_color='#CC00FF',
                                                      line_width=2))
                                          ])
                                 ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=SacogDbEntityKey.LIGHT_RAIL_STOPS_QUARTER_MILE,
                layer_style=dict(geometry_type=GeometryTypeKey.POLYGON,
                                 style_attributes=[
                                     dict(style_type=StyleTypeKey.SINGLE,
                                          style_value_contexts=[
                                              StyleValueContext(
                                                  value=None,
                                                  symbol=None,
                                                  style=Style(
                                                      line_color='#CC00FF',
                                                      line_width=2))
                                          ])
                                 ])),
            LayerConfiguration(
                library_keys=[LayerLibraryKey.APPLICATION],
                db_entity_key=DbEntityKey.PH_BLOCK_GROUP_OUTCOMES,
                layer_style=dict(
                    geometry_type=GeometryTypeKey.POLYGON,
                    style_attributes=[
                        dict(attribute='adult_all_walk_minutes',
                             style_type=StyleTypeKey.QUANTITATIVE,
                             style_value_contexts=[
                                 StyleValueContext(value=0,
                                                   symbol='=',
                                                   style=Style(
                                                       polygon_fill='#E8E8E8',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=0,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#C3523C',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=2,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#B1782D',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=4,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#9F9F1E',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=6,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#8DC60F',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=8,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#7BED00',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=15,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#5FBC1E',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=20,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#438C3D',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=25,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#275C5B',
                                                       polygon_opacity=0.3)),
                                 StyleValueContext(value=30,
                                                   symbol='>',
                                                   style=Style(
                                                       polygon_fill='#0B2C7A',
                                                       polygon_opacity=0.3)),
                             ])
                    ]))
        ])
Ejemplo n.º 27
0
 def layer_libraries(self, class_scope=None):
     return self.parent_fixture.layer_libraries(
         FixtureList(self.layers()).matching_scope(
             class_scope=self.config_entity
             and self.config_entity.__class__))
Ejemplo n.º 28
0
    def default_db_entities(self):
        """
            Scenarios define DbEntities specific to the Scenario. Creates a list a dictionary of configuration
            functionality. These are filtered based on whether the given scenario matches the scope in the
            configuration
        :return:
        """
        scenario = self.config_entity
        project = self.config_entity.parent_config_entity
        # The Behavior keyspace
        behavior_key = BehaviorKey.Fab.ricate
        # Used to load Behaviors defined elsewhere
        get_behavior = lambda key: Behavior.objects.get(key=behavior_key(key))

        return super(SacogScenarioFixture, self).default_db_entities() + map(
            lambda db_entity_dict: update_or_create_db_entity(
                scenario, db_entity_dict['value']),
            FixtureList([
                dict(
                    class_scope=FutureScenario,
                    value=DbEntity(
                        key=DbEntityKey.INCREMENT,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=CoreIncrementFeature,
                            import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                            import_ids_only=True,
                            related_fields=dict(built_form=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'built_form.built_form.BuiltForm')))),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('scenario_increment'),
                            intersection=AttributeIntersection(
                                from_attribute='id', to_attribute='id')),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.FUTURE_SCENARIO)
                        ]),
                ),
                dict(
                    class_scope=FutureScenario,
                    value=DbEntity(
                        key=DbEntityKey.END_STATE,
                        feature_class_configuration=FeatureClassConfiguration(
                            abstract_class=CanvasFeature,
                            import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                            related_fields=dict(built_form=dict(
                                single=True,
                                related_class_name=uf_model(
                                    'built_form.built_form.BuiltForm')))),
                        feature_behavior=FeatureBehavior(
                            behavior=get_behavior('scenario_end_state'),
                            intersection=AttributeIntersection(
                                from_attribute='id', to_attribute='id')),
                        _categories=[
                            Category(
                                key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                value=DbEntityCategoryKey.FUTURE_SCENARIO)
                        ]),
                ),
                dict(class_scope=FutureScenario,
                     value=DbEntity(
                         key=DbEntityKey.FUTURE_AGRICULTURE_CANVAS,
                         name='Scenario Agriculture End State',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=AgricultureFeature,
                             import_from_db_entity_key=DbEntityKey.
                             BASE_AGRICULTURE_CANVAS,
                             import_ids_only=False,
                             related_fields=dict(built_form=dict(
                                 single=True,
                                 related_class_name=uf_model(
                                     'built_form.built_form.BuiltForm'),
                                 related_class_join_field_name='key',
                                 source_class_join_field_name='built_form_key')
                                                 )),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('agriculture_scenario'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.FUTURE_SCENARIO)
                         ])),
                dict(class_scope=FutureScenario,
                     value=DbEntity(
                         key=DbEntityKey.FISCAL,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=FiscalFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.VMT_VARIABLES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=VmtVariablesFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.VMT,
                         name='Vehicle Miles Traveled Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=VmtFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.ENERGY,
                         name='Energy Demand Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=EnergyFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.WATER,
                         name='Water Demand Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=WaterFeature,
                             import_from_db_entity_key=DbEntityKey.BASE_CANVAS,
                             empty_table=True),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=AttributeIntersection(
                                 from_attribute='id', to_attribute='id')),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_VARIABLES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhVariablesFeature,
                             import_from_db_entity_key=DbEntityKey.GRID_150M,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_GRID_OUTCOMES,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhGridOutcomesFeature,
                             import_from_db_entity_key=DbEntityKey.GRID_150M,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.REFERENCE)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_BLOCK_GROUP_OUTCOMES,
                         name='Public Health Output',
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhBlockGroupOutcomesFeature,
                             import_from_db_entity_key=DbEntityKey.GRID_150M,
                             import_ids_only=True,
                             filter_query=dict(),
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ])),
                dict(class_scope=Scenario,
                     value=DbEntity(
                         key=DbEntityKey.PH_OUTCOMES_SUMMARY,
                         feature_class_configuration=FeatureClassConfiguration(
                             abstract_class=PhOutcomesSummary,
                             no_table_associations=True,
                             empty_table=True,
                         ),
                         feature_behavior=FeatureBehavior(
                             behavior=get_behavior('internal_analysis'),
                             intersection=GeographicIntersection.
                             polygon_to_polygon),
                         _categories=[
                             Category(
                                 key=DbEntityCategoryKey.KEY_CLASSIFICATION,
                                 value=DbEntityCategoryKey.ANALYSIS_RESULTS)
                         ]))
            ]).matching_scope(class_scope=self.config_entity
                              and self.config_entity.__class__))
Ejemplo n.º 29
0
    def results(self):
        """
            Used to update or create Results per ConfigEntity instance
            Returns the result library(ies) scoped for the class of self.config_entity.
            The Result will belong to the ResultLibrary specified by result_library_key
        :return:
        """
        return FixtureList(
            # Basic Core result query that summarizes increments
            self.parent_fixture.results() + [

                # Line Chart Config
                ResultConfiguration(
                    result_type='line_chart',
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_db_entity_key=ResultKey.POPULATION_BY_YEAR,
                    source_db_entity_key=ScagDmDbEntityKey.CITY_BOUNDARY,
                    name='Population By Year',
                    attributes=['pop16', 'pop20', 'pop30', 'pop35', 'pop45'],
                    db_column_lookup=dict(pop16='pop16',
                                          pop20='pop20',
                                          pop30='pop30',
                                          pop35='pop35',
                                          pop45='pop45'),
                    labels=['pop16', 'pop20', 'pop30', 'pop35', 'pop45'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(pop16) as pop16__sum, SUM(pop20) as pop20__sum, SUM(pop30) as pop30__sum, SUM(pop35) as pop35__sum, SUM(pop45) as pop45__sum FROM %({0})s'
                    .format(ScagDmDbEntityKey.CITY_BOUNDARY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='line_chart',
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_db_entity_key=ResultKey.HOUSEHOLDS_BY_YEAR,
                    source_db_entity_key=ScagDmDbEntityKey.CITY_BOUNDARY,
                    name='Households By Year',
                    attributes=['hh16', 'hh20', 'hh30', 'hh35', 'hh45'],
                    db_column_lookup=dict(hh16='hh16',
                                          hh20='hh20',
                                          hh30='hh30',
                                          hh35='hh35',
                                          hh45='hh45'),
                    labels=['hh16', 'hh20', 'hh30', 'hh35', 'hh45'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(hh16) as hh16__sum, SUM(hh20) as hh20__sum, SUM(hh30) as hh30__sum, SUM(hh35) as hh35__sum, SUM(hh45) as hh45__sum FROM %({0})s'
                    .format(ScagDmDbEntityKey.CITY_BOUNDARY),
                    sort_priority=ResultSort.BASE),
                ResultConfiguration(
                    result_type='line_chart',
                    library_keys=[ResultLibraryKey.APPLICATION],
                    result_db_entity_key=ResultKey.EMPLOYMENT_BY_YEAR,
                    source_db_entity_key=ScagDmDbEntityKey.CITY_BOUNDARY,
                    name='Employment By Year',
                    attributes=['emp16', 'emp20', 'emp30', 'emp35', 'emp45'],
                    db_column_lookup=dict(emp16='emp16',
                                          emp20='emp20',
                                          emp30='emp30',
                                          emp35='emp35',
                                          emp45='emp45'),
                    labels=['emp16', 'emp20', 'emp30', 'emp35', 'emp45'],
                    stackable=False,
                    is_stacked=False,
                    create_query=lambda result_config:
                    'SELECT SUM(emp16) as emp16__sum, SUM(emp20) as emp20__sum, SUM(emp30) as emp30__sum, SUM(emp35) as emp35__sum, SUM(emp45) as emp45__sum FROM %({0})s'
                    .format(ScagDmDbEntityKey.CITY_BOUNDARY),
                    sort_priority=ResultSort.BASE)
            ])
Ejemplo n.º 30
0
    def behaviors(self, **kwargs):
        key = BehaviorKey.Fab.ricate
        # This doesn't fetch from the database, since the Behavior being sought might not exist quite yet
        polygon = GeographicKey.POLYGON

        # Create a special DbEntity used only by Behavior.feature_template_behavior instances
        dummy_user = get_user_model().objects.get(username=UserGroupKey.SUPERADMIN)

        DbEntity.objects.update_or_create(key='template_feature_behavior', defaults=dict(
            creator=dummy_user,
            updater=dummy_user))

        return FixtureList([
            Behavior(
                key=key('environmental_constraint'),
                parents=[],
                # Environmental constraints always intersect primary features polygon to polygon
                intersection=GeographicIntersection.polygon_to_polygon
            ),
            # A behavior attributed to Features representing UrbanFootprint base data
            Behavior(
                key=key('reference'),
                parents=[]
            ),
            Behavior(
                key=key('reference_layers_editable_attribute'),
                parents=[]
            ),
            Behavior(
                key=key('tool'),
                parents=[]
            ),
            # A behavior attributed to a Tool that produces a result from one or more inputs
            Behavior(
                key=key('analysis_tool'),
                parents=['tool']
            ),
            # A behavior attributed to a Tool that performs updates
            Behavior(
                key=key('update_tool'),
                parents=['tool']
            ),
            # A behavior attributed to a Tool that edits features or similar
            Behavior(
                key=key('editor_tool'),
                parents=['tool']
            ),
            # A behavior attributed to Features representing UrbanFootprint base data
            Behavior(
                key=key('editable_feature'),
                parents=[]
            ),
            Behavior(
                key=key('base_feature'),
                parents=[]
            ),
            # The behavior of the Agriculture Builder tool
            Behavior(
                    key=key('agriculture_editor_tool'),
                    parents=['editor_tool']
            ),
            # The behavior of the Scenario Builder tool
            Behavior(
                    key=key('scenario_editor_tool'),
                    parents=['editor_tool']
            ),
            Behavior(
                key=key('sed_editor_tool'),
                parents=['editor_tool']
            ),
            # agriculture_editor_tool is a parent so that this DbEntity with this behavior will run the
            # agriculture module when its features are updated
            Behavior(
                key=key('base_agriculture'),
                parents=['agriculture_editor_tool']
            ),
            # agriculture_editor_tool is a parent so that this DbEntity with this behavior will run the
            # agriculture module when its features are updated
            Behavior(
                key=key('scenario_end_state'),
                parents=['scenario_editor_tool']
            ),
            Behavior(
                key=key('scenario_increment'),
                parents=[]
            ),
            # agriculture_editor_tool is a parent so that this DbEntity with this behavior will run the
            # agriculture module when its features are updated
            Behavior(
                key=key('agriculture_scenario'),
                parents=['agriculture_editor_tool']
            ),
            Behavior(
                key=key('developable'),
                parents=[]
            ),
            Behavior(
                key=key('internal_analysis'),
                parents=[]
            ),
            Behavior(
                # Background imagery
                key=key('remote_imagery'),
                parents=[]
            ),
            Behavior(
                # results
                key=key('result'),
                parents=[]
            ),
            Behavior(
                # results
                key=key('master'),
                abstract=True,
                parents=[]
            ),
            Behavior(
                # results
                key=key('draft'),
                abstract=True,
                parents=[]
            ),
            Behavior(
                # results
                key=key('default_config_entity'),
                parents=[]
            ),
            Behavior(
                # results
                key=key('base_scenario'),
                parents=['default_config_entity']
            ),
            Behavior(
                # results
                key=key('future_scenario'),
                parents=['default_config_entity']
            ),
            Behavior(
                # results
                key=key('base_master_scenario'),
                parents=['base_scenario', 'master']
            ),
            Behavior(
                # results
                key=key('base_draft_scenario'),
                parents=['base_scenario', 'draft']
            ),
            Behavior(
                # results
                key=key('future_master_scenario'),
                parents=['future_scenario', 'master']
            ),
            Behavior(
                # results
                key=key('future_draft_scenario'),
                parents=['future_scenario', 'draft']
            )
        ])