示例#1
0
def basic_analysis(params):
    import mdml_client as mdml
    # Connect to the MDML to query for data
    exp = mdml.experiment(params['experiment_id'], params['user'],
                          params['pass'], params['host'])
    # Grabbing the latest temperature value
    query = [{"device": "DATA1", "variables": ["temperature"], "last": 1}]
    res = exp.query(query, verify_cert=False)  # Running the query
    tempF = res['DATA1'][0]['temperature']
    tempC = (tempF - 32) * (5 / 9)
    return {'time': mdml.unix_time(True), 'tempC': tempC}
    # Generating data
    if IMAGES:
        random_image = np.random.randint(255, size=num_points, dtype=np.uint8)
        _, img = cv2.imencode('.jpg', random_image)
        img_bytes = img.tobytes()
        img_b64bytes = b64encode(img_bytes)
        img_byte_string = img_b64bytes.decode('utf-8')
    else:
        dat = '\t'.join(random_data(num_points))

    try:
        while i < NUM_MESSAGES:
            if IMAGES:
                My_MDML_Exp.publish_image(device, img_byte_string,
                                          'random_image_' + str(i) + '.JPG',
                                          mdml.unix_time())
                print(THROUGHPUT)
                if not THROUGHPUT:
                    time.sleep(DELAYS[j])
            else:
                # Generating data
                My_MDML_Exp.publish_data(device,
                                         dat,
                                         "\t",
                                         timestamp=mdml.unix_time())
                if not THROUGHPUT:
                    time.sleep(DELAYS[j])
            i += 1
    except KeyboardInterrupt:
        print("Ending MDML experiment early")
    finally:
示例#3
0
# Sleep to let MDML ingest the configuration
time.sleep(2)

reset = False

import os

try:
    i = 0
    while True:
        while i < 100000000:
            # Generating random images
            img_byte_string = b64encode(
                np.random.bytes(3750000)).decode('utf-8')
            My_MDML_Exp._publish_image_benchmarks(
                'IMAGE', img_byte_string, 'random_image_' + str(i) + '.JPG',
                mdml.unix_time(), '10MB')
            print(i)
            i += 1
        if not reset:
            print("Ending MDML experiment")
            My_MDML_Exp.reset()
            reset = True
except KeyboardInterrupt:
    if not reset:
        My_MDML_Exp.reset()
    My_MDML_Exp.stop_debugger()
finally:
    My_MDML_Exp.disconnect()
示例#4
0
parser.add_argument("--host", help="MDML instance host", required=True)
parser.add_argument("--username", help="MDML username", required=True)
parser.add_argument("--password", help="MDML password", required=True)
args = parser.parse_args()

import time
import mdml_client as mdml

#exp = mdml.experiment("TEST", "test", "testtest", "merf.egs.anl.gov")
print(f"Host is {args.host}")
exp = mdml.experiment("TEST", args.username, args.password, args.host)
exp.add_config(auto=True)
exp.send_config()
time.sleep(1)

curr_time = mdml.unix_time(True)  # True for integer return instead of string
print(curr_time)

# Data type of dict required for the first .publish_data call when using auto configurations.
data = {
    'time': mdml.unix_time(True),
    'temperature': 56,
    'humidity': 58,
    'note': 'Temperature and humidity values'
}
exp.publish_data(device_id="DATA1",
                 data=data,
                 timestamp=curr_time + 2,
                 add_device=True)

time.sleep(3)
示例#5
0
    funcx_func_uuid = "1712a2fc-cc40-4b2c-ae44-405d58f78c5d"  # Sept 16th 2020

# Now that the function is ready for use, we need to start an experiment to use it with
import sys
import time
sys.path.insert(1, '../')  # using local mdml_client
import mdml_client as mdml

exp = mdml.experiment("TEST", args.username, args.password, args.host)
exp.add_config(auto=True)
exp.send_config()
time.sleep(1)

# Send some data to analyze
data = {
    'time': mdml.unix_time(True),
    'temperature': 212,
    'humidity': 58,
    'note': 'Temperature and humidity values'
}
exp.publish_data(device_id="DATA1", data=data, add_device=True)

# Now, run the analysis
# Define function parameters
params = {
    'experiment_id': 'TEST',
    'user': args.username,
    'pass': args.password,
    'host': args.host
    # Other function specific params here.
}
示例#6
0
import sys # using local mdml_client
sys.path.insert(1, '../')

import mdml_client as mdml
import time
exp = mdml.experiment("TEST", "test", "testtest", "merfpoc.egs.anl.gov")
exp.add_config('dev_config.json')
exp.send_config()
time.sleep(1)

