Exemple #1
0
def validate_filter_item(key, value, argument_name):
    formatted_value_name = '{0}[{1}]'.format(argument_name, key)
    assert_string(key, 'Filter ID \'%s\'' % key)
    assert_type(value, FilterDefinition, argument_name=formatted_value_name)
    key_argument_name = 'key %s' % key
    value_argument_name = 'id %s' % value.id
    assert_equals(key, value['id'], key_argument_name, value_argument_name)
Exemple #2
0
def validate_date_range_item(key, value, argument_name):
    formatted_value_name = '{0}[{1}]'.format(argument_name, key)
    assert_string(key, 'Date Range ID \'%s\'' % key)
    assert_type(value, DateRangeSpecification, argument_name=formatted_value_name)
    key_argument_name = 'key %s' % key
    value_argument_name = 'id %s' % value.id
    assert_equals(key, value['id'], key_argument_name, value_argument_name)
Exemple #3
0
def validate_size_item(key, value, argument_name):
    formatted_value_name = '{0}[{1}]'.format(argument_name, key)
    assert_string(key, 'Size ID \'%s\'' % key)
    assert_type(value, LayoutSize, argument_name=formatted_value_name)
    key_argument_name = 'key %s' % key
    value_argument_name = 'id %s' % value.id
    assert_equals(key, value['id'], key_argument_name, value_argument_name)
Exemple #4
0
def validate_settings_item(key, value, argument_name):
    formatted_value_name = '{0}[{1}]'.format(argument_name, key)
    assert_string(key, 'Settings ID \'%s\'' % key)
    assert_type(value, VisualizationSettings, argument_name=formatted_value_name)
    key_argument_name = 'key %s' % key
    value_argument_name = 'id %s' % value.id
    assert_equals(key, value['id'], key_argument_name, value_argument_name)
Exemple #5
0
class AxesSettings(PythonModel):
    @classmethod
    def registry(cls):
        return AxisProperty

    @property
    @AxisProperty.getter(
        'xAxis',
        value_validate_function=lambda value: assert_type(
            value, desired_type=XAxisSettings, argument_name='x_axis_settings'
        ),
        default_value=lambda: XAxisSettings(),
        nullable=False,
    )
    def x_axis_settings(self):
        return self.get('xAxis')

    @x_axis_settings.setter
    @AxisProperty.setter(
        value_parser_function=lambda value: XAxisSettings(value))
    def x_axis_settings(self, value):
        self['xAxis'] = value

    @property
    @AxisProperty.getter(
        'y1Axis',
        value_validate_function=lambda value: assert_type(
            value,
            desired_type=YAxisSettings,
            argument_name='y1_axis_settings'),
        default_value=lambda: YAxisSettings(),
        nullable=False,
    )
    def y1_axis_settings(self):
        return self.get('y1Axis')

    @y1_axis_settings.setter
    @AxisProperty.setter(
        value_parser_function=lambda value: YAxisSettings(value))
    def y1_axis_settings(self, value):
        self['y1Axis'] = value

    @property
    @AxisProperty.getter(
        'y2Axis',
        value_validate_function=lambda value: assert_type(
            value,
            desired_type=YAxisSettings,
            argument_name='y2_axis_settings'),
        default_value=lambda: YAxisSettings(),
        nullable=False,
    )
    def y2_axis_settings(self):
        return self.get('y2Axis')

    @y2_axis_settings.setter
    @AxisProperty.setter(
        value_parser_function=lambda value: YAxisSettings(value))
    def y2_axis_settings(self, value):
        self['y2Axis'] = value
Exemple #6
0
def view_type_settings_validator(key, value, argument_name=None):
    key_argument_name = ('Key - {0}[{1}]'.format(argument_name, key)
                         if argument_name else 'Key \'{0}\''.format(key))

    value_argument_name = ('{0}[{1}]'.format(argument_name, key)
                           if argument_name else
                           'Value for Key \'{0}\''.format(key))

    assert_in(key, VISUALIZATION_TYPE_VALUES, key_argument_name)
    assert_type(value, SettingsGroup, value_argument_name)
