Exemplo n.º 1
0
    def update_from_config(self, filename):
        """Update a Petri Net with a configuration file

        Read a configuration file and update the transition parameters with the
        values specifies on it.

        Args:
            filename (str): String representing the path of the configuration
                            file
        """

        config_file = utils.load_configuration(filename)
        config = config_file['conditions']

        for t_conf in config:
            t_name = t_conf.get('transition', None)
            t_min = t_conf.get('time-min', None)
            t_max = t_conf.get('time-max', None)
            t_guard = t_conf.get('condition', None)

            # transition doesn't exist
            if not self._pn.has_transition(t_name):
                continue

            # there are no modifications
            t = self._pn.transition(t_name)
            if [t.min_time, t.max_time,
                    str(t.guard)] == [t_min, t_max, t_guard]:
                continue

            self.update_transition(t_name, t_min, t_max,
                                   self._str_to_expression(t_guard))
Exemplo n.º 2
0
def main():
    conf = load_configuration('conf.ini')

    with open(os.path.join(here, 'data', 'counters.json')) as fp:
        counters_data = json.load(fp)

    counters = []
    sortkey = lambda x: counters_data[x[0]]
    cconf = sorted(conf['catalogs'].iteritems(), key=sortkey, reverse=True)
    maxcount = max(counters_data.itervalues())

    for name, catalog in cconf:
        count = counters_data[name]
        counters.append({
            'name': name,
            'title': catalog.get('title') or name,
            'cfg': catalog,
            'count': count,
            'width': '{0:.2f}'.format(count * 100 / maxcount),
        })

    loader = jinja2.FileSystemLoader(os.path.join(here, 'templates'))
    env = jinja2.Environment(loader=loader)
    template = env.get_template('index.jinja')
    rendered = template.render({
        'counters': counters,
    })

    print(rendered)
Exemplo n.º 3
0
def get_mongo_client(db='informed_investing', connect=True):
    m_cfg = load_configuration('mongo')
    client = MongoClient(
        f"mongodb://{m_cfg['user']}:{m_cfg['password']}@{m_cfg['host']}:{m_cfg['port']}",
        connect=connect)
    db = client[db]
    return db
def _load_configuration(input_directory, experiment, keys):
    config = utils.load_configuration(
        os.path.join(input_directory, "..", "config_" + experiment + ".yaml"))

    if len(keys) > 1:
        return config[keys[0]][keys[1]]
    else:
        return config[keys[0]]
Exemplo n.º 5
0
def main():

    conf = utils.load_configuration("drwatson.conf")
    app = api.create_app()

    app.run(host='0.0.0.0',
            debug=conf.getboolean('app', 'Debug'),
            port=int(conf["app"]["port"]))
Exemplo n.º 6
0
def main():
    # We want to update counters for each catalog
    # and print on the standard output.
    counters = {}

    conf = load_configuration('conf.ini')
    for catalog_name, catalog in conf['catalogs'].iteritems():
        counters[catalog_name] = count_datasets(catalog)

    print(json.dumps(counters))
Exemplo n.º 7
0
def main():
    # Load sawyer specific configuration
    sawyer_configuration = load_configuration('sawyer_configuration.json')
    sample_configurations = sawyer_configuration['sample_configurations']

    # Setup simulator
    sim, sawyer_robot, obstacles = init_sim_with_sawyer()

    # Moving Sawyer to a start position
    sawyer_robot.move_to_joint_pos(sample_configurations['config0'])
    time.sleep(2)
    manual_control(sawyer_robot)
Exemplo n.º 8
0
    def __init__(self, pn, path_conf):
        """Initialization of the Improver class.

        Args:
            pn (PetriNet): Petri net to be walked
            path_conf (str): Path to the configuration file
        """
        self._pn = copy.deepcopy(pn)
        configuration = utils.load_configuration(path_conf)
        self._actions = self._get_actions(configuration)
        self._pn.update_from_config(path_conf)
        self._add_environment_pn()
        self._current_time = 0.0
        self.restart()