curr_time = mdml.unix_time(True) # True for integer return instead of string
print(curr_time)

# Data type of dict required for the first .publish_data call when using auto configurations. 
data = [
    [300, 400, 500, 600],
    [1200, 1500, 2100, 1750]
]
exp.publish_vector_data(device_id = "SMPS_VECTOR", data = data, timestamp = curr_time+2)

try:
    while True:
        time.sleep(10)
except KeyboardInterrupt:
    print("Quitting")
finally:
    exp.reset()
    time.sleep(1)
    exp.disconnect()
示例#7
0
try:
    i = 1
    while True:
        while i < 300:
            # Generating random images
            random_image = np.random.randint(255,
                                             size=(400, 500, 3),
                                             dtype=np.uint8)
            _, img = cv2.imencode('.jpg', random_image)
            img_bytes = img.tobytes()
            img_b64bytes = b64encode(img_bytes)
            img_byte_string = img_b64bytes.decode('utf-8')

            # Publish image
            My_MDML_Exp.publish_image('IMAGE', img_byte_string,
                                      'random_image_' + str(i) + '.JPG',
                                      mdml.unix_time())

            # Sleep to publish data once a second
            time.sleep(.1)
            i += 1
        if not reset:
            print("Ending MDML experiment")
            My_MDML_Exp.reset()
            reset = True
except KeyboardInterrupt:
    if not reset:
        My_MDML_Exp.reset()
    My_MDML_Exp.stop_debugger()
示例#8
0
# Receive events about your experiment from MDML
My_MDML_Exp.start_debugger()

# Sleep to let debugger thread set up
time.sleep(1)

# Add and validate a configuration for the experiment
My_MDML_Exp.add_config(config)
# You can also input a filepath to a file containing the configuration
# The contents of the file must be a dict after json.loads()

# Send configuration file to the MDML
#My_MDML_Exp.send_config() # this starts the experiment

# Creating example data to publish
data = '1\t4\t30\t1630\t64\tExperiment running according to plan.'
device_id = 'DEVICE_J'  # Should match one of the devices in config file
data_delimiter = '\t'
use_influxdb = True  #False#
# Appending unix time to data for InfluxDB
data = mdml.unix_time() + data_delimiter + data

# Publishing data - do this as much and as often as required by your experiment
My_MDML_Exp.publish_data(device_id,\
    data,\
    data_delimiter,\
    use_influxdb)

# Make sure to reset the MDML to end your experiment!
#My_MDML_Exp.reset()
示例#9
0
def random_data(size):
    dat = []
    for _ in range(size):
        dat.append(str(random.random()))
    return dat


reset = False
try:
    i = 0
    while True:
        while i < 10:  # publish data 10 times
            # Create random data
            dat['intensity'] = random_data(101)

            # Send data to MDML
            My_MDML_Exp.publish_vector_data('VECTOR', dat, mdml.unix_time())

            # Sleep to publish data every three seconds
            time.sleep(3)
            i += 1
        if not reset:
            print("Ending MDML experiment")
            My_MDML_Exp.reset()
            reset = True
except KeyboardInterrupt:
    if not reset:
        My_MDML_Exp.reset()
    My_MDML_Exp.stop_debugger()
print(len(b64encode(np.random.bytes(1500000)).decode('utf-8')))  # 2MB
print(len(b64encode(np.random.bytes(3750000)).decode('utf-8')))  # 5MB
print(len(b64encode(np.random.bytes(7500000)).decode('utf-8')))  # 10MB
print(len(b64encode(np.random.bytes(15000000)).decode('utf-8')))  # 10MB

try:
    i = 0
    while True:
        while i < 14000:
            if i < 1000:
                # Generating random images
                img_byte_string = b64encode(
                    np.random.bytes(750)).decode('utf-8')
                My_MDML_Exp._publish_image_benchmarks(
                    'IMAGE', img_byte_string,
                    'random_image_' + str(i) + '.JPG', mdml.unix_time(), '1KB')
                time.sleep(.1)

            elif i < 2000:
                # Generating random images
                img_byte_string = b64encode(
                    np.random.bytes(1500)).decode('utf-8')
                My_MDML_Exp._publish_image_benchmarks(
                    'IMAGE', img_byte_string,
                    'random_image_' + str(i) + '.JPG', mdml.unix_time(), '2KB')
                time.sleep(.1)

            elif i < 3000:
                # Generating random images
                img_byte_string = b64encode(
                    np.random.bytes(3750)).decode('utf-8')