def setUpClass(cls):
     """
     Create entity and entity group.
     """
     super().setUpClass()
     entity = Entity(ENTITY)
     cls._entity_service = EntitiesService(cls.connection)
     cls._entity_service.create_or_replace(entity)
     time.sleep(cls.wait_time)
 def setUp(self):
     """
     Create entity.
     """
     entity = Entity(NAME,
                     label=LABEL,
                     interpolate=INTERPOLATE,
                     time_zone=TIME_ZONE,
                     tags=TAGS)
     self.service.create_or_replace(entity)
     time.sleep(self.wait_time)
 def test_fields_match(self):
     """
     Check fields of Entity model were set as expected.
     """
     LAST_INSERT_DATE = datetime.now()
     CREATED_DATE = LAST_INSERT_DATE
     e = Entity(NAME, ENABLED, LABEL, INTERPOLATE, TIME_ZONE,
                LAST_INSERT_DATE, TAGS, CREATED_DATE)
     self.assertEqual(TAGS, e.tags)
     self.assertEqual(LABEL, e.label)
     self.common_checks(e)
    def test_replace(self):
        """
        Check tags delete.
        """
        entity = Entity(name=NAME)
        self.service.create_or_replace(entity)

        time.sleep(self.wait_time)

        e = self.service.get(NAME)
        # print(e)
        self.assertIsNotNone(e)
        self.assertIsInstance(e, Entity)
        self.assertEqual(NAME, e.name)
        self.assertTrue(e.enabled)
        self.assertDictEqual({}, e.tags)
    def test_update(self):
        label = "new_label"
        tag_value = "new_tag_value"
        tags = TAGS.copy()
        tags[TAG] = tag_value
        entity = Entity(name=NAME, label=label, tags=tags)
        self.service.update(entity)

        time.sleep(self.wait_time)

        e = self.service.get(NAME)
        # print(e)
        self.assertIsNotNone(e)
        self.assertIsInstance(e, Entity)
        self.assertEqual(tag_value, e.tags[TAG])
        self.assertEqual(label, entity.label)
        self.common_checks(e)
示例#6
0
series = []
metric_and_labels = {JACKET_TEMPERATURE: [], PRODUCT_TEMPERATURE: [], AGITATOR_SPEED: []}

total_asset_duration = {}
commands = []

# prepare entities meta
assets = []
for i in range(ASSET_COUNT):
    site = rand_int(SITE_COUNT)
    site_value = sites[site]
    building_value = buildings[site][rand_int(BUILDING_PER_SITE_COUNT)]
    entity_name = '%s-%s' % (ENTITY_PREFIX, i)

    assets.append({'id': entity_name, 'site': site_value, 'building': building_value})
    entity = Entity(entity_name, tags={'site': site_value, 'building': building_value})

    if SAVE_AS_COMMANDS:
        commands.append('entity e:%s t:site=%s t:building=%s' % (entity_name, site_value, building_value))
    else:
        entities_service.create_or_replace(entity)

# prepare splines
for asset in assets:
    proc = 0
    t = START_TIME
    entity_name = asset['id']

    dataSplines = SplineHolder()
    data_command_splines.append([asset, dataSplines])
示例#7
0
fields_dict = {'asset_name': 'label', 'asset_path': 'name'}
time_zone_dict = {'USRI': 'EDT', 'PRJU': 'PRT'}
time_zone_field = 'site_is_code'

for index, row in df.where(pd.notnull(df), None).iterrows():
    row_dict = row.to_dict()
    fields_columns = {
        k: v
        for k, v in row_dict.iteritems()
        if k in fields_dict and row_dict[k] is not None
    }

    entity_params = dict(
        map(lambda kv: (fields_dict[kv[0]], kv[1]),
            fields_columns.iteritems()))

    if time_zone_field in row_dict and row_dict[
            time_zone_field] in time_zone_dict:
        site_code = row_dict[time_zone_field]
        entity_params['time_zone'] = time_zone_dict[site_code]

    entity_params['tags'] = dict({
        k: v
        for k, v in row_dict.iteritems()
        if k not in fields_dict and row_dict[k] is not None
    })
    entity = Entity(**entity_params)
    print(entity)
    # entities_service.create_or_replace(entity)
示例#8
0
]

assets = []
for i in range(ASSET_COUNT):
    site = rand_int(SITE_COUNT)
    building = rand_int(BUILDING_PER_SITE_COUNT)
    assets.append({
        'id': 'axi.asset-%s' % i,
        'site': sites[site],
        'building': buildings[site][building]
    })

for asset in assets:
    entity = Entity(asset['id'],
                    tags={
                        'site': asset['site'],
                        'building': asset['building']
                    })
    entities_service.create_or_replace(entity)

batch_id = 1400
dataCommandSplines = []
series = []

for asset in assets:
    proc = 0
    t = next_time(None, MIN_TIME)

    dataSplines = SplineHolder()
    dataCommandSplines.append([asset, dataSplines])