Exemplo n.º 9
0
def main():
    # Load sawyer specific configuration
    sawyer_configuration = load_configuration('sawyer_configuration.json')
    excluded_pairs = sawyer_configuration['excluded_pairs']
    sample_configurations = sawyer_configuration['sample_configurations']

    # Setup simulator
    sim, sawyer_robot, obstacles = init_sim_with_sawyer()

    # Moving Sawyer to a start position
    sawyer_robot.move_to_joint_pos(sample_configurations['config0'])
    time.sleep(3)

    start_state_config = sample_configurations['config0']
    goal_state_config = sample_configurations['config1']
    sawyer_id = sawyer_robot.get_simulator_id()
    link_pairs = get_link_pairs(sawyer_id, excluded_pairs=excluded_pairs)

    # Initializing STOMP
    stomp = STOMP(sim,
                  sawyer_robot,
                  link_pairs,
                  obstacles,
                  start_state_config,
                  goal_state_config,
                  N=10,
                  control_coefficient=0.1,
                  play_pause=True)
    # stomp.visualize_trajectory(show_only_dot=True)
    stomp.plan()
    stomp.visualize_trajectory()
    stomp.print_trajectory()
    trajectory_data = stomp.get_trajectory(1)
    sawyer_robot.execute_trajectory(trajectory_data)

    # Loop until someone shuts us down
    try:
        while True:
            sim.step()
    except KeyboardInterrupt:
        p.disconnect()
        sys.exit(0)
Exemplo n.º 10
0
def create_app():
    """
    Defines routes and returns a Flask object.
    """

    conf = utils.load_configuration("drwatson.conf")

    app = flask.Flask(__name__)
    app.secret_key = os.urandom(128)
    cors.CORS(app)

    mongo = pymongo.MongoClient("localhost", 27017)
    db = mongo.drwatson

    Watson = w.WatsonConnector(url=conf["watson"]["url"],
                               username=conf["watson"]["username"],
                               password=conf["watson"]["password"],
                               version=conf["watson"]["version"])

    Person = p.Personality(url=conf["personality"]["url"],
                           username=conf["personality"]["username"],
                           password=conf["personality"]["password"],
                           version=conf["personality"]["version"])

    Chatbot = c.Chatbot(url=conf["chatbot"]["url"],
                        username=conf["chatbot"]["username"],
                        password=conf["chatbot"]["password"],
                        version=conf["chatbot"]["version"],
                        workspace_id=conf["chatbot"]["workspace"])

    chatbot_sessions = {}

    #########
    # Feeds #
    #########

    @app.route('/feeds', methods=['GET'])
    def get_feeds():
        """
        Returns all available feeds.
        """

        feeds = db.feeds
        output = []

        for s in feeds.find():
            output.append(s)

        return json_util.dumps(output)

    @app.route('/feeds/<path:feed>', methods=['GET'])
    def get_feed(feed):
        """
        Returns info for specified feed.
        """

        feed = db.feeds.find({"key": feed})

        return json_util.dumps(feed)

    @app.route('/feeds/<path:key>', methods=['PUT'])
    def post_feed(key):
        """
        Post new feed
        """

        feeds = db.feeds
        feed = feeds.find({"key": key})

        # TODO: Validate request data
        key = flask.request.json['key']
        url = flask.request.json['url']
        name = flask.request.json['name']
        active = flask.request.json['active']
        date_field = flask.request.json['date_field']
        text_field = flask.request.json['text_field']

        new_feed = {
            "key": key,
            "url": url,
            "name": name,
            "active": active,
            "date_field": date_field,
            "text_field": text_field
        }

        feeds.replace_one({"key": key}, new_feed, True)

        return flask.jsonify({"result": []}, 201)

    @app.route('/feeds/<path:key>', methods=['DELETE'])
    def delete_feed(key):
        """
        Delete a feed.
        """
        feeds = db.feeds
        feed = feeds.find({"key": key})

        if not feed:
            flask.abort(404)

        feeds.delete_one({"key": key})

        return flask.jsonify({}, 200)

    #########
    # Users #
    #########

    @app.route('/users', methods=['GET'])
    def get_users():
        """
        Returns all users.
        """

        users = db.users
        output = []

        for s in users.find():
            output.append(s)

        output = json_util.dumps(output)

        status = 200
        if output == "[]":
            status = 204

        return output, status

    @app.route('/users/<path:username>', methods=['GET'])
    def get_user(username):
        """
        Returns Profile for specified user.
        """

        user = db.users.find({"username": username})
        user = json_util.dumps(user)

        status = 200
        if user == "[]":
            status = 204

        return user, status

    @app.route('/users/<path:username>/feeds', methods=['GET'])
    def get_feeds_for_user(username):
        """
        Returns all feeds for specified user.
        """

        user = db.users.find_one({"username": username})

        try:
            feeds = user["feeds"]
            status = 200
        except IndexError as e:
            feeds = {}
            status = 204

        feeds = json_util.dumps(feeds)

        return feeds, status

    @app.route('/users/<path:username>', methods=['PUT'])
    def post_user(username):
        """
        Create a new user profile.
        """
        users = db.users

        # TODO: Validate request data
        username = flask.request.json['username']
        password = flask.request.json['password']
        mail = flask.request.json['mail']
        feeds = flask.request.json['feeds']

        new_user = {
            "username": username,
            "mail": mail,
            "password": password,
            "feeds": feeds
        }

        users.replace_one({"username": username}, new_user, True)

        return flask.jsonify({}, 201)

    @app.route('/users/<path:username>', methods=['DELETE'])
    def delete_user(username):
        """
        Delete a user profile.
        """
        users = db.users
        user = users.find({"username": username})

        if not user:
            flask.abort(404)

        users.delete_one({"username": username})

        return flask.jsonify({}, 200)

    ###########
    # Reports #
    ###########

    @app.route('/reports/<path:username>', methods=['GET'])
    @app.route('/users/<path:username>/reports', methods=['GET'])
    def get_user_reports(username):
        """
        Returns all reports for specified user.
        """

        reports = db.reports.find({"username": username})
        reports = json_util.dumps(reports)

        status = 200
        if reports == "[]":
            status = 204

        return reports, status

    @app.route('/reports/<path:username>/<path:date>', methods=['GET'])
    def get_user_report_date(username, date):
        """
        Returns specified report for specified user.
        """

        report = db.reports.find({"username": username, "date": date})
        report = json_util.dumps(report)

        status = 200
        if report == "[]":
            status = 204

        return report, status

    @app.route('/reports/<path:username>/<path:date>', methods=['PUT'])
    def post_report(username, date):
        """
        Create a new report for a user
        """

        reports = db.reports
        report = reports.find({"username": username, "date": date})

        if not report:
            flask.abort(404)

        rm = r.ReportManager(username, Watson, db)
        rm.ta_report(date)

        return flask.jsonify({}, 201)

    @app.route('/reports/<path:username>/<path:date>', methods=['DELETE'])
    def delete_report(username, date):
        """
        Delete a report
        """
        reports = db.reports
        report = reports.find({"username": username, "date": date})

        if not report:
            flask.abort(404)

        reports.delete_one({"username": username, "date": date})

        return flask.jsonify({}, 200)

    @app.route('/pireport/<path:username>', methods=['GET'])
    def get_user_pireport(username):
        """
        Returns PI report for specified user.
        """

        report = db.pireports.find({"username": username})
        report = json_util.dumps(report)

        status = 200
        if report == "[]":
            status = 204

        return report, status

    #############
    # Functions #
    #############

    @app.route('/functions/generate/reports/<path:username>', methods=['GET'])
    def generate_all_reports(username):
        """
        Generate all reports for specified user.
        """

        rm = r.ReportManager(username=username,
                             watson_manager=Watson,
                             personality=Person,
                             db_connector=db)

        dates = rm.get_dates()

        for date in dates:
            pass
        #rm.ta_report(date)

        rm.pi_report()

        return flask.jsonify({}, 200)

    @app.route('/functions/chatbot', methods=['POST'])
    def chatbot():
        """
        Talk to chatbot.
        """

        # TODO: Validate request data
        chat_input = flask.request.json['input']
        session_id = flask.request.json['sessionid']

        if session_id in chatbot_sessions:
            context = chatbot_sessions[session_id]
        else:
            context = {}

        response = Chatbot.conversate(text=chat_input, context=context)
        chatbot_sessions[session_id] = response['context']
        response_output = response['output']

        try:
            response_output["intent"] = response["intents"]
        except IndexError as e:
            response_output["intent"] = []

        print(response_output)

        return flask.jsonify(response_output, 200)

    return app
