Esempio n. 1
0
 def to_derived_bucket(self, bucket: Bucket) -> Bucket:
     if bucket.type == BucketType.VALUE:
         if not isinstance(bucket, NumericValueBucket):
             return NumericValueBucket(**bucket.to_dict())
     elif bucket.type == BucketType.VALUE_MEASURE:
         if not isinstance(bucket, NumericValueMeasureBucket):
             return NumericValueMeasureBucket(**bucket.to_dict())
     elif bucket.type == BucketType.CATEGORY_MEASURE:
         if not isinstance(bucket, CategoryMeasureBucket):
             return CategoryMeasureBucket(**bucket.to_dict())
     elif bucket.type == BucketType.ENUM_MEASURE:
         if not isinstance(bucket, EnumMeasureBucket):
             return EnumMeasureBucket(**bucket.to_dict())
     return bucket
Esempio n. 2
0
 def try_get_enum_id(self, bucket: Bucket) -> Optional[MeasureMethod]:
     if bucket.type == BucketType.ENUM_MEASURE:
         if isinstance(bucket, EnumMeasureBucket):
             return bucket.enumId
         else:
             return bucket.to_dict().get('enumId')
     else:
         return None
Esempio n. 3
0
 def try_get_measure(self, bucket: Bucket) -> Optional[MeasureMethod]:
     if bucket.type == BucketType.VALUE_MEASURE \
       or bucket.type == BucketType.CATEGORY_MEASURE or bucket.type == BucketType.ENUM_MEASURE:
         if isinstance(bucket, MeasureBucket):
             return bucket.measure
         else:
             return bucket.to_dict().get('measure')
     else:
         return None
Esempio n. 4
0
 def try_get_include(self,
                     bucket: Bucket) -> Optional[RangeBucketValueIncluding]:
     if bucket.type == BucketType.VALUE:
         if isinstance(bucket, NumericValueBucket):
             return bucket.include
         else:
             return bucket.to_dict().get('include')
     else:
         return None
Esempio n. 5
0
 def deserialize(self, row: EntityRow) -> Bucket:
     # noinspection PyTypeChecker
     return TupleShaper.deserialize_tenant_based(
         row,
         self.to_derived_bucket(
             Bucket(
                 bucketId=row.get('bucket_id'),
                 name=row.get('name'),
                 type=row.get('type'),
                 include=row.get('include'),
                 measure=row.get('measure'),
                 enumId=row.get('enum_id'),
                 segments=row.get('segments'),
                 description=row.get('description'),
             )))
	def to_category_segments_bucket(self, bucket: Bucket) -> CategorySegmentsHolder:
		if isinstance(bucket, CategorySegmentsHolder):
			return bucket
		else:
			return CategorySegmentsHolder(**bucket.to_dict())
	def to_numeric_segments_bucket(self, bucket: Bucket) -> NumericSegmentsHolder:
		if isinstance(bucket, NumericSegmentsHolder):
			return bucket
		else:
			return NumericSegmentsHolder(**bucket.to_dict())
		def fill_bucket_id(bucket: Bucket) -> None:
			old_bucket_id = bucket.bucketId
			bucket.bucketId = bucket_service.generate_storable_id()
			bucket_id_map[old_bucket_id] = bucket.bucketId
Esempio n. 9
0
 def set_storable_id(self, storable: Bucket,
                     storable_id: BucketId) -> Bucket:
     storable.bucketId = storable_id
     return storable