Exemple #1
0
    def Insert(self, distance, currentTime):
		distanceData = Entity()
		distanceData.PartitionKey = 'sensorKey'
		distanceData.RowKey = str(uuid.uuid1())
		distanceData.distance = str(distance)
		distanceData.time = str(currentTime)
		self._tableService.insert_entity('sensordata', distanceData)
    def batch(self):
        table_name = self._create_table()

        entity = Entity()
        entity.PartitionKey = 'batch'
        entity.test = True

        # All operations in the same batch must have the same partition key but different row keys
        # Batches can hold from 1 to 100 entities
        # Batches are atomic. All operations completed simulatenously. If one operation fails, they all fail.
        # Insert, update, merge, insert or merge, insert or replace, and delete entity operations are supported

        # Context manager style
        with self.service.batch(table_name) as batch:
            for i in range(0, 5):
                entity.RowKey = 'context_{}'.format(i)
                batch.insert_entity(entity)

        # Commit style
        batch = TableBatch()
        for i in range(0, 5):
            entity.RowKey = 'commit_{}'.format(i)
            batch.insert_entity(entity)
        self.service.commit_batch(table_name, batch)

        self.service.delete_table(table_name)
 def _create_random_base_entity_class(self):
     '''
     Creates a class-based entity with only pk and rk.
     '''
     partition = self.get_resource_name('pk')
     row = self.get_resource_name('rk')
     entity = Entity()
     entity.PartitionKey = partition
     entity.RowKey = row
     return entity
    def test_batch_update(self):
        # Arrange

        # Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_update'
        entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty(EdmType.INT64, '1234567890')
        entity.test5 = datetime.utcnow()
        self.ts.insert_entity(self.table_name, entity)

        entity = self.ts.get_entity(self.table_name, '001', 'batch_update')
        self.assertEqual(3, entity.test3)
        entity.test2 = 'value1'

        batch = TableBatch()
        batch.update_entity(entity)
        resp = self.ts.commit_batch(self.table_name, batch)

        # Assert
        self.assertIsNotNone(resp)
        entity = self.ts.get_entity(self.table_name, '001', 'batch_update')
        self.assertEqual('value1', entity.test2)
        self.assertEqual(resp[0], entity.etag)
    def test_batch_too_many_ops(self):
        # Arrange
        entity = self._create_default_entity_dict('001', 'batch_negative_1')
        self.ts.insert_entity(self.table_name, entity)

        # Act
        with self.assertRaises(AzureBatchValidationError):
            batch = TableBatch()
            for i in range(0, 101):
                entity = Entity()
                entity.PartitionKey = 'large'
                entity.RowKey = 'item{0}'.format(i)
                batch.insert_entity(entity)
            self.ts.commit_batch(self.table_name, batch)
    def test_query_entities_large(self):
        # Arrange
        table_name = self._create_query_table(0)
        total_entities_count = 1000
        entities_per_batch = 50

        for j in range(total_entities_count // entities_per_batch):
            batch = TableBatch()
            for i in range(entities_per_batch):
                entity = Entity()
                entity.PartitionKey = 'large'
                entity.RowKey = 'batch{0}-item{1}'.format(j, i)
                entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
                entity.test2 = 'hello world;' * 100
                entity.test3 = 3
                entity.test4 = EntityProperty(EdmType.INT64, '1234567890')
                entity.test5 = datetime(2016, 12, 31, 11, 59, 59, 0)
                batch.insert_entity(entity)
            self.ts.commit_batch(table_name, batch)

        # Act
        start_time = datetime.now()
        entities = list(self.ts.query_entities(table_name))
        elapsed_time = datetime.now() - start_time

        # Assert
        print('query_entities took {0} secs.'.format(elapsed_time.total_seconds()))
        # azure allocates 5 seconds to execute a query
        # if it runs slowly, it will return fewer results and make the test fail
        self.assertEqual(len(entities), total_entities_count)
    def test_batch_too_many_ops(self):
        # Arrange
        entity = self._create_default_entity_dict('001', 'batch_negative_1')
        self.ts.insert_entity(self.table_name, entity)

        # Act
        with self.assertRaises(AzureBatchValidationError):
            batch = TableBatch()
            for i in range(0, 101):
                entity = Entity()
                entity.PartitionKey = 'large'
                entity.RowKey = 'item{0}'.format(i)
                batch.insert_entity(entity)
            self.ts.commit_batch(self.table_name, batch)
Exemple #8
0
def addCar(rowKey, make, model, year, color, price):
    car = Entity()
    car.PartitionKey = 'cardealership'
    car.RowKey = str(rowKey)
    car.make = make
    car.model = model
    car.year = year
    car.color = color
    car.price = price
    table_service.insert_entity('itemstable', car)
    print('Created entry for car ' + make + ' ' + model)
    return
Exemple #9
0
 def UpdateState(self, newstate):
     #update the status of this node
     self.State = newstate
     logging.info('STATUS CHANGE: ' + self.State)
     status = Entity()
     status.PartitionKey = self.Pool
     status.RowKey = self.Name
     status.Command = ""
     status.State = self.State
     status.IP = self.IP
     status.OS = self.OS
     status.Size = self.Size
     temp = tablesvc.insert_or_replace_entity(Tables.NodeTable, status)
def post_table_log(json_str):
    from azure.storage.table import TableService, Entity
    table_service = TableService(account_name=pkey.azure_storage_id, account_key=pkey.azure_storage_key)
    table_service.create_table("facebooklog")

    def get_table_timestamp_key():
        import time
        current_time = time.gmtime()
        start = time.mktime(current_time)
        last = time.mktime(time.struct_time((2070,1,1,0,0,0,3,100,-1)))
        return str(int(last - start))

    task = Entity()
    task.PartitionKey = 'feedlog'
    task.RowKey = get_table_timestamp_key()
    task.json = json_str
    table_service.insert_entity('facebooklog', task)
Exemple #11
0
def addCoffee(rowKey, brand, flavor, size, price):
    coffee = Entity()
    coffee.PartitionKey = 'coffeeshop'
    coffee.RowKey = str(rowKey)
    coffee.brand = brand
    coffee.flavor = flavor
    coffee.size = size
    coffee.price = price
    table_service.insert_entity('itemstable', coffee)
    print('Created entry for coffee ' + brand + ' ' + flavor)
    return
Exemple #12
0
def importALotOfRows():
    for a in range(1,1100):
        task = Entity()
        task.PartitionKey = 'participant'
        task.RowKey = "participant_" + str(a)
        task.userID = a
        task.datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        task.version = a
        table_service.insert_or_replace_entity('participants', task)
Exemple #13
0
 def UpdateState(self, newstate):
     logging.info("Execution status update: " + newstate)
     self.State = newstate
     execrec = Entity()
     execrec.PartitionKey = self.Command.RowKey
     execrec.RowKey = self.Command.PartitionKey
     execrec.Executable = self.Command.CommandLine
     execrec.State = self.State
     execrec.Output = self.Output
     temp = tablesvc.insert_or_replace_entity(Tables.ExecTable, execrec)
    def put(self):

        userModel = json.loads(request.data)
        userName = str(userModel['userName'])

        #save to table
        task = Entity()
        task.PartitionKey = 'f6dcfcfe-169e-4731-a589-2f8c6c75768a'  #self.partition_name
        task.RowKey = userModel['userName']
        task.FirstName = userModel['firstName']
        task.LastName = userModel['lastName']
        task.EmailAddress = userModel['emailAddress']
        task.CellNo = userModel['cellNo']
        table_service.update_entity(tablename, task, if_match='*')
Exemple #15
0
        async def go():
            entity = Entity()
            entity.Foo = 'Foo'
            entity.Ufo = 'Ufo'
            entity.Number = 1
            entity.PartitionKey = 'app'
            entity.RowKey = '2'

            data = await self.bs.insert_entity('versions', entity)

            self.assertIsNotNone(data)
 def dictToEntity(self, dic):
     entity = Entity()
     if dic['camera']['isActive'] == "True":
         entity.PartitionKey = self.PARTITION_ACTIVATION
     else:
         entity.PartitionKey = self.PARTITION_DEACTIVATION
     entity.RowKey = str(dic['camera']['timestamp'])
     entity.id = dic['camera']['id']
     entity.street = dic['camera']['street']
     entity.city = dic['camera']['city']
     entity.speedLimit = dic['camera']['speedLimit']
     entity.rate = dic['camera']['rate']
     if self.dump:
         print ""
         print "Partition Key = %s" % entity.PartitionKey
         print "Row Key = %s" % entity.RowKey
         print "Camera Id = %s" % entity.id
         print "Street = %s" % entity.street
         print "City = %s" % entity.city
         print "Speed Limit = %d" % entity.speedLimit
         print "Rate = %d" % entity.rate
         print ""
     return entity
Exemple #17
0
def sendLocationToStorageReturnId(markers):
    table_service = getTableService()
    
    """ Generate partition and row keys based on current time """
    year = datetime.now().year - 2000
    partitionKey = str(year) + datetime.now().strftime("%m%d")
    rowKey = datetime.now().strftime("%H%M%S") + str(random.randint(0, 99))
        
    """ Create entity send to Azure Storage Table. PartitionKey and RowKey make up composite key """
    entity = Entity();
    entity.PartitionKey = partitionKey
    entity.RowKey = rowKey

    """ 
        Azure storage is not able to serialize lists so store as JSON string. Also convert decimals to string as
        python Decimal object cannot be encoded to JSON.
    """
    entity.markers = json.dumps([{"lat": str(m["lat"]), "lng": str(m["lng"])} for m in markers])

    table_service.insert_entity('maps', entity)

    """ Make a final key, consisting of partitionKey and rowKey suitable for use inside URL """
    finalId = partitionKey + "A" + rowKey
    return finalId
Exemple #18
0
    def test_batch_insert(self):
        # Arrange

        # Act
        entity = Entity()
        entity.PartitionKey = '001'
        entity.RowKey = 'batch_insert'
        entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty(EdmType.INT64, '1234567890')
        entity.test5 = datetime.utcnow()

        batch = TableBatch()
        batch.insert_entity(entity)
        resp = self.ts.commit_batch(self.table_name, batch)

        # Assert
        self.assertIsNotNone(resp)
        result = self.ts.get_entity(self.table_name, '001', 'batch_insert')
        self.assertEqual(resp[0], result.etag)
Exemple #19
0
def insert_entry_to_azure(table_service, rowKey, entry, table_name='test', partitionKey='default'):
    '''
    takes table service
    
    Takes a list 
    Uploads to azure table storage 
    '''
    segment = Entity()
    segment.PartitionKey = partitionKey
    segment.RowKey = str(rowKey).zfill(8)
    segment.latA = str(entry['latA'])
    segment.longA = str(entry['longA'])
    segment.latB = str(entry['latB'])
    segment.longB = str(entry['longB'])
    segment.colorKey = str(entry['color'])

    print segment
    table_service.insert_entity(table_name, segment)
Exemple #20
0
def insert_entry_to_azure(table_service,
                          rowKey,
                          entry,
                          table_name='test',
                          partitionKey='default'):
    '''
    takes table service
    
    Takes a list 
    Uploads to azure table storage 
    '''
    segment = Entity()
    segment.PartitionKey = partitionKey
    segment.RowKey = str(rowKey).zfill(8)
    segment.latA = str(entry['latA'])
    segment.longA = str(entry['longA'])
    segment.latB = str(entry['latB'])
    segment.longB = str(entry['longB'])
    segment.colorKey = str(entry['color'])

    print segment
    table_service.insert_entity(table_name, segment)
Exemple #21
0
    def writePropertyValue(self, entity: Entity):
        if self.propertyName in entity.keys():
            if self._needToWriteToBlob(entity[self.propertyName]):
                valueIdentifier = self.blobBackend.getValueReference(
                    entity["PartitionKey"],
                    entity["RowKey"],
                    self.propertyName,
                    blobNamePrefix=self.blobPrefix)
                value = entity[self.propertyName]
                self.blobBackend.setValueForReference(valueIdentifier, value)
                entity[self.propertyName] = valueIdentifier
                propertyBlobStatus = True if self.propertyBlobStatusName is not None else None
            else:
                propertyBlobStatus = False if self.propertyBlobStatusName is not None else None

            if propertyBlobStatus is not None:
                entity[self.propertyBlobStatusName] = propertyBlobStatus
Exemple #22
0
def addReferralToMainUser(id, referralLink):
    try:
        task = Entity()
        task.PartitionKey = 'referral_' + referralLink
        task.RowKey = "referral_" + str(id)
        task.userID = id
        task.referral = referralLink
        task.datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        task.version = 1
        table_service.insert_or_replace_entity('participantReferrer', task)

        #update participant
        item = table_service.get_entity('participants', 'participant', "participant_" + str(id))
        item.isConfirmed = True
        item.isCompleted = True
        item.invitedReferralLink = referralLink
        table_service.insert_or_replace_entity('participants', item)

    except Exception as e:
        logging.error(traceback.format_exc())
 def insert_or_replace_entity_to_azure(self, rowKey, entry, t_name=DEFAULT_TABLE):
     '''
     takes table service
     
     Takes a list 
     Uploads to azure table storage 
     '''
     segment = Entity()
     segment.PartitionKey = self.default_partition
     segment.RowKey = str(rowKey).zfill(8)
     segment.latA = str(entry['latA'])
     segment.longA = str(entry['longA'])
     segment.latB = str(entry['latB'])
     segment.longB = str(entry['longB'])
     segment.colorKey = str(entry['color'])
         
     #print segment.colorKey 
     
     if os.name == 'nt':
         self.table_service.insert_or_replace_entity(t_name, self.default_partition, str(rowKey).zfill(8), segment)
     else:
         self.table_service.insert_or_replace_entity(t_name, segment) 
Exemple #24
0
    def test_batch_inserts(self):
        # Arrange

        # Act
        entity = Entity()
        entity.PartitionKey = 'batch_inserts'
        entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty(EdmType.INT64, '1234567890')

        batch = TableBatch()
        for i in range(100):
            entity.RowKey = str(i)
            batch.insert_entity(entity)
        self.ts.commit_batch(self.table_name, batch)

        entities = list(
            self.ts.query_entities(self.table_name,
                                   "PartitionKey eq 'batch_inserts'", ''))

        # Assert
        self.assertIsNotNone(entities)
        self.assertEqual(100, len(entities))
    def test_batch_inserts(self):
        # Arrange

        # Act
        entity = Entity()
        entity.PartitionKey = 'batch_inserts'
        entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty(EdmType.INT64, '1234567890')

        batch = TableBatch()
        for i in range(100):
            entity.RowKey = str(i)
            batch.insert_entity(entity)
        self.ts.commit_batch(self.table_name, batch)

        entities = list(self.ts.query_entities(self.table_name, "PartitionKey eq 'batch_inserts'", ''))

        # Assert
        self.assertIsNotNone(entities)
        self.assertEqual(100, len(entities))
###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print(
    'Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.'
)
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'.
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '001'
pizza.description = 'Pepperoni'
pizza.cost = 18
table_service.insert_entity('itemstable', pizza)
print('Created entry for pepperoni...')

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '002'
pizza.description = 'Veggie'
pizza.cost = 15
table_service.insert_entity('itemstable', pizza)
print('Created entry for veggie...')
Exemple #27
0

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first car with  the make, model, year, color and price
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'Cardealership'
car.RowKey = '001'
car.make = 'Ford'
car.model = 'Explorer'
car.year = '2017'
car.color = 'Red'
car.price = 30000
table_service.insert_entity('itemstable', car)
print('Created entry for Ford Explorer...')