Exemplo n.º 11
0
np.random.shuffle(pos_assemblies)

assemblies = np.split(np.arange(num_neurons_per_assembly * num_assemblies), num_assemblies)

branch1_nodes = np.max(assemblies) + 1 + np.arange(num_branch_nodes)
branch2_nodes = np.max(branch1_nodes) + 1 + np.arange(num_branch_nodes)
branch3_nodes = np.max(branch2_nodes) + 1 + np.arange(num_branch_nodes)
branch_nodes = [branch1_nodes, branch2_nodes, branch3_nodes]

if experiment == "rewiring_ex5":
    idc_branch_nodes = [0, 2]
else:
    idc_branch_nodes = range(num_branch_nodes)

# Load the configuration file.
config = utils.load_configuration(os.path.join(
    input_directory, "..", "config_" + experiment + ".yaml"))
sim_simulation_time = config["simulation_time"]
sim_w_max = config["connection_parameters"]["w_max"]
sim_input_size = config["input_parameters"]["num_inputs"]
sim_num_assemblies = config["input_parameters"]["num_assemblies"]
sim_assembly_size = config["input_parameters"]["assembly_size"]
sim_num_branches = config["neuron_parameters"]["num_branches"]
sim_sampling_interval_weights = config["sampling_interval_weights"]
input_size = config["input_parameters"]["num_inputs"]