Exemple #7
0
    def add_or_update_series(self, series_object):
        assert_type(series_object, SeriesSettingsObject)
        _id = series_object.id
        if _id not in self.series_order:
            updated_value = self.series_order
            updated_value.append(_id)
            self._series_order = updated_value

        updated_objects = self.series_objects
        updated_objects[_id] = series_object
        self._series_objects = updated_objects
Exemple #8
0
class VisualizationSettings(PythonModel):
    @classmethod
    def registry(cls):
        return VisualizationSettingsProperty

    @property
    @VisualizationSettingsProperty.getter(
        nullable=False, value_validate_function=lambda value: assert_string(value, 'id')
    )
    def id(self):
        return self.get('id')

    @id.setter
    @VisualizationSettingsProperty.setter()
    def id(self, value):
        self['id'] = value

    @property
    @VisualizationSettingsProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_type(
            value, TitleSettings, argument_name='title_settings'
        ),
    )
    def title_settings(self):
        return self.get('titleSettings')

    @title_settings.setter
    @VisualizationSettingsProperty.setter(
        value_parser_function=lambda values: TitleSettings(values)
    )
    def title_settings(self, value):
        self['titleSettings'] = value

    @property
    @VisualizationSettingsProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'view_type_settings', view_type_settings_validator
        ),
    )
    def view_type_settings(self):
        return self.get('viewTypeSettings')

    @view_type_settings.setter
    @VisualizationSettingsProperty.setter(
        value_parser_function=parse_view_type_settings
    )
    def view_type_settings(self, value):
        self['viewTypeSettings'] = value
Exemple #9
0
class LayoutItem(PythonModel):
    @classmethod
    def registry(cls):
        return LayoutItemProperty

    # TODO(vedant) - Come up with a proper structure for frontEndSelections
    # and/or filterModalSelections. Get rid of one of them since they have a
    # very similar structure.

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        default_value=lambda: [],
        value_validate_function=lambda value: assert_non_string_iterable(
            value, 'custom_fields', validate_custom_field),
    )
    def custom_fields(self):
        return self.get('customFields')

    @custom_fields.setter
    @LayoutItemProperty.setter(
        value_parser_function=lambda custom_field_objects: [
            CustomField(custom_field_object)
            for custom_field_object in custom_field_objects
        ])
    def custom_fields(self, value):
        self['customFields'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'filter_modal_selections'),
    )
    def filter_modal_selections(self):
        return self.get('filterModalSelections')

    @filter_modal_selections.setter
    @LayoutItemProperty.setter()
    def filter_modal_selections(self, value):
        self['filterModalSelections'] = value

    @property
    @LayoutItemProperty.getter(
        serialized_property_name='frontendSelectionsFilter',
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'front_end_selections_filter'),
    )
    def front_end_selections_filter(self):
        return self.get('frontendSelectionsFilter')

    @front_end_selections_filter.setter
    @LayoutItemProperty.setter()
    def front_end_selections_filter(self, value):
        self['frontendSelectionsFilter'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_string(value, 'id'))
    def id(self):
        return self.get('id')

    @id.setter
    @LayoutItemProperty.setter()
    def id(self, value):
        self['id'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_string(value, 'query_id'),
    )
    def query_id(self):
        return self.get('queryId')

    @query_id.setter
    @LayoutItemProperty.setter()
    def query_id(self, value):
        self['queryId'] = value

    @property
    @LayoutItemProperty.getter(
        value_validate_function=lambda value: assert_string(value, 'name'))
    def name(self):
        return self.get('name')

    @name.setter
    @LayoutItemProperty.setter()
    def name(self, value):
        self['name'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        default_value=DEFAULT_IS_ADVANCED_QUERY_ITEM,
        value_validate_function=lambda value: assert_boolean(
            value, 'is_advanced_query_item'),
    )
    def is_advanced_query_item(self):
        return self.get('isAdvancedQueryItem')

    @is_advanced_query_item.setter
    @LayoutItemProperty.setter()
    def is_advanced_query_item(self, value):
        self['isAdvancedQueryItem'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        default_value=DEFAULT_IS_LOCKED,
        value_validate_function=lambda value: assert_boolean(
            value, 'is_locked'),
    )
    def is_locked(self):
        return self.get('isLocked')

    @is_locked.setter
    @LayoutItemProperty.setter()
    def is_locked(self, value):
        self['isLocked'] = value

    @property
    @LayoutItemProperty.getter(value_validate_function=lambda value:
                               assert_string(value, 'setting_id'))
    def setting_id(self):
        return self.get('settingId')

    @setting_id.setter
    @LayoutItemProperty.setter()
    def setting_id(self, value):
        self['settingId'] = value

    @property
    @LayoutItemProperty.getter(
        serialized_property_name='type',
        nullable=False,
        value_validate_function=lambda value: assert_type(
            value, VisualizationType, argument_name='item_type'),
        value_formatter_function=lambda value: value.name,
    )
    def item_type(self):
        return self.get('type')

    @item_type.setter
    @LayoutItemProperty.setter(
        value_parser_function=deserialize_visualization_type)
    def item_type(self, value):
        self['type'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_integer(
            value, 'upper_x', lower_bound=UPPER_X_LOWER_BOUND),
    )
    def upper_x(self):
        return self.get('upperX')

    @upper_x.setter
    @LayoutItemProperty.setter()
    def upper_x(self, value):
        self['upperX'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_integer(
            value, 'upper_x', lower_bound=UPPER_Y_LOWER_BOUND),
    )
    def upper_y(self):
        return self.get('upperY')

    @upper_y.setter
    @LayoutItemProperty.setter()
    def upper_y(self, value):
        self['upperY'] = value

    @property
    @LayoutItemProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_string(value, 'size_id'),
    )
    def size_id(self):
        return self.get('sizeId')

    @size_id.setter
    @LayoutItemProperty.setter()
    def size_id(self, value):
        self['sizeId'] = value
