Esempio n. 1
0
def run_experiment(data, task_id):
    """Background task to send an email with Flask-Mail."""
    end_result = {}
    for experiment in data:
        end_result[experiment] = {}
        database.EVALUATION_DATABASE = '%s.%s.%s' % (str(current_mills()), task_id, experiment)
        for method in data[experiment]:
            end_result[experiment][method] = {}
            kwargs = {}
            dbs = []
            number_of_experiments = 0
            functions = {}
            for key in data[experiment][method]:
                if key == 'dbs':
                    dbs = data[experiment][method][key]
                elif key == 'number_of_experiments':
                    number_of_experiments = data[experiment][method][key]
                elif 'method' in data[experiment][method][key]:
                    influx_client.switch_database('registry')
                    query = "SELECT arn FROM methods WHERE name_id = '%s';" % data[experiment][method][key]['method']
                    response = influx_client.query(query)
                    arn = ''
                    for item in response:
                        arn = item['arn']
                    functions[key] = {arn: data[experiment][method][key]['parameters']}
                else:
                    custom_kwargs = {key: data[experiment][method][key]}
                    kwargs = {**kwargs, **custom_kwargs}
            for db in dbs:
                influx_client.switch_database('registry')
                query = "SELECT * FROM dbs WHERE name_id = '%s';" % db
                response = influx_client.query(query)
                db = {}
                for item in response:
                    db = item
                db_client = REGISTRY[db['driver']](**json.loads(db['arguments']))
                for i in range(number_of_experiments):
                    arn_kwargs = {'metadata': []}
                    for fnc in functions:
                        for arn in functions[fnc]:
                            body = functions[fnc][arn]
                            body['driver'] = db['driver']
                            response = aws_client.invoke(FunctionName=arn,
                                                         InvocationType='RequestResponse',
                                                         Payload=json.dumps(body), )
                            string_response = response["Payload"].read().decode()
                            parsed_response = json.loads(string_response)
                            arn_kwargs[fnc] = parsed_response['data']
                            if 'metadata' in parsed_response:
                                arn_kwargs['metadata'].append(parsed_response['metadata'])
                    kwargs = {**kwargs, **arn_kwargs}
                    getattr(db_client, method)(**kwargs)
                end_result[experiment][method] = database.Client().get_last_results(method)
    return end_result
Esempio n. 2
0
def on_message(client, userdata, message):
    message_decoded = (str(message.payload.decode("utf-8"))).split(";")
    success = False
    card_id = int(message_decoded[1])
    card_time = datetime.strptime(message_decoded[2], "%H:%M:%S")
    card_time = card_time.strftime("%H:%M:%S")

    for client in db.clients:
        if message_decoded[0] == client.name:
            print("Terminal rozpoznany!")
            success = True
            card_read(client, card_id, card_time)

    if not success:
        print("Nieznany terminal: {}".format(message_decoded[0]))
        add = input("Czy chcesz dodac terminal do bazy? [T/N]: ")
        if add.upper() == "T":
            db.add_client(db.Client(message_decoded[0]))
            print("\nTerminal dodany")
            time.sleep(0.5)
            card_read(db.clients[-1], card_id, card_time)
        else:
            print("Wiadomosc pominieta")
            time.sleep(0.5)
Esempio n. 3
0
from driver.influxdb.client import Client as InfluxClient
from driver.opentsdb.client import Client as OpentsClient
from driver.postgresdb.client import Client as PostgresClient


app = Flask(__name__)

app.config.update(
    CELERY_BROKER_URL='amqp://*****:*****@localhost:5672/apalia',
    CELERY_RESULT_BACKEND='amqp://*****:*****@localhost:5672/apalia'
)
celery = make_celery(app)

aws_client = boto3.client('lambda')

influx_client = database.Client()

REGISTRY = {'influxdb': InfluxClient, 'opentsdb': OpentsClient, 'postgresql': PostgresClient}


def current_mills():
    return int(time.time()*1000.0)


@app.route('/methods', methods=['GET', 'POST'])
def method_registry():
    influx_client.switch_database('registry')
    if request.method == 'POST':
        data = json.loads(request.data)
        arn = data['arn']
        name_id = data['name_id']
Esempio n. 4
0
        print("\t[5] Usun pracownika")
        print("\t[6] Przypisz karte RFID do pracownika")
        print("\t[7] Usun przypisane karty do pracownika")
        print("\t[8] Wygeneruj Raport")
        print("\t[9] Wyswietl klientow")
        print("\t[10] Wyswietl pracownikow")
        print("\t[Any] Wyjscie\n")
        user_input = input("Wybierz akcje: ")
        print()

        if user_input == '1':
            server.run()

        elif user_input == '2':
            client_name = input("Podaj nazwe nowego terminalu: ")
            client = db.Client(client_name)
            db.add_client(client)
            print("\nTerminal dodano!")

        elif user_input == '3':
            db.print_clients()
            rem_client = input("\nPodaj nazwe terminalu do usuniecia: ")
            db.remove_client(rem_client)

        elif user_input == '4':
            worker_name = input("Podaj imie i nazwisko nowego pracownika: ")
            worker = db.Worker(worker_name)
            db.add_worker(worker)

        elif user_input == '5':
            db.print_workers()
Esempio n. 5
0
import json

import plotly.plotly as py
import plotly.graph_objs as go
import database

from scipy import stats

py.sign_in('aleksey.sergien', 'WRBJNVEVssmXHxrKRuSS')
client = database.Client()

exp_names_DEFAULT = ['writing_multiple_databases']
name_of_measurements_DEFAULT = ['write_records']
colors_DEFAULT = {
    'influxdb': {
        'full': '#d7724a',
        'line': '#a73508'
    },
    'opentsdb': {
        'full': '#6fe314',
        'line': '#327300'
    },
    'postgresdb': {
        'full': '#226ad9',
        'line': '#002d73'
    }
}
order_DEFAULT = ['influxdb', 'postgresdb', 'opentsdb']
downsample_size_DEFAULT = 100
title_DEFAULT = 'Records writing'
x_title_DEFAULT = 'number of records'