예제 #1
0
class BtcTransactions(Model):
    """
    Class representing information for a single bitcoin transaction.
    Each field is explained below

    tx_hash: hash of transaction (string)
    time: time of transaction (int)
    total_val_input: total amount of satoshis sent as input
    total_val_output: total amount of satoshis sent as output
    tx_inx: transaction index (int)
    input: set wallet addresses that are inputs to transaction
    output: set wallet addresses that are outputs to transaction
    """
    class Meta:
        table_name = 'btc_transactions_bt'
        read_capacity_units = 15
        write_capacity_units = 20

    tx_inx = NumberAttribute(hash_key=True)
    tx_hash = UnicodeAttribute()
    time = NumberAttribute()
    total_val_input = NumberAttribute()
    total_val_output = NumberAttribute()
    #  [{'address': xyx, 'value': 10, 'tx_inx': inx}, {'address': xyx, 'value': 10, 'tx_inx': inx}]
    inputs = JSONAttribute()
    # [{'address': xyx, 'value': 10}, {'address': xyx, 'value': 10}, ...]
    outputs = JSONAttribute()
예제 #2
0
class BtcAddresses(Model):
    """
    Class representing information relevant to a single bitcoin wallet address.
    Each field is explained below

    address: wallet address (string)
    node_id: id of node associated with address (after initial clustering based in common inputs) (string)
    used_as_input: set of tx_hash objects where the address was used an input
        in corresponding transaction (set)
    used_as_output: set of tx_hash objects where the address was used as output
        in corresponding transaction (set)
    """
    class Meta:
        table_name = 'btc_addresses_bt'
        read_capacity_units = 25
        write_capacity_units = 50

    address = UnicodeAttribute(hash_key=True)

    addr_index = AddrIdentifierIndex()
    identifier = NumberAttribute()

    neighbor_addrs = JSONAttribute(default=json.dumps([]))
    used_as_input = JSONAttribute(default=json.dumps([]))
    used_as_output = JSONAttribute(default=json.dumps([]))
예제 #3
0
class Game(Model):
    class Meta:
        table_name = GAMES_TABLE_NAME
        region = REGION_NAME

    uuid = UnicodeAttribute(hash_key=True, default=str(uuid.uuid4()))
    game_name = UnicodeAttribute()
    search_name = UnicodeAttribute()
    openretro_url = UnicodeAttribute(null=True)
    whdload_url = UnicodeAttribute(null=True)
    hardware = JSONAttribute(null=True)
    custom_controls = JSONAttribute(null=True)
    variants = UnicodeSetAttribute(null=True)

    def to_dict(self):
        return {
            'uuid': self.uuid,
            'game_name': self.game_name,
            'search_name': self.search_name,
            'openretro_url': self.openretro_url,
            'whdload_url': self.whdload_url,
            'hardware': self.hardware,
            'custom_controls': self.custom_controls,
            'variants': list(self.variants) if self.variants else None,
        }
예제 #4
0
class ImageMetaData(Model):
    class Meta:
        table_name = os.environ.get('META_TABLE')

    checksum = UnicodeAttribute(hash_key=True)
    exif = JSONAttribute()
    info = JSONAttribute()
예제 #5
0
class Server(Model):
    class Meta:
        if os.getenv("STAGE", "PRODUCTION") == "TESTING":
            host = "http://dynamodb:8000"
        table_name = "server"
        billing_mode = "PAY_PER_REQUEST"
        region = "us-west-2"

    server_index = ServerIndex()

    address = UnicodeAttribute(hash_key=True)
    game = UnicodeAttribute()

    protocol = NumberAttribute(default=0)

    status = JSONAttribute()
    players = JSONAttribute()
    player_count = NumberAttribute(default=0)

    active = BooleanAttribute(default=True)
    scraped = BooleanAttribute(default=False)

    first_seen = UTCDateTimeAttribute(default=datetime.utcnow())
    last_seen = UTCDateTimeAttribute(default=datetime.utcnow())

    country_code = UnicodeAttribute(default="ZZ")
예제 #6
0
class Lexema(Model):
    """
    A DynamoDB Lexema
    """
    class Meta:
        table_name = "Lexemas"

    lexema = UnicodeAttribute(hash_key=True)
    documentos = JSONAttribute(default='[]')  # inverse index
    tfidf = JSONAttribute(default='[]')