Exemple #10
0
class DashboardSpecification(PythonModel):
    '''
    A class that defines a Dashboard Specification
    '''
    @classmethod
    def registry(cls):
        return DashboardProperty

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'dateRanges', validate_date_range_item),
    )
    def date_ranges(self):
        return self.get('dateRanges')

    @date_ranges.setter
    @DashboardProperty.setter(
        value_parser_function=lambda date_range_objects: {
            _id: DateRangeSpecification(date_range_object)
            for (_id, date_range_object) in date_range_objects.items()
        })
    def date_ranges(self, value):
        self['dateRanges'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'filters', validate_filter_item),
    )
    def filters(self):
        return self.get('filters')

    @filters.setter
    @DashboardProperty.setter(
        value_parser_function=lambda filter_objects: {
            _id: FilterDefinition(filter_object)
            for (_id, filter_object) in filter_objects.items()
        })
    def filters(self, value):
        self['filters'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'items', validate_layout_item),
    )
    def items(self):
        return self.get('items')

    @items.setter
    @DashboardProperty.setter(
        value_parser_function=lambda layout_objects: {
            _id: LayoutItem(layout_object)
            for (_id, layout_object) in layout_objects.items()
        })
    def items(self, value):
        self['items'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: DashboardOptions(),
        value_validate_function=lambda value: assert_type(
            value, DashboardOptions, argument_name='options'),
    )
    def options(self):
        return self.get('options')

    @options.setter
    @DashboardProperty.setter(
        value_parser_function=lambda value: DashboardOptions(value))
    def options(self, value):
        self['options'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'queries', validate_query_item),
    )
    def queries(self):
        return self.get('queries')

    @queries.setter
    @DashboardProperty.setter(
        value_parser_function=lambda query_objects: {
            _id: QueryDefinition(query_object)
            for (_id, query_object) in query_objects.items()
        })
    def queries(self, value):
        self['queries'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'settings', validate_settings_item),
    )
    def settings(self):
        return self.get('settings')

    @settings.setter
    @DashboardProperty.setter(
        value_parser_function=lambda settings_objects: {
            _id: VisualizationSettings(settings_object)
            for (_id, settings_object) in settings_objects.items()
        })
    def settings(self, value):
        self['settings'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'sizes', validate_size_item),
    )
    def sizes(self):
        return self.get('sizes')

    @sizes.setter
    @DashboardProperty.setter(
        value_parser_function=lambda size_objects: {
            _id: LayoutSize(size_object)
            for (_id, size_object) in size_objects.items()
        })
    def sizes(self, value):
        self['sizes'] = value

    @property
    @DashboardProperty.getter()
    def version(self):
        return '2018-12-11'

    def __repr__(self):
        if self.options:
            title = self.options.title
            return 'Dashboard \'{0}\''.format(title)

        return 'Unnamed Dashboard'
