Skip to content

Commit

Permalink
Update database setup file. Delete unecessary devices and experiments…
Browse files Browse the repository at this point in the history
…. Fix minor format error in scripts.

Signed-off-by: Lukas Bromig <lukas.bromig@tum.de>
  • Loading branch information
Lbromig committed Mar 30, 2021
1 parent 1cfba44 commit 9788983
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 38 deletions.
3 changes: 2 additions & 1 deletion examples/Tutorial_2_Incorporating_SiLA_Services.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ def run(services):
response = client.call_property("SiLAService\n", "ServerName")
print(f'{i}. call:', response, flush=True)
time.sleep(1.5)
OldServerName = response

# A Set command. A call to the SiLAService feature. Change the server name.
client.call_command("SiLAService\n","SetServerName", parameters={"ServerName/constrained/String": "MyNewName"})
response = client.call_property("SiLAService\n", "ServerName")
print('Changed name to: ', response['servername/constrained/string'], flush=True)
# Change the ServerName back to the original one
client.call_command("SiLAService\n","SetServerName", parameters={
"ServerName/constrained/String": ServerName['servername/constrained/string']})
"ServerName/constrained/String": OldServerName['servername/constrained/string']})
response = client.call_property("SiLAService\n", "ServerName")
print('Changed name back to:', response['servername/constrained/string'], flush=True)
152 changes: 115 additions & 37 deletions setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,10 @@
devices = [{
'uuid': uuid4(),
'server_uuid': uuid4(),
'name': "Dummy Device 1",
'name': "SiLA_Python_Test",
'type': DeviceType.SILA,
'address': "192.168.0.20",
'port': 50001,
'available': True,
'user': None
}, {
'uuid': uuid4(),
'server_uuid': uuid4(),
'name': "Dummy Device 2",
'type': DeviceType.CUSTOM,
'address': "192.168.0.25",
'port': 55001,
'available': False,
'user': 1
}, {
'uuid': uuid4(),
'server_uuid': uuid4(),
'name': "Dummy Device 3",
'type': DeviceType.SILA,
'address': "192.168.0.40",
'port': 50002,
'address': "127.0.0.1",
'port': 50051,
'available': True,
'user': None
}]
Expand Down Expand Up @@ -392,7 +374,24 @@