if experiment == "rewiring_ex5":
    assembly_idc = []
    assembly_idc = np.loadtxt(
        os.path.join(input_directory, "assembly_neurons_idc"), dtype=np.int)
    # for assembly_idx_low in np.sort(assembly_idc_low):
    #     assembly_idc.append(np.arange(assembly_idx_low, assembly_idx_low +
#
# This script downloads and ingests Drop Token game
# and player data into the database configured in
# the `configuration.yml` file located in the same
# directory. The database and its tables must be created
# using the `DW_setup.sql` script (located in the same directory)
# before running this script.
# The script assumes that both the games and players
# data sets are complete data sets each time the script runs.
# Data in the `prepared` schema tables is removed before
# new data gets added.
from loaders import load_game_data as games, load_player_data as players
import utils

local_games_csv_path = './game_data.csv'

config = utils.load_configuration('./configuration.yml')

games.load_data(config['game_data_csv_location'], local_games_csv_path, False,
    config['database_server'], config['database_server_port'], config['database'],
    config['database_user'], config['database_password'], True)

players.load_data(config['player_data_location'], config['database_server'], 
    config['database_server_port'], config['database'], config['database_user'], 
    config['database_password'], True)





Exemplo n.º 13
0
        abort(501, 'Undefined service: %s.' % service_name)


@get('/service/<service_name>/status')
def service_status(service_name):
    """Exposes the /service/<service_name>/status endpoint accessible via
    a GET method.
    Used to retrieve the number of running resources for a service as JSON.
    """
    try:
        service_definition = services[service_name]
        running_resources = docker.count_containers_by_image(
            service_definition['image'])
        response = {}
        response['running_resources'] = running_resources
        return response
    except KeyError:
        abort(501, 'Undefined service: %s.' % service_name)


if __name__ == '__main__':
    """Main method.
    Retrieve the configuration from the configuration file.
    It also retrieves the services from a service definition file.
    Finally, it creates a DockerManager instance and start the web server.
    """
    config = load_configuration('genisys-connector.yml')
    services = load_services_from_file(config['connector']['service_file'])
    docker = DockerManager(config['docker']['url'])
    run(host=config['connector']['bind'], port=config['connector']['port'])
Exemplo n.º 14
0
 def __call__(self):
     yaml_spec = load_configuration()
     return self.klass(yaml_spec)
import requests
from flask import Flask, request

from utils import (get_healthy_server, healthcheck, load_configuration,
                   process_firewall_rules_flag, process_rewrite_rules,
                   process_rules, transform_backends_from_config)

loadbalancer = Flask(__name__)

config = load_configuration("loadbalancer.yaml")
register = transform_backends_from_config(config)


@loadbalancer.route("/")
@loadbalancer.route("/<path>")
def router(path="/"):
    updated_register = healthcheck(register)
    host_header = request.headers["Host"]
    header_dictionary = {k: v for k, v in request.headers.items()}

    if not process_firewall_rules_flag(
            config,
            host_header,
            request.environ["REMOTE_ADDR"],
            f"/{path}",
            header_dictionary,
    ):
        return "Forbidden", 403

    for entry in config["hosts"]:
        try:
Exemplo n.º 16
0
#import the class definition from "email_handler.py" file
from email_handler import Class_eMail
#import common
import sys
sys.path.insert(1, '/home/dominika/ZSW_CZW0815_SMART_HOME/main')
import common
import utils

#set the email ID where you want to send the test email
# global data
utils.load_configuration()
To_Email_ID = common.data['mail']
#print(To_Email_ID)

# warning
warning_subject = 'Warning!'
warning_text = 'Warning! \
                The password was incorrect. \
                Please enter the correct password.'

# Send Plain Text Email
email = Class_eMail()
email.send_Text_Mail(To_Email_ID, warning_subject, warning_text)
del email
Exemplo n.º 17
0
        else:
            compute_definition = select_compute_definition(computes)
    except KeyError:
        abort(501, 'Undefined compute: {}.'.format(compute_name))
    services = shared_queue.get()
    services.add(service_name)
    shared_queue.put(services)
    scale_service(compute_definition, service_name, resource_number)


def start_webserver(host, port):
    run(host=host, port=port)


