Exemplo n.º 1
0
                        '_timestamp': 'evt_timestamp',
                        '_db_schema': db_schema
                    })
'''
When creating an EntityType object you will need to specify the name of the entity, the database
object that will contain entity data

After creating an EntityType you will need to register it so that it visible in the UI.
'''
entity.register()
'''
Entities can get pretty lonely without data. You can feed your entity data by
writing directly to the entity table or you can cheat and generate data.

'''
entity.generate_data(days=0.5, drop_existing=True)
df = db.read_table(table_name=entity_name, schema=db_schema)
df.head()
'''
To retrieve the model when the predictions function will execute, 
we are storing the model in a object storage bucket.
In a production environment, the model will be trained and stored on object storage using a different approach.
This sample is considering a model already trained and serialized.
'''
#model file is loaded in memory
rel_path = 'models/base_model_LSTM64_LSTM32_Dropout0.375240min_new'  #relative path for the model
script_dir = os.path.dirname(__file__)  #absolute dir the script is in
abs_file_path = os.path.join(script_dir, rel_path)
model_file = open(abs_file_path, 'rb')

#create bucket on COS to store the model
Exemplo n.º 2
0
'''

entity_name = 'sim_test'  # you can give your entity type a better nane
db = Database(credentials=credentials)
db_schema = None  # set if you are not using the default\
entity = EntityType(entity_name, db, Column('temp', Float()), Column('pressure', Float()),
                    Column('company_code', String(50)), Column('category_code', String(5)),
                    **{'_timestamp': 'evt_timestamp', '_db_schema': db_schema})
entity.register(raise_error=True)

'''
To build historical data, you can use the entity's "generate_data" method.
'''

entity.generate_data(days=0.5, drop_existing=True)

'''
To see the data you just loaded, ask the db object to read the database
table and produce a pandas dataframe.
'''
df = db.read_table(table_name=entity_name, schema=db_schema)
print(df.head())

'''
You should see a new database table - named the same way as your entity. This table
will be loaded with a half day's worth of data.

The numeric columns like 'temp' and 'pressure' will have timeseries data with a mean
of 0. Data will be generated with 5 devices.