booking_info = [{
'name':
'experiment1',
'Tutorial_1',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'end':
int(
datetime.strptime('20-09-2020 09:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'user':
1,
'device': None,
'experiment':
1
},
{
'name':
'Tutorial_2',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
Expand All @@ -406,12 +405,46 @@
'device':
devices[0]['uuid'],
'experiment':
1
2
},
{
'name':
'Tutorial_3',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'end':
int(
datetime.strptime('20-09-2020 09:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'user':
1,
'device': None,
'experiment':
3
},
{
'name':
'Tutorial_4',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'end':
int(
datetime.strptime('20-09-2020 09:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'user':
1,
'device': None,
'experiment':
4
}]

experiments = [{
'name':
'Experiment 1',
'Tutorial_1',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
Expand All @@ -424,6 +457,54 @@
1,
'script':
1
},
{
'name':
'Tutorial_2',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'end':
int(
datetime.strptime('20-09-2020 09:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'user':
1,
'script':
2
},
{
'name':
'Tutorial_3',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'end':
int(
datetime.strptime('20-09-2020 09:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'user':
1,
'script':
3
},
{
'name':
'Tutorial_4',
'start':
int(
datetime.strptime('19-09-2020 08:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'end':
int(
datetime.strptime('20-09-2020 09:54:22',
'%d-%m-%Y %H:%M:%S').timestamp()),
'user':
1,
'script':
4
}]

scripts = [
Expand Down Expand Up @@ -522,7 +603,6 @@
'\ttime.sleep(1) \n'
"\tsys.stdout.write('All Good\\n') \n"
'\tsys.stdout.flush() \n'
'\n'
},
{
'name': 'Tutorial 2 Incorporating SiLA 2 Services',
Expand Down Expand Up @@ -565,17 +645,17 @@
'\t\tresponse = client.call_property("SiLAService\\n", "ServerName") \n'
'\t\tprint(response, flush=True) \n'
'\t\ttime.sleep(2)\n'
'\tOldServerName=response \n'
'\t\n'
'\t# A Set command. A call to the SiLAService feature. Change the server name. \n'
'\tclient.call_command("SiLAService\\n","SetServerName", parameters={"ServerName/constrained/String": "MyNewName"}) \n'
'\tresponse = client.call_property("SiLAService\\n", "ServerName") \n'
"\tprint('Changed name to: ', response['servername/constrained/string'], flush=True) \n"
'\t# Change the ServerName back to the original one \n'
'\tclient.call_command("SiLAService\\n","SetServerName", parameters={"ServerName/constrained/String": ServerName["servername/constrained/string"]}) \n'
'\tclient.call_command("SiLAService\\n","SetServerName", parameters={"ServerName/constrained/String": OldServerName["servername/constrained/string"]}) \n'
'\t# Change the ServerName back to the original one\n'
'\tresponse = client.call_property("SiLAService\\n", "ServerName") \n'
"\tprint('Changed name back to:', response['servername/constrained/string'], flush=True) \n"
'\n'
},
{
'name': 'Tutorial 3 Using The Data Handler',
Expand Down Expand Up @@ -613,7 +693,6 @@
'def run(services): \n'
'\t""" Required to import and instantiate devices """ \n'
'\treturn \n'
'\n'
},
{
'name': 'Tutorial 4 Incorporating Databases',
Expand All @@ -640,7 +719,7 @@
"\tprint(f'Checking connectivity. DB server version: {influx_client.ping()}', flush=True) \n"
'\n'
'\t""" \n'
'4.3 If you do not already have a database, creat a new one: \n'
'\t4.3 If you do not already have a database, creat a new one: \n'
'\t""" \n'
'\n'
"\tinflux_client.create_database(dbname='SiLA_2_Manager') \n"
Expand All @@ -659,12 +738,12 @@
'\t\t\t"tags": { \n'
'\t\t\t\t"experiment_name": "influxDB_test", \n'
'\t\t\t\t"device": "experiment_docker_container" \n'
'\t\t\t\t}, \n'
'\t\t\t}, \n'
'\t\t\t"time": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"), \n'
'\t\t\t"fields": { \n'
'\t\t\t\t"test_number": random_number \n'
'\t\t\t\t} \n'
'\t\t\t} \n'
'\t\t} \n'
'\n'
'\t\ttry: \n'
'\t\t\tinflux_client.write_points([data_point]) \n'
Expand All @@ -674,8 +753,8 @@
'\n'
'\t\t""" \n'
'\t\t4.5 Query your data using the SQL-like Influx Query Language (InfluxQL). You can find information on the syntax at: \n'
'\t\thttps://docs.influxdata.com/influxdb/v1.8/query_language/ . The following query will read the value that was \n'
'\t\tjust written to the database. \n'
'\t\t\thttps://docs.influxdata.com/influxdb/v1.8/query_language/ . The following query will read the value that was \n'
'\t\t\tjust written to the database. \n'
'\n'
'\t\tHint 4: Copy and paste the query below to visualize the data in chronograf. Change the LIMIT to display the \n'
'\t\t\tnumber of last data points. Remove the escape character (backslash) around the influxDB_test in the query. \n'
Expand All @@ -685,11 +764,10 @@
'\n'
'\t\t# This is an example query. \n'
'\t\tresults = influx_client.query( \n'
"\t\t\t'SELECT test_number FROM SiLA_2_Manager.autogen.testMeasurement WHERE experiment_name = \'influxDB_test\' GROUP BY position ORDER BY DESC LIMIT 1') \n"
"\t\t\t'SELECT test_number FROM SiLA_2_Manager.autogen.testMeasurement WHERE experiment_name = \\'influxDB_test\\' GROUP BY position ORDER BY DESC LIMIT 1') \n"
"\t\tprint('The latest random number was queried from the database: ', flush=True) \n"
'\t\tprint(results, flush=True) \n'
'\t\ttime.sleep(5) \n'
'\n'
}
]

Expand Down Expand Up @@ -926,9 +1004,9 @@ def main():
add_defined_execution_errors(c)
add_databases(c)
add_logs(c)
add_booking_info(c)
add_experiments(c)
add_scripts(c)
add_experiments(c)
add_booking_info(c)
conn.commit()
conn.close()

Expand Down

0 comments on commit 9788983

Please sign in to comment.