class GlobalStat(BaseStatistic):
    """An aggregate of all entities across the entire application.

    This statistic only has a single instance in Cloud Datastore that contains
    the total number of entities stored and the total number of bytes they take
    up.

    Attributes:
        entity_bytes (int): the number of bytes taken up to store the statistic
            in Cloud Datastore minus the cost of storing indices.
        builtin_index_bytes (int): the number of bytes taken up to store
            built-in index entries.
        builtin_index_count (int): the number of built-in index entries.
        composite_index_bytes (int): the number of bytes taken up to store
            composite index entries.
        composite_index_count (int): the number of composite index entries.
    """

    STORED_KIND_NAME = "__Stat_Total__"

    entity_bytes = model.IntegerProperty(default=0)

    builtin_index_bytes = model.IntegerProperty(default=0)

    builtin_index_count = model.IntegerProperty(default=0)

    composite_index_bytes = model.IntegerProperty(default=0)

    composite_index_count = model.IntegerProperty(default=0)
class BaseStatistic(model.Model):
    """Base Statistic Model class.

    Attributes:
        bytes (int): the total number of bytes taken up in Cloud Datastore for
            the statistic instance.
        count (int): attribute is the total number of occurrences of the
            statistic in Cloud Datastore.
        timestamp (datetime.datetime): the time the statistic instance was
            written to Cloud Datastore.
    """

    # This is necessary for the _get_kind() classmethod override.
    STORED_KIND_NAME = "__BaseStatistic__"

    bytes = model.IntegerProperty()

    count = model.IntegerProperty()

    timestamp = model.DateTimeProperty()

    @classmethod
    def _get_kind(cls):
        """Kind name override."""
        return cls.STORED_KIND_NAME
class KindPropertyNamePropertyTypeStat(BaseKindStatistic):
    """Statistic on (kind, property_name, property_type) tuples in Cloud
    Datastore.

    There is an instance of the KindPropertyNamePropertyTypeStat for every
    (kind, property_name, property_type) tuple in the application's datastore.

    Attributes:
      property_type (str): the property type associated with the statistic
          instance.
      property_name (str): the name of the property associated with the
          statistic instance.
      builtin_index_bytes (int): the number of bytes taken up to store
          built-in index entries
      builtin_index_count (int): the number of built-in index entries.
    """

    STORED_KIND_NAME = "__Stat_PropertyType_PropertyName_Kind__"

    property_type = model.StringProperty()

    property_name = model.StringProperty()

    builtin_index_bytes = model.IntegerProperty(default=0)

    builtin_index_count = model.IntegerProperty(default=0)
class NamespaceStat(BaseStatistic):
    """An aggregate of all entities across an entire namespace.

    This statistic has one instance per namespace.  The key_name is the
    represented namespace. NamespaceStat entities will only be found
    in the namespace "" (empty string). It contains the total
    number of entities stored and the total number of bytes they take up.

    Attributes:
        subject_namespace (str): the namespace associated with the statistic
            instance.
        entity_bytes (int): the number of bytes taken up to store the statistic
            in Cloud Datastore minus the cost of storing indices.
        builtin_index_bytes (int): the number of bytes taken up to store
            builtin-in index entries.
        builtin_index_count (int): the number of built-in index entries.
        composite_index_bytes (int): the number of bytes taken up to store
            composite index entries.
        composite_index_count (int): the number of composite index entries.
    """

    STORED_KIND_NAME = "__Stat_Namespace__"

    subject_namespace = model.StringProperty()

    entity_bytes = model.IntegerProperty(default=0)

    builtin_index_bytes = model.IntegerProperty(default=0)

    builtin_index_count = model.IntegerProperty(default=0)

    composite_index_bytes = model.IntegerProperty(default=0)

    composite_index_count = model.IntegerProperty(default=0)
class PropertyTypeStat(BaseStatistic):
    """An aggregate of all properties across the entire application by type.

    There is an instance of the PropertyTypeStat for every property type
    (google.appengine.api.datastore_types._PROPERTY_TYPES) in use by the
    application in its datastore.

    Attributes:
        property_type (str): the property type associated with the statistic
            instance.
        entity_bytes (int): the number of bytes taken up to store the statistic
            in Cloud Datastore minus the cost of storing indices.
        builtin_index_bytes (int): the number of bytes taken up to store
        built-in index entries.
        builtin_index_count (int): the number of built-in index entries.
    """

    STORED_KIND_NAME = "__Stat_PropertyType__"

    property_type = model.StringProperty()

    entity_bytes = model.IntegerProperty(default=0)

    builtin_index_bytes = model.IntegerProperty(default=0)

    builtin_index_count = model.IntegerProperty(default=0)
Exemple #6
0
class KindStat(BaseKindStatistic):
    """An aggregate of all entities at the granularity of their Kind.

    There is an instance of the KindStat for every Kind that is in the
    application's datastore.  This stat contains per-Kind statistics.

    Attributes:
        builtin_index_bytes (int): the number of bytes taken up to store
            built-in index entries.
        builtin_index_count (int): the number of built-in index entries.
        composite_index_bytes (int): the number of bytes taken up to store
            composite index entries.
        composite_index_count (int): the number of composite index entries.
    """

    __slots__ = ()

    STORED_KIND_NAME = "__Stat_Kind__"

    builtin_index_bytes = model.IntegerProperty(default=0)

    builtin_index_count = model.IntegerProperty(default=0)

    composite_index_bytes = model.IntegerProperty(default=0)

    composite_index_count = model.IntegerProperty(default=0)
class EntityGroup(_BaseMetadata):
    """Model for __entity_group__ metadata, available in HR datastore only.

    This metadata contains a numeric __version__ property that is guaranteed
    to increase on every change to the entity group. The version may increase
    even in the absence of user-visible changes to the entity group. The
    __entity_group__ entity may not exist if the entity group was never
    written to.

    Attributes:
        version (int): counter for changes in entity group.
    """

    __slots__ = ()

    KIND_NAME = "__entity_group__"
    ID = 1

    version = model.IntegerProperty(name="__version__")

    @classmethod
    def key_for_entity_group(cls, key):
        """Return the key for the entity group containing key.

        Args:
            key (key.Key): a key for an entity group whose __entity_group__ key
                you want.

        Returns:
            key.Key: The __entity_group__ key for the entity group containing
                key.
        """
        return model.Key(cls.KIND_NAME, cls.ID, parent=key.root())
class BaseKindStatistic(BaseStatistic):
    """Base Statistic Model class for stats associated with kinds.

    Attributes:
        kind_name (str): the name of the kind associated with the statistic
            instance.
        entity_bytes (int): the number of bytes taken up to store the statistic
            in Cloud Datastore minus the cost of storing indices.
    """

    STORED_KIND_NAME = "__BaseKindStatistic__"

    kind_name = model.StringProperty()

    entity_bytes = model.IntegerProperty(default=0)
class KindCompositeIndexStat(BaseStatistic):
    """Statistic on (kind, composite_index_id) tuples in Cloud Datastore.

    There is an instance of the KindCompositeIndexStat for every unique
    (kind, composite_index_id) tuple in the application's datastore indexes.

    Attributes:
        index_id (int): the id of the composite index associated with the
            statistic instance.
        kind_name (str): the name of the kind associated with the statistic
            instance.
    """

    STORED_KIND_NAME = "__Stat_Kind_CompositeIndex__"

    index_id = model.IntegerProperty()

    kind_name = model.StringProperty()
 class SomeKind(model.Model):
     prop1 = model.IntegerProperty()
 class SomeKind(model.Model):
     prop1 = model.StringProperty()
     prop2 = model.StringProperty()
     prop3 = model.IntegerProperty()
     prop4 = model.IntegerProperty()
 def test_constructor():
     with pytest.raises(NotImplementedError):
         model.IntegerProperty()