car = Entity()
car.PartitionKey = 'Cardealership'
car.RowKey = '002'
car.make = 'Toyota'
car.model = 'Sienna'
###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print(
    'Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.'
)
input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'.
# Here, we add five entries for cars with five pieces of data: 1) make, 2) model, 3) year, 4) color, 5) price
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

cars = Entity()
cars.PartitionKey = 'car_selections'
cars.RowKey = '001'
cars.make = 'Volkswagen'
cars.model = 'Jetta'
cars.year = 2010
cars.color = 'silver'
cars.price = 13300
table_service.insert_entity('htangitemstable', cars)
print('Created entry for Volkswagen/Jetta...')

cars = Entity()
cars.PartitionKey = 'car_selections'
cars.RowKey = '002'
cars.make = 'Ford'
cars.model = 'Focus'
Exemple #29
0

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '001'
pizza.description = 'Pepperoni'
pizza.cost = 18
table_service.insert_entity('itemstable', pizza)
print('Created entry for pepperoni...')

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '002'
pizza.description = 'Veggie'
pizza.cost = 15
table_service.insert_entity('itemstable', pizza)
print('Created entry for veggie...')
Exemple #30
0
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 09 16:47:26 2015

@author: justin.malinchak
"""

from azure.storage.table import TableService, Entity
table_service = TableService(account_name='portalvhdss5m831rhl98hj', account_key='Z1MliCYE7p9Ks9kYQoGeM4V99hODtiJL82BVi/zIm06jLYh7n0tV8YaZHzITKixMwUUmjJ1Vp05XrgHG+gXFlg==')


table_service.create_table('tasktable')
task = {'PartitionKey': 'tasksSeattle', 'RowKey': '1', 'description' : 'Take out the trash', 'priority' : 200}
table_service.insert_entity('tasktable', task)

task = Entity()
task.PartitionKey = 'tasksSeattle'
task.RowKey = '2'
task.description = 'Wash the car'
task.priority = 100
table_service.insert_entity('tasktable', task)
#
task = {'description' : 'Take out the garbage', 'priority' : 250}
table_service.update_entity('tasktable', 'tasksSeattle', '1', task)
#
task = {'description' : 'Take out the garbage again', 'priority' : 250}
table_service.insert_or_replace_entity('tasktable', 'tasksSeattle', '1', task)

task = {'description' : 'Buy detergent', 'priority' : 300}
table_service.insert_or_replace_entity('tasktable', 'tasksSeattle', '3', task)
###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print(
    'Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.'
)
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'.
# Here, we add an entry for first car with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'carcatalog'
car.RowKey = '001'
car.make = 'Chevrolet'
car.model = 'Blazer'
car.year = 2000
car.color = 'Black'
car.price = 24000
table_service.insert_entity('itemstable', car)
print('Created entry for Chevy Blazer ...')

car = Entity()
car.PartitionKey = 'carcatalog'
car.RowKey = '002'
car.make = 'Ford'
car.model = 'Explorer'
    def test_batch_reuse(self):
        # Arrange

        table2 = self._get_table_reference('table2')
        self.ts.create_table(table2)

         # Act
        entity = Entity()
        entity.PartitionKey = '003'
        entity.RowKey = 'batch_all_operations_together-1'
        entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty(EdmType.INT64, '1234567890')
        entity.test5 = datetime.utcnow()

        batch = TableBatch()
        batch.insert_entity(entity)
        entity.RowKey = 'batch_all_operations_together-2'
        batch.insert_entity(entity)
        entity.RowKey = 'batch_all_operations_together-3'
        batch.insert_entity(entity)
        entity.RowKey = 'batch_all_operations_together-4'
        batch.insert_entity(entity)

        self.ts.commit_batch(self.table_name, batch)
        self.ts.commit_batch(table2, batch)

        batch = TableBatch()
        entity.RowKey = 'batch_all_operations_together'
        batch.insert_entity(entity)
        entity.RowKey = 'batch_all_operations_together-1'
        batch.delete_entity(entity.PartitionKey, entity.RowKey)
        entity.RowKey = 'batch_all_operations_together-2'
        entity.test3 = 10
        batch.update_entity(entity)
        entity.RowKey = 'batch_all_operations_together-3'
        entity.test3 = 100
        batch.merge_entity(entity)
        entity.RowKey = 'batch_all_operations_together-4'
        entity.test3 = 10
        batch.insert_or_replace_entity(entity)
        entity.RowKey = 'batch_all_operations_together-5'
        batch.insert_or_merge_entity(entity)

        self.ts.commit_batch(self.table_name, batch)
        resp = self.ts.commit_batch(table2, batch)

        # Assert
        self.assertEqual(6, len(resp))
        entities = list(self.ts.query_entities(self.table_name, "PartitionKey eq '003'", ''))
        self.assertEqual(5, len(entities))
    def test_batch_all_operations_together_context_manager(self):
        # Arrange

         # Act
        entity = Entity()
        entity.PartitionKey = '003'
        entity.RowKey = 'batch_all_operations_together-1'
        entity.test = EntityProperty(EdmType.BOOLEAN, 'true')
        entity.test2 = 'value'
        entity.test3 = 3
        entity.test4 = EntityProperty(EdmType.INT64, '1234567890')
        entity.test5 = datetime.utcnow()
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-2'
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-3'
        self.ts.insert_entity(self.table_name, entity)
        entity.RowKey = 'batch_all_operations_together-4'
        self.ts.insert_entity(self.table_name, entity)

        with self.ts.batch(self.table_name) as batch:
            entity.RowKey = 'batch_all_operations_together'
            batch.insert_entity(entity)
            entity.RowKey = 'batch_all_operations_together-1'
            batch.delete_entity(entity.PartitionKey, entity.RowKey)
            entity.RowKey = 'batch_all_operations_together-2'
            entity.test3 = 10
            batch.update_entity(entity)
            entity.RowKey = 'batch_all_operations_together-3'
            entity.test3 = 100
            batch.merge_entity(entity)
            entity.RowKey = 'batch_all_operations_together-4'
            entity.test3 = 10
            batch.insert_or_replace_entity(entity)
            entity.RowKey = 'batch_all_operations_together-5'
            batch.insert_or_merge_entity(entity)

        # Assert
        entities = list(self.ts.query_entities(self.table_name, "PartitionKey eq '003'", ''))
        self.assertEqual(5, len(entities))
Exemple #34
0
def save_image(img: Image, crs, lat, long, height, stats, ptime):
    table_service = TableService(account_name=_LOGS_ACCOUNT_NAME,
                                 account_key=_LOGS_ACCOUNT_KEY)
    task = Entity()
    task.PartitionKey = img.instrument.NAME
    task.RowKey = img.observation_set
    task.processing_time = ptime
    task.cr_count = len(crs)
    task.latitude = str(lat)
    task.longitude = str(long)
    task.height = str(height)
    task.image_type = img.file_type
    task.observation_date = str(img.observation_date)
    task.observation_start_time = str(img.observation_start_time)
    task.equinox = str(img.equinox)
    task.exposition_duration = str(img.exposition_duration)
    task.gain = str(img.gain)
    task.proposal_id = str(img.proposal_id)
    task.position_angle = str(img.position_angle)
    task.right_ascension = str(img.right_ascension)
    task.right_ascension_target = str(img.right_ascension_target)
    task.declination = str(img.declination)
    task.declination_target = str(img.declination_target)

    if img.aperture is not None:
        task.aperture = str(img.aperture)
        task.ecliptic_lon = str(img.ecliptic_lon)
        task.ecliptic_lat = str(img.ecliptic_lat)
        task.galactic_lon = str(img.galactic_lon)
        task.galactic_lat = str(img.galactic_lat)

    task.moon_angle = str(img.moon_angle)
    task.sun_angle = str(img.sun_angle)
    task.sun_altitude = str(img.sun_altitude)
    task.wcs_axes = img.wcs_axes

    for idx in range(1, img.wcs_axes + 1):
        task['wcs_crpix_%d' % idx] = str(img.wcs_crpix(idx))
        task['wcs_crval_%d' % idx] = str(img.wcs_crval(idx))
        task['wcs_ctype_%d' % idx] = str(img.wcs_ctype(idx))
        for part in [1, 2]:
            task['wcs_cd_%d_%d' % (idx, part)] = str(img.wcs_cd(idx, part))
        task['wcs_ltv_%d' % idx] = str(img.wcs_ltv(idx))
        task['wcs_ltm_%d' % idx] = str(img.wcs_ltm(idx))

    task.wcs_pa_aper = str(img.wcs_pa_aper)
    task.wcs_va_factor = str(img.wcs_va_factor)
    task.wcs_orientation = str(img.wcs_orientation)
    task.wcs_ra_aperture = str(img.wcs_ra_aperture)
    task.wcs_dec_aperture = str(img.wcs_dec_aperture)

    # Add stats
    for key, value in stats.items():
        task['stat_%s' % key] = str(value)

    table_service.insert_or_replace_entity('imagestable', task)
    # for chunk in chunks(crs, 100):
    #    batch = TableBatch()
    if __SAVE_CR_SEPARATELY_:
        logging.info('Done inserting image at {} '.format(datetime.datetime.now().replace(microsecond=0)))
        logging.info('Started cr individual inserts')
        for cr in crs:
            cr_task = {'PartitionKey': img.observation_set, 'RowKey': cr.label}

            for prop in cr:
                cr_task[prop] = str(cr[prop])

            table_service.insert_or_replace_entity(cr_task)
Exemple #35
0

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first car with following pieces of data - make, model, year, color and price.
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'carmenu'
car.RowKey = '001'
car.make = 'Ford'
car.model = 'Taurus'
car.year = 1994
car.color = 'White'
car.price = 5000
table_service.insert_entity('itemstable', car)
print('Created entry for Ford Taurus...')
time.sleep(1)

#add an entry for coffee with following pieces of data - brand, flavor, size and price
coffee = Entity()
coffee.PartitionKey = 'coffeemenu'
coffee.RowKey = '1001'
###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print(
    'Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.'
)
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'.
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '001'
pizza.description = 'Pepperoni'
pizza.cost = 18
table_service.insert_entity('itemstable', pizza)
print('Created entry for pepperoni...')

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '002'
pizza.description = 'Veggie'
pizza.cost = 15
table_service.insert_entity('itemstable', pizza)
print('Created entry for veggie...')
Exemple #37
0
# pizza.description = 'Veggie'
# pizza.cost = 15
# table_service.insert_entity('itemstable', pizza)
# print('Created entry for veggie...')

# pizza = Entity()
# pizza.PartitionKey = 'pizzamenu'
# pizza.RowKey = '003'
# pizza.description = 'Hawaiian'
# pizza.cost = 12
# table_service.insert_entity('itemstable', pizza)
# print('Created entry for Hawaiian...\n')

# Shailesh Beri - Add code here to populate partition with cars using dealership scenario and with characteristics [make, model, year, color and price] instead of Pizza

cars = Entity()
cars.PartitionKey = 'carstype'
cars.RowKey = '001'
cars.make = 'BMW'
cars.model = 'X3'
cars.year = 2017
cars.color = 'Red'
cars.price = 51000
table_service.insert_entity('itemstable', cars)
print('Created entry for BMW X3...')

cars = Entity()
cars.PartitionKey = 'carstype'
cars.RowKey = '002'
cars.make = 'Audi'
cars.model = 'Q5'
Exemple #38
0
def insert_or_replace_entity_from_pi_azure_raw_accel(table_service, rowKey, entry, table_name='test', partitionKey='default'):
    '''
    takes table service
    
    Takes a list 
    Uploads to azure table storage 
    '''
    segment = Entity()
    segment.PartitionKey = partitionKey
    segment.RowKey = str(rowKey).zfill(8)
    segment.latA = str(entry['latA'])
    segment.longA = str(entry['longA'])
    segment.latB = str(entry['latB'])
    segment.longB = str(entry['longB'])
    segment.colorKey = str(entry['color'])
    if entry['x']:
        segment.x = str(entry['x'])
        segment.y = str(entry['y'])
        segment.z = str(entry['z'])
        
    print segment
    table_service.insert_or_replace_entity(table_name, segment) 

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '001'
pizza.description = 'Pepperoni'
pizza.cost = 18
table_service.insert_entity('itemstable', pizza)
print('Created entry for pepperoni...')

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '002'
pizza.description = 'Veggie'
pizza.cost = 15
table_service.insert_entity('itemstable', pizza)
print('Created entry for veggie...')
response = table_service.create_table('itemstable')
if response == True:
print('Storage Table: itemstable created successfully.\n')
else:
print('Error creating Storage Table.\n')
time.sleep(1)
## Use the Azure Storage Storage SDK for Python to create some entries in the Table
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore.’)
print(‘ This is similar to adding records to a database.')
raw_input('Press Enter to continue...')
# Each entry in a Table is called an 'Entity'.
# Here, we add an entry for first cars with data - the name, and the cost
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.
cars = Entity()
cars.PartitionKey = 'carsmenu'
cars.RowKey = '001'
cars.make = 'Tayota'
cars.model = 'Camrey'
cars.year = '2016'
cars.color = 'Blue'
cars.price = 18000
table_service.insert_entity('itemstable', cars)
print('Created entry for camrey...')
cars = Entity()
cars.PartitionKey = 'carsmenu'
cars.RowKey = '002'
cars.make = 'Tayota'
cars.model = 'Carolla'
cars.year = '2017'
Exemple #41
0

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'carinfo'
car.RowKey = '001'
car.make = 'Honda'
car.model = 'Odyssey'
car.year='2017'
car.color='blue'
car.price = '$20,000'
table_service.insert_entity('itemstable', car)
print('Created entry for Honda Odyssey')

car = Entity()
car.PartitionKey = 'carinfo'
car.RowKey = '002'
car.make = 'Toyota'
car.model = 'Corolla'
###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print(
    'Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.'
)
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'.
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '001'
pizza.description = 'Pepperoni'
pizza.cost = 18
table_service.insert_entity('itemstable', pizza)
print('Created entry for pepperoni...')

pizza = Entity()
pizza.PartitionKey = 'pizzamenu'
pizza.RowKey = '002'
pizza.description = 'Veggie'
pizza.cost = 15
table_service.insert_entity('itemstable', pizza)
print('Created entry for veggie...')
###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print(
    'Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.'
)
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'.
# Here, we add an entry for first pizza with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'Cargallery'
car.RowKey = '001'
car.make = 'Jeep'
car.model = 'Wrangler JK Altitude'
car.year = '2018'
car.color = 'White'
car.price = 38190.00
table_service.insert_entity('itemstable', car)
print('Created entry for Jeep...')

car = Entity()
car.PartitionKey = 'Cargallery'
car.RowKey = '002'
car.make = 'Toyota'
car.model = 'Highlander'
    def create_entity_class(self):
        '''
        Creates a class-based entity with fixed values, using all of the supported data types.
        '''
        entity = Entity()

        # Partition key and row key must be strings and are required
        entity.PartitionKey= 'pk{}'.format(str(uuid.uuid4()).replace('-', ''))
        entity.RowKey = 'rk{}'.format(str(uuid.uuid4()).replace('-', '')) 

        # Some basic types are inferred
        entity.age = 39 # EdmType.INT64
        entity.large = 933311100 # EdmType.INT64
        entity.sex = 'male' # EdmType.STRING
        entity.married = True # EdmType.BOOLEAN
        entity.ratio = 3.1 # EdmType.DOUBLE
        entity.birthday = datetime(1970, 10, 4) # EdmType.DATETIME

        # Binary, Int32 and GUID must be explicitly typed
        entity.binary = EntityProperty(EdmType.BINARY, b'xyz')
        entity.other = EntityProperty(EdmType.INT32, 20)
        entity.clsid = EntityProperty(EdmType.GUID, 'c9da6455-213d-42c9-9a79-3e9149a57833')
        return entity
Exemple #45
0

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first car with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'carmenu'
car.RowKey = '001'
car.make = 'Peugot'
car.year = 1989
car.color = 'white'
car.price = 18000
car.model = 'TR7'
table_service.insert_entity('itemstable', car)
print('Created entry for Peugot...')

car = Entity()
car.PartitionKey = 'carmenu'
car.RowKey = '002'
car.make = 'Cadillac'
car.year = 1990
 def _create_random_entity_class(self, pk=None, rk=None):
     '''
     Creates a class-based entity with fixed values, using all
     of the supported data types.
     '''
     partition = pk if pk is not None else self.get_resource_name('pk')
     row = rk if rk is not None else self.get_resource_name('rk')
     entity = Entity()
     entity.PartitionKey = partition
     entity.RowKey = row
     entity.age = 39
     entity.sex = 'male'
     entity.name = 'John Doe'
     entity.married = True
     entity.deceased = False
     entity.optional = None
     entity.evenratio = 3.0
     entity.ratio = 3.1
     entity.large = 933311100
     entity.Birthday = datetime(1973, 10, 4)
     entity.birthday = datetime(1970, 10, 4)
     entity.binary = EntityProperty(EdmType.BINARY, b'binary')
     entity.other = EntityProperty(EdmType.INT32, 20)
     entity.clsid = EntityProperty(
         EdmType.GUID, 'c9da6455-213d-42c9-9a79-3e9149a57833')
     return entity
Exemple #47
0

###
# Use the Azure Storage Storage SDK for Python to create some entries in the Table
###
print('Now let\'s add some entries to our Table.\nRemember, Azure Storage Tables is a NoSQL datastore, so this is similar to adding records to a database.')
raw_input('Press Enter to continue...')

# Each entry in a Table is called an 'Entity'. 
# Here, we add an entry for first car with two pieces of data - the name, and the cost
#
# A partition key tracks how like-minded entries in the Table are created and queried.
# A row key is a unique ID for each entity in the partition
# These two properties are used as a primary key to index the Table. This makes queries much quicker.

car = Entity()
car.PartitionKey = 'cars'
car.RowKey = '001'
car.make = 'Ford'
car.model = 'Edge'
car.year = '2007'
car.color = 'Gray'
car.price = 32000
table_service.insert_entity('itemstable', car)
print('Created entry for 2007 Ford Edge...')

car = Entity()
car.PartitionKey = 'cars'
car.RowKey = '002'
car.make = 'GMC'
car.model = 'Acadia'
Exemple #48
0
def addNewParticipant(id, address, ownReferralLink, isConfirmed, isCompleted = False, invitedReferral = ''):
    try:
        task = Entity()
        task.PartitionKey = 'participant'
        task.RowKey = "participant_" + str(id)
        task.userID = id
        task.ethereumAddress = address
        task.referral = ownReferralLink
        task.invitedReferralLink = invitedReferral
        task.isConfirmed = isConfirmed
        task.isCompleted = isCompleted
        task.datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        task.version = 1
        table_service.insert_or_replace_entity('participants', task)
    except Exception as e:
        logging.error(traceback.format_exc())