Exemple #11
0
def validate_advanced_field_item(value, index, argument_name):
    formatted_argument_name = '{0}[{1}]'.format(argument_name, index)
    assert_type(value,
                AdvancedFieldDefinition,
                argument_name=formatted_argument_name)
Exemple #12
0
def validate_custom_field(value, index, argument_name):
    formatted_argument_name = '{0}[{1}]'.format(argument_name, index)
    assert_type(value, CustomField, argument_name=formatted_argument_name)
Exemple #13
0
class SettingsGroup(PythonModel):
    AXES_SETTINGS_TYPES = set(
        [
            VisualizationType.CHART,
            VisualizationType.TIME,
            VisualizationType.HEATTILES,
            VisualizationType.BUBBLE_CHART,
        ]
    )

    LEGEND_SETTINGS_TYPES = set(
        [
            VisualizationType.ANIMATED_MAP,
            VisualizationType.CHART,
            VisualizationType.MAP,
            VisualizationType.TIME,
        ]
    )

    def __init__(self, visualization_type, values=None, allow_extra_properties=True):
        self.visualization_type = visualization_type
        super(SettingsGroup, self).__init__(values, allow_extra_properties)

    @classmethod
    def registry(cls):
        return SettingsGroupProperty

    @property
    @SettingsGroupProperty.getter(
        value_validate_function=lambda value: assert_type(
            value, LegendSettings, 'LegendSettings', 'legend_settings'
        ),
        default_value=LegendSettings,
    )
    def legend_settings(self):
        return self.get('legendSettings')

    @legend_settings.setter
    @SettingsGroupProperty.setter(value_parser_function=LegendSettings)
    def legend_settings(self, value):
        self['legendSettings'] = value

    @property
    @SettingsGroupProperty.getter(
        value_validate_function=lambda value: assert_type(
            value, AxesSettings, 'AxesSettings', 'axes_settings'
        ),
        default_value=AxesSettings,
    )
    def axes_settings(self):
        return self.get('axesSettings')

    @axes_settings.setter
    @SettingsGroupProperty.setter(value_parser_function=AxesSettings)
    def axes_settings(self, value):
        # print 'AxesSettings',value
        self['axesSettings'] = value

    @property
    @SettingsGroupProperty.getter(
        nullable=False,
        value_validate_function=lambda value: assert_type(
            value, SeriesSettings, 'SeriesSettings', 'series_settings'
        ),
        default_value=SeriesSettings,
    )
    def series_settings(self):
        return self.get('seriesSettings')

    @series_settings.setter
    @SettingsGroupProperty.setter(value_parser_function=SeriesSettings)
    def series_settings(self, value):
        self['seriesSettings'] = value

    @property
    @SettingsGroupProperty.getter(
        value_validate_function=lambda value: assert_one_of(
            value, VIEW_SPECIFIC_TYPES, 'view_specific_settings'
        )
    )
    def view_specific_settings(self):
        if 'viewSpecificSettings' not in self:
            self['viewSpecificSettings'] = VISUALIZATION_TYPE_TO_SETTING[
                self.visualization_type
            ]()

        return self.get('viewSpecificSettings')

    @view_specific_settings.setter
    @SettingsGroupProperty.setter(
        value_validate_function=lambda value: assert_one_of(
            value, VIEW_SPECIFIC_TYPES_OR_DICT, 'view_specific_settings'
        )
    )
    def view_specific_settings(self, value):
        value = VISUALIZATION_TYPE_TO_SETTING[self.visualization_type](value)
        self['viewSpecificSettings'] = value

    def after_serialize(self, serialized_value):
        if self.visualization_type not in SettingsGroup.AXES_SETTINGS_TYPES:
            serialized_value.pop('axesSettings')

        if self.visualization_type not in SettingsGroup.LEGEND_SETTINGS_TYPES:
            serialized_value.pop('legendSettings')

        return serialized_value
Exemple #14
0
class DashboardSpecification(PythonModel):
    '''
    A class that defines a Dashboard Specification
    '''
    @classmethod
    def registry(cls):
        return DashboardProperty

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'dateRanges', validate_date_range_item),
    )
    def date_ranges(self):
        return self.get('dateRanges')

    @date_ranges.setter
    @DashboardProperty.setter(
        value_parser_function=lambda date_range_objects: {
            _id: DateRangeSpecification(date_range_object)
            for (_id, date_range_object) in date_range_objects.items()
        })
    def date_ranges(self, value):
        self['dateRanges'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'filters', validate_filter_item),
    )
    def filters(self):
        return self.get('filters')

    @filters.setter
    @DashboardProperty.setter(
        value_parser_function=lambda filter_objects: {
            _id: FilterDefinition(filter_object)
            for (_id, filter_object) in filter_objects.items()
        })
    def filters(self, value):
        self['filters'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'items', validate_layout_item),
    )
    def items(self):
        return self.get('items')

    @items.setter
    @DashboardProperty.setter(
        value_parser_function=lambda layout_objects: {
            _id: LayoutItem(layout_object)
            for (_id, layout_object) in layout_objects.items()
        })
    def items(self, value):
        self['items'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=DashboardOptions,
        value_validate_function=lambda value: assert_type(
            value, DashboardOptions, argument_name='options'),
    )
    def options(self):
        return self.get('options')

    @options.setter
    @DashboardProperty.setter(value_parser_function=DashboardOptions)
    def options(self, value):
        self['options'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'queries', validate_query_item),
    )
    def queries(self):
        return self.get('queries')

    @queries.setter
    @DashboardProperty.setter(
        value_parser_function=lambda query_objects: {
            _id: QueryDefinition(query_object)
            for (_id, query_object) in query_objects.items()
        })
    def queries(self, value):
        self['queries'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'settings', validate_settings_item),
    )
    def settings(self):
        return self.get('settings')

    @settings.setter
    @DashboardProperty.setter(
        value_parser_function=lambda settings_objects: {
            _id: VisualizationSettings(settings_object)
            for (_id, settings_object) in settings_objects.items()
        })
    def settings(self, value):
        self['settings'] = value

    @property
    @DashboardProperty.getter(
        nullable=False,
        default_value=lambda: {},
        value_validate_function=lambda value: assert_mapping(
            value, 'sizes', validate_size_item),
    )
    def sizes(self):
        return self.get('sizes')

    @sizes.setter
    @DashboardProperty.setter(
        value_parser_function=lambda size_objects: {
            _id: LayoutSize(size_object)
            for (_id, size_object) in size_objects.items()
        })
    def sizes(self, value):
        self['sizes'] = value

    @property
    @DashboardProperty.getter()
    def version(self):
        return '2019-01-24'

    def after_deserialize(self):
        '''
        After deserializing, we need to find all BUMP_CHART settings
        and check if its seriesSettings are incomplete. If so, we need
        to fix it.
        '''
        for settings_object in list(self.settings.values()):
            view_settings = settings_object.view_type_settings

            # HACK(pablo, vedant): get the series settings from the CHART
            # visualization, which we'll just assume is always correct
            correct_series = view_settings['CHART'].series_settings
            correct_series_objs = correct_series.series_objects
            correct_series_order = correct_series.series_order

            if 'BUMP_CHART' not in view_settings:
                view_settings['BUMP_CHART'] = SettingsGroup(
                    VisualizationType.BUMP_CHART)
                view_settings['BUMP_CHART'].series_settings = {
                    'seriesObjects': correct_series_objs,
                    'seriesOrder': correct_series_order,
                }
            else:
                # make sure the bumpchart series settings are correctly set
                bumpchart_series = view_settings['BUMP_CHART'].series_settings
                series_info = {
                    'seriesObjects': bumpchart_series['seriesObjects'],
                    'seriesOrder': bumpchart_series['seriesOrder'],
                }
                if series_info[
                        'seriesObjects'] == {} and correct_series_objs != {}:
                    series_info['seriesObjects'] = correct_series_objs
                if series_info[
                        'seriesOrder'] == [] and correct_series_order != []:
                    series_info['seriesOrder'] = correct_series_order
                view_settings['BUMP_CHART'].series_settings = series_info

    def __repr__(self):
        if self.options:
            title = self.options.title
            return u'Dashboard \'{0}\''.format(title)

        return 'Unnamed Dashboard'