if __name__ == '__main__':
    config = load_configuration('genisys.yml')
    computes = load_computes_from_file(config['genisys']['compute_file'])
    shared_queue = Queue(1)
    try:
        api_thread_args = dict(host=config['genisys']['bind'],
                               port=config['genisys']['port'])
        api_thread = threading.Thread(target=start_webserver,
                                      kwargs=api_thread_args).start()
        poller_thread_args = dict(config=config,
                                  computes=computes,
                                  queue=shared_queue)
        poller_thread = threading.Thread(target=poll_connectors,
                                         kwargs=poller_thread_args).start()
    except Exception:
        print('The application failed to start.')
Exemplo n.º 18
0
        'G': arguments['G'],
        'kernel_size': 3,
        'c_dim': 3,
        'G0': arguments['G0'],
    }

    model = load_model(model_parameters, arguments['vgg'], verbose=arguments['verbose'])

    if arguments['summary'] is True:
        model.rdn.summary()

    if arguments['train'] is True:
        from trainer.train import Trainer

        trainer = Trainer(train_arguments=arguments)
        trainer.train_model(model)

    if arguments['test'] is True:
        from predict import Predictor

        predictor = Predictor(test_arguments=arguments)
        predictor.get_predictions(model)


if __name__ == '__main__':
    parser = get_parser()
    cl_args = parser.parse_args()
    cl_args = vars(cl_args)
    load_configuration(cl_args)
    main(cl_args)
Exemplo n.º 19
0
from flask import Flask, request
import requests, random
from utils import load_configuration, transform_backends_from_config, get_healthy_server, process_rules, process_rewrite_rules, process_firewall_rules_flag
from tasks import healthcheck
import sys

loadbalancer = Flask(__name__)
config = load_configuration('loadbalancer.yaml')
register = transform_backends_from_config(config)


@loadbalancer.route("/")
@loadbalancer.route("/<path>")
def router(path="/"):
    updated_register = healthcheck(register)
    host_header = request.headers["Host"]
    if not process_firewall_rules_flag(
            config, host_header, request.environ["REMOTE_ADDR"], "/" + path):
        return "Forbidden", 403
    for entry in config["hosts"]:
        if host_header == entry["host"]:
            healthy_server = get_healthy_server(entry["host"],
                                                updated_register)
            if not healthy_server:
                return "No Backends servers available", 503
            headers = process_rules(config, host_header,
                                    {k: v
                                     for k, v in request.headers.items()},
                                    "header")
            params = process_rules(config, host_header,
                                   {k: v
Exemplo n.º 20
0
 def __init__(self):
     self._name = "quickfs"
     self._config = load_configuration(self._name)
     self._api_key = self._config['API_KEY']
Exemplo n.º 21
0
        vm.active = False
    spaghetti.kernel.run_chunk(simulation_time - 40, 0, simulation_time)

    sm_inp.active = True
    vm_nrn.active = True
    for vm in vm_br:
        vm.active = True
    spaghetti.kernel.run_chunk(20.0, 0, simulation_time)


if __name__ == '__main__':
    import copy
    from scoop import futures

    # Load the configuration file.
    config = utils.load_configuration("experiments/config_rewiring_ex2.yaml")

    # Change a specific parameter.
    param = "plateau_duration_max"
    delta_param = +0.1  # +-10 %

    # params = config["connection_parameters"]
    params = config["neuron_parameters"]["branch_parameters"]

    value = params[param]
    if value >= 0:
        params[param] += delta_param * value
    else:
        params[param] += -delta_param * value

    if delta_param >= 0:
Exemplo n.º 22
0
 def __init__(self, ticker):
     config = load_configuration('iexfinance')
     self._stock = Stock(ticker, token=config['API_KEY'])
     print(self._stock.get_price())
Exemplo n.º 23
0

@get('/service/<service_name>/status')
def service_status(service_name):
    """Exposes the /service/<service_name>/status endpoint accessible via
    a GET method.
    Used to retrieve the number of running resources for a service as JSON.
    """
    try:
        service_definition = services[service_name]
        running_resources = docker.count_containers_by_image(
            service_definition['image'])
        response = {}
        response['running_resources'] = running_resources
        return response
    except KeyError:
        abort(501, 'Undefined service: %s.' % service_name)


if __name__ == '__main__':
    """Main method.
    Retrieve the configuration from the configuration file.
    It also retrieves the services from a service definition file.
    Finally, it creates a DockerManager instance and start the web server.
    """
    config = load_configuration('genisys-connector.yml')
    services = load_services_from_file(config['connector']['service_file'])
    docker = DockerManager(config['docker']['url'])
    run(host=config['connector']['bind'],
        port=config['connector']['port'])