예제 #7
0
    def test_json_attribute(self):
        """
        JSONAttribute.default
        """
        attr = JSONAttribute()
        assert attr is not None

        assert attr.attr_type == STRING
        attr = JSONAttribute(default={})
        assert attr.default == {}
예제 #8
0
    def test_json_attribute(self):
        """
        JSONAttribute.default
        """
        attr = JSONAttribute()
        self.assertIsNotNone(attr)

        self.assertEqual(attr.attr_type, STRING)
        attr = JSONAttribute(default={})
        self.assertEqual(attr.default, {})
예제 #9
0
class Robot(Model):
    class Meta:
        table_name = 'Robots'
    id = UnicodeAttribute(hash_key=True)
    buildingId = UnicodeAttribute(default='')
    sensorId = JSONAttribute(default='[]')
    capabilities = JSONAttribute(default='[]')
    movement = UnicodeAttribute(default='')
    floor = NumberAttribute(default=0)
    room = NumberAttribute(default=0)
    xpos = NumberAttribute(default=0)
    ypos = NumberAttribute(default=0)
예제 #10
0
class User(Model):
    class Meta:
        table_name = "users"
        region = "us-east-2"

    uid = UnicodeAttribute(hash_key=True)
    email = UnicodeAttribute()
    membership_type = NumberAttribute(default=0)
    membership_start = UTCDateTimeAttribute(null=True)
    payment = JSONAttribute(
        null=True)  # {credit_card, security, expiry, name, address, phone}
    websites = JSONAttribute(
        null=True)  # {url1:{name, frequency, status, contact}, url2: ...}
예제 #11
0
class Order(Model):
    class Meta:
        table_name = 'Order'
        region = 'ap-northeast-1'
        max_retry_attempts = 8
        base_backoff_ms = 297

    order_id = UnicodeAttribute(hash_key=True)
    order_date = UnicodeAttribute()
    customer_id = UnicodeAttribute()
    order_status = UnicodeAttribute()
    items = ListAttribute()
    payment = JSONAttribute(null=True)
    inventory = JSONAttribute(null=True)
예제 #12
0
class Cluster(Model):
    """
    A DynamoDB Server Cluster.
    """
    class Meta:
        table_name = settings.value.DYNAMODB_TABLE_HOSTS
        if settings.value.APPLICATION_ENV == 'development':
            host = settings.value.DYNAMODB_URL

    name = UnicodeAttribute(hash_key=True)
    sd_type = UnicodeAttribute()
    connect_timeout_ms = NumberAttribute()
    per_connection_buffer_limit_bytes = NumberAttribute()
    lb_type = UnicodeAttribute()
    ring_hash_lb_config = JSONAttribute(null=True)
    hosts = JSONAttribute(null=True)
    service_name = UnicodeAttribute(null=True)
    health_check = JSONAttribute(null=True)
    max_requests_per_connection = NumberAttribute(null=True)
    circuit_breakers = JSONAttribute(null=True)
    ssl_context = JSONAttribute(null=True)
    features = UnicodeAttribute(null=True)
    http2_settings = JSONAttribute(null=True)
    cleanup_interval_ms = NumberAttribute(null=True)
    dns_refresh_rate_ms = NumberAttribute(null=True)
    dns_lookup_family = UnicodeAttribute(null=True)
    dns_resolvers = JSONAttribute(null=True)
    outlier_detection = JSONAttribute(null=True)
예제 #13
0
class PokemonModel(Model):
    class Meta:
        table_name = 'pokemon'
        aws_access_key_id = aws_access
        aws_secret_access_key = aws_secret_access

    name = UnicodeAttribute(hash_key=True)
    game = UnicodeAttribute(null=True)
    region = UnicodeAttribute(null=True)
    type = JSONAttribute(null=True)
    display = JSONAttribute(null=True)
    evolution = JSONAttribute(null=True)
    stats = JSONAttribute(null=True)
    image_url = UnicodeAttribute(null=True)
    dex_number = NumberAttribute(null=True)
예제 #14
0
class DynamoDBEventModel(Model):
    """
    A DynamoDB Event model
    """
    class Meta:
        region = os.environ.get('AWS_REGION', 'ap-southeast-2')
        table_name = os.environ.get("EVENT_TABLE", "events")
        host = os.environ.get('DYNAMODB_HOST', None)

    aggregate_name = UnicodeAttribute(hash_key=True)
    aggregate_key = UnicodeAttribute(range_key=True)
    event_type = UnicodeAttribute()
    created_at = UTCDateTimeAttribute()
    event_data = JSONAttribute()

    @classmethod
    def _conditional_operator_check(cls, conditional_operator):
        pass

    @property
    def aggregate_id(self):
        return self.aggregate_key.split(AGGREGATE_KEY_DELIMITER)[0]

    @property
    def version(self):
        return int(self.aggregate_key.split(AGGREGATE_KEY_DELIMITER)[1])
예제 #15
0
class TableWithRange(Model):
    Meta = make_meta(table_name='with_range')

    key1 = UnicodeAttribute(hash_key=True)
    key2 = UnicodeAttribute(range_key=True)
    date_attr = UTCDateTimeAttribute(null=True)
    json_attr = JSONAttribute()
예제 #16
0
    def test_quoted_json(self):
        attr = JSONAttribute()
        serialized = attr.serialize('\\t')
        assert attr.deserialize(serialized) == '\\t'

        serialized = attr.serialize('"')
        assert attr.deserialize(serialized) == '"'
예제 #17
0
class Poll(Model):
    """
    A DynamoDB User
    """
    class Meta:
        table_name = DYNAMO_DB_TABLE_NAME
    key = UnicodeAttribute(hash_key=True)

    question = UnicodeAttribute()
    author = JSONAttribute()
    # option_id is index of the option in the list
    options = ListAttribute(default=list)
    votes = MapAttribute(default=dict)  # user_id -> option_id
    users = MapAttribute(default=dict)   # user_id -> data
    # see https://pynamodb.readthedocs.io/en/latest/optimistic_locking.html
    version = VersionAttribute()
    # information about poll message in telegram
    telegram_version = NumberAttribute()
    telegram_datetime = UTCDateTimeAttribute()

    def get_users_by_option_id(self):
        users_by_option_id = {}
        for user_id in self.votes:
            option_id = self.votes[user_id]
            users_by_option_id.setdefault(option_id, [])
            users_by_option_id[option_id].append(self.users[user_id])
        return users_by_option_id
예제 #18
0
    def test_quoted_json(self):
        attr = JSONAttribute()
        serialized = attr.serialize('\\t')
        self.assertEqual(attr.deserialize(serialized), '\\t')

        serialized = attr.serialize('"')
        self.assertEqual(attr.deserialize(serialized), '"')
class KeySchema(Model):
  iprcode = NumberAttribute(hash_key=True, default = 0)
  cprcode = NumberAttribute(default = 0, range_key = True)
  oprcode = NumberAttribute(default = 0)
  pr_dpcode = UnicodeAttribute(default = 'none')
  pr_barcode = UnicodeAttribute(default = 'none')
  pr_barcode2 = UnicodeAttribute(default = 'none')
  pr_sucode1 = UnicodeAttribute(default = 'none')
  pr_suref3 = UnicodeAttribute(default= 'none')
  pr_sa_method = UnicodeAttribute(default= 'none')
  sellingPrice = NumberAttribute(default = 0)
  lastUpdate = NumberAttribute( default = 0)
  needsUpdate = UnicodeAttribute(default = 'Y')
  data = JSONAttribute()

  # indexes
  needsUpdateIndex = createIndex('needsUpdate','sellingPrice')
  cprcodeIndex = createIndex('cprcode', 'sellingPrice')
  oprcodeIndex = createIndex('oprcode', 'sellingPrice')
  pr_dpcodeIndex = createIndex('pr_dpcode', 'sellingPrice')
  pr_barcodeIndex = createIndex('pr_barcode', 'sellingPrice')
  pr_barcode2Index = createIndex('pr_barcode2', 'sellingPrice')
  pr_suref3Index = createIndex('pr_suref3', 'sellingPrice')
  pr_sa_methodIndex = createIndex('pr_sa_method', 'sellingPrice')
  cprcodeOnlyIndex = createIndex('cprcode', indexName='cprcodeOnly')

  def __repr__(self):
    return pformat(vars(self)["attribute_values"])
예제 #20
0
class MetaAttribute(MapAttribute):
    num_threads = NumberAttribute(default=0)
    num_arecs = NumberAttribute(default=0)
    entrypoint = UnicodeAttribute(null=True)
    stopped = ListAttribute(default=list)
    exe = MapAttribute(null=True)
    result = JSONAttribute(null=True)
    broken = BooleanAttribute(default=False)
예제 #21
0
class Website(Model):
    class Meta:
        table_name = "websites"
        region = "us-east-2"

    url = UnicodeAttribute(hash_key=True)
    current_code = UnicodeAttribute(null=True)
    contacts = JSONAttribute(null=True)  # {contact_location:frequency}
예제 #22
0
파일: nosql_models.py 프로젝트: kozlek/b4t
class EventModel(BaseNoSQLModel):
    event_date = DateTimeAttribute()
    appointment_id = DjangoPrimaryKeyAttribute()
    name = UnicodeAttribute()
    attributes = JSONAttribute(default={})

    class Meta(BaseNoSQLModel.Meta):
        table_name = "event"
예제 #23
0
class CharacterModel(Model):
    class Meta:
        table_name = 'ff14-character'
        region = 'us-west-2'

    c_id = NumberAttribute(hash_key=True)
    name = UnicodeAttribute()
    levels = JSONAttribute()
예제 #24
0
 def test_json_deserialize(self):
     """
     JSONAttribute.deserialize
     """
     attr = JSONAttribute()
     item = {'foo': 'bar', 'bool': True, 'number': 3.141}
     encoded = six.u(json.dumps(item))
     self.assertEqual(attr.deserialize(encoded), item)
예제 #25
0
 def test_control_chars(self):
     """
     JSONAttribute with control chars
     """
     attr = JSONAttribute()
     item = {'foo\t': 'bar\n', 'bool': True, 'number': 3.141}
     encoded = json.dumps(item)
     assert attr.deserialize(encoded) == item
예제 #26
0
 def test_json_deserialize(self):
     """
     JSONAttribute.deserialize
     """
     attr = JSONAttribute()
     item = {'foo': 'bar', 'bool': True, 'number': 3.141}
     encoded = json.dumps(item)
     assert attr.deserialize(encoded) == item
예제 #27
0
class BlindCredential(Model):
    class Meta:
        table_name = settings.DYNAMODB_TABLE
        if settings.DYNAMODB_URL:
            host = settings.DYNAMODB_URL
        region = settings.AWS_DEFAULT_REGION
        connection_cls = DDBConnection
        session_cls = DDBSession

    id = UnicodeAttribute(hash_key=True)
    revision = NumberAttribute()
    data_type = UnicodeAttribute()
    data_type_date_index = DataTypeDateIndex()
    name = UnicodeAttribute()
    credential_pairs = JSONAttribute()
    credential_keys = NonNullUnicodeSetAttribute(default=set, null=True)
    enabled = BooleanAttribute(default=True)
    data_key = JSONAttribute()
    cipher_version = NumberAttribute()
    cipher_type = UnicodeAttribute()
    metadata = JSONAttribute(default=dict, null=True)
    modified_date = UTCDateTimeAttribute(default=datetime.now)
    modified_by = UnicodeAttribute()
    documentation = UnicodeAttribute(null=True)

    def equals(self, other_cred):
        if self.name != other_cred.name:
            return False
        if self.credential_pairs != other_cred.credential_pairs:
            return False
        if self.credential_keys != other_cred.credential_keys:
            return False
        if self.enabled != other_cred.enabled:
            return False
        if self.data_key != other_cred.data_key:
            return False
        if self.cipher_version != other_cred.cipher_version:
            return False
        if self.cipher_type != other_cred.cipher_type:
            return False
        if self.metadata != other_cred.metadata:
            return False
        if self.documentation != other_cred.documentation:
            return False
        return True
예제 #28
0
class ConfigModel(Model):
    class Meta:
        table_name = "PongConfiguration"
        region = "us-west-2"

    Id = UnicodeAttribute(hash_key=True)
    Config = JSONAttribute()
    UpdatedAt = UTCDateTimeAttribute()
    CreatedAt = UTCDateTimeAttribute()
예제 #29
0
 def test_json_serialize(self):
     """
     JSONAttribute.serialize
     """
     attr = JSONAttribute()
     item = {'foo': 'bar', 'bool': True, 'number': 3.141}
     assert attr.serialize(item) == json.dumps(item)
     assert attr.serialize({}) == '{}'
     assert attr.serialize(None) is None
예제 #30
0
 def test_json_serialize(self):
     """
     JSONAttribute.serialize
     """
     attr = JSONAttribute()
     item = {'foo': 'bar', 'bool': True, 'number': 3.141}
     self.assertEqual(attr.serialize(item), six.u(json.dumps(item)))
     self.assertEqual(attr.serialize({}), six.u('{}'))
     self.assertEqual(attr.serialize(None), None)