Exemplo n.º 1
0
 def __init__(self, dbfile=""):
     if (dbfile == ""):
         App_Root = os.path.abspath(
             os.path.join(
                 os.path.abspath(
                     os.path.join(
                         os.path.dirname(os.path.realpath(__file__)),
                         os.pardir)), os.pardir))
         dbfile = os.path.join(App_Root, Conf("SqLite").read_sqlite())
     else:
         dbfile = os.path.join(dbfile, Conf("SqLite").read_sqlite())
     self.dbfile = dbfile
Exemplo n.º 2
0
def main():
    import time
    import numpy as np
    from conf import Conf

    cnf = Conf(exp_name='default')

    model = Autoencoder(hmap_d=cnf.hmap_d).to(cnf.device)
    model.load_w('/home/fabio/PycharmProjects/LoCO/models/weights/vha.pth')

    print(model)
    print(f'* number of parameters: {model.n_param}')

    x = torch.rand((1, 14, cnf.hmap_d, cnf.hmap_h, cnf.hmap_w)).to(cnf.device)

    print('\n--- ENCODING ---')
    y = model.encode(x)
    print(f'* input shape: {tuple(x.shape)}')
    print(f'* output shape: {tuple(y.shape)}')

    print(
        f'* space savings: {100 - 100 * np.prod(tuple(y.shape)) / np.prod(tuple(x.shape)):.2f}%'
    )
    print(f'* factor: {np.prod(tuple(x.shape)) / np.prod(tuple(y.shape)):.2f}')

    print('\n--- DECODING ---')
    xd = model.decode(y)
    print(f'* input shape: {tuple(y.shape)}')
    print(f'* output shape: {tuple(xd.shape)}')

    print('\n--- FORWARD ---')
    y = model.forward(x)
    print(f'* input shape: {tuple(x.shape)}')
    print(f'* output shape: {tuple(y.shape)}')
Exemplo n.º 3
0
    def __init__(self, app_name, abbrev=None):
        self.app_name = app_name
        self.abbrev = abbrev if abbrev else self.app_name[:4]
        self.conf = Conf()
        self.TABLES = {
            ACTOR_PARTICIPANTS: self.get_actor_pariticipants,
            ACTORS: self.get_actors,
            ANSWERS: self.get_answers,
            ARTIFACTS: self.get_artifacts,
            CRITERIA: self.get_criteria,
            EVAL_MODES: self.get_eval_modes,
            ITEMS: self.get_items,
            PARTICIPANTS: self.get_participants,
            TASKS: self.get_tasks,
        }
        # TODO: It should be possible to grab this from the schema
        self.UPDATE_ORDER = [
            PARTICIPANTS,
            ACTORS,
            ACTOR_PARTICIPANTS,
            CRITERIA,
            EVAL_MODES,
            TASKS,
            ITEMS,
            ARTIFACTS,
            ANSWERS,
        ]

        self._convert_id = lambda r: self.abbrev + '-' + '0' * (8 - len(
            r)) + r if r != 'None' else None
Exemplo n.º 4
0
def run(conf_fname, sensor_queue, debug=False):
    logging.basicConfig(
        filename='climon.log',
        format=
        '%(asctime)s %(levelname)s MON[%(process)d/%(thread)d] %(message)s',
        level=logging.DEBUG)

    conf = Conf(conf_fname)

    if 'monitor-interval' in conf.raw['common']:
        db = database.WriteDB(conf.raw['common']['database'])

        missing_stats = set()

        queue_timestamp = monitor_timestamp = stats_timestamp = datetime.min

        while True:
            logging.debug('Queue size: %d', sensor_queue.qsize())

            while not sensor_queue.empty():
                try:
                    item = sensor_queue.get_nowait()
                    logging.debug('db.set(%r, %r, %r, %r)', item['sensor_id'],
                                  item['timestamp'], item['metric'],
                                  item['value'])
                    db.set(item['sensor_id'], item['timestamp'],
                           item['metric'], item['value'])
                    missing_stats.add((item['sensor_id'], item['timestamp']))
                except queue.Empty:
                    logging.debug('empty sensor_queue')
                    break

            if interval_over(monitor_timestamp,
                             int(conf.raw['common']['monitor-interval'])):
                monitor_timestamp = datetime.utcnow()
                for sensor_id, sensor in conf.iter_elements('sensor'):
                    log_sensor_data(db, sensor_id, sensor, monitor_timestamp)
                    missing_stats.add((sensor_id, monitor_timestamp))

                for toggle_id, toggle in conf.iter_elements('toggle'):
                    log_toggle_state(db, toggle_id, toggle, monitor_timestamp)
                    missing_stats.add((toggle_id, monitor_timestamp))

            if interval_over(stats_timestamp,
                             int(conf.raw['common']['stats-interval'])):
                stats_timestamp = datetime.utcnow()
                for id, timestamp in missing_stats:
                    db.update_stats(id, timestamp)
                missing_stats = set()

            logging.debug('Starting to sleep')
            sleep_since(queue_timestamp,
                        int(conf.raw['common']['queue-interval']))
            queue_timestamp = datetime.utcnow()

        db.close()
    else:
        logging.debug('Monitor is idle.')
        while True:
            sleep(60)
Exemplo n.º 5
0
 def __init__(self):
     conf = Conf()
     conf.load('dspd.properties','../config')
     self.statuslog = StatusLog(conf,prefix = 'status_log_local')
     self.conf = conf
     self.dspd_key = conf.get('dspd_key_name')
     self.ard_key = conf.get('ard_key_name')
Exemplo n.º 6
0
def _test1():
    """Load the full coniguration"""
    logging.info("### TEST1 ###")
    mainDirs = "../../../../test/config"
    conf = Conf()
    conf.load("status_log.properties", mainDirs)
    conf.dump()

    # Default.  No connection information
    sl0 = StatusLog()
    sl0.dump()
    
    # Use init() to initialize
    sl1 = StatusLog()
    sl1.init(host='nn02.corp.xad.com', port=3306, user='******', password='******',
             dbname='xad_etl')
    sl1.dump()
    
    # Use conf to initialize.  Prefix = 'status_log'
    sl2 = StatusLog(conf)
    sl2._checkInit()
    sl2.dump()
    
    # Use conf to initialize.  Prefix = 'status_log_local'
    sl3 = StatusLog()
    sl3.confInit(conf, prefix='status_log_local')
    sl3.dump()
    
    #sl3.addStatus('TEST/statuslog_py/hourly', '2017/01/22/11')
    #sl3.addStatus('TEST/statuslog_py/DAILY', '2017/01/22')

    sl3._selectAll(50);
    
    _testStatus(sl3, 'TEST/statuslog_py/hourly', '2017/01/22/11')
    _testStatus(sl3, 'TEST/statuslog_py/hourly', '2017/01/22/12')
Exemplo n.º 7
0
def main():
    ''' Start the main application interface '''
    app=QtWidgets.QApplication(sys.argv)

    # Initiate the global configuration
    global conf
    conf=Conf()
    
    # Clean the log file
    if(conf.get("clean_log")=="yes"):
        open(LOG_FILE, "w").close()

    # Show splash-screen
    if(conf.get("splash_screen")=="yes"):
        ss=True
    else:
        ss=False
    if(ss):
        splash=QtWidgets.QSplashScreen(QtWidgets.QPixmap("icons/splash.png"))
        splash.show()
        time.sleep(0.1)
        app.processEvents()
        splash.showMessage("Loading...")

    # Create main window
    w=Window()
    if(ss):
        splash.finish(w)

    # Start application
    sys.exit(app.exec_())
Exemplo n.º 8
0
def main(exp_name, conf_file_path, seed):
    # type: (str, str, int) -> None

    # if `exp_name` is None,
    # ask the user to enter it
    if exp_name is None:
        exp_name = click.prompt('▶ experiment name', default='default')

    # if `exp_name` contains '!',
    # `log_each_step` becomes `False`
    log_each_step = True
    if '!' in exp_name:
        exp_name = exp_name.replace('!', '')
        log_each_step = False

    # if `exp_name` contains a '@' character,
    # the number following '@' is considered as
    # the desired random seed for the experiment
    split = exp_name.split('@')
    if len(split) == 2:
        seed = int(split[1])
        exp_name = split[0]

    cnf = Conf(conf_file_path=conf_file_path,
               seed=seed,
               exp_name=exp_name,
               log=log_each_step)
    print(f'\n{cnf}')

    print(f'\n▶ Starting Experiment \'{exp_name}\' [seed: {cnf.seed}]')

    trainer = Trainer(cnf=cnf)
    trainer.run()
Exemplo n.º 9
0
def main(exp_name, seed):
    # type: (str, int) -> None

    # if `exp_name` is None,
    # ask the user to enter it
    if exp_name is None:
        exp_name = click.prompt('▶ experiment name', default='default')

    # if `exp_name` contains a '@' character,
    # the number following '@' is considered as
    # the desired random seed for the experiment
    split = exp_name.split('@')
    if len(split) == 2:
        seed = int(split[1])
        exp_name = split[0]

    cnf = Conf(seed=seed, exp_name=exp_name)

    print(f'\n▶ Starting Experiment \'{exp_name}\' [seed: {cnf.seed}]')

    if cnf.model_input == 'joint':
        trainer = TrainerJoint(cnf=cnf)
    elif cnf.model_input == 'detection':
        trainer = TrainerDet(cnf=cnf)
    else:
        assert False, ''
    trainer.run()
Exemplo n.º 10
0
def visualizeSets_5(
    cs=d.default_cs,
    env=d.default_env,
    agent=d.default_agent,
    k=d.default_k_visualization,
    ps=d.default_ps,
    colors=d.default_colors_sets,
    components=d.default_components,
    loc=d.default_loc,
    show=True,
    conf=None,
    test_chaos_theory=False,
):

    if conf is None:
        conf = Conf()
        conf.test_chaos_theory = test_chaos_theory

    trajs = []
    for p in ps:
        for c in cs:
            trajs.append(getTraj(c, env, agent, p, conf=conf))
    v = Visualisator()
    v.show = show
    name = tools.FileNaming.descrName(env, agent, c, conf)
    filename = tools.FileNaming.imageTrajName(env.name, agent.name,
                                              c, p, conf, k)
    v.plotCompGP(trajs, colors=colors, name=name, components=components,
                 loc=loc, k=k, filename=filename)
Exemplo n.º 11
0
def main(exp_name):
    # type: (str) -> None

    cnf = Conf(exp_name=exp_name)

    print(f'▶ Results of experiment \'{exp_name}\'')
    results(cnf=cnf)
Exemplo n.º 12
0
 def __init__(self):
     self.connect = MySQLdb.connect(*Conf().read())
     self.connect.set_character_set('utf8')
     c = self.connect.cursor()
     c.execute('SET NAMES utf8;')
     c.execute('SET CHARACTER SET utf8;')
     c.execute('SET character_set_connection=utf8;')
Exemplo n.º 13
0
def main():
    mode = Mode()
    musicList = MusicList()
    selectMusic = SelectMusic()
    musicStart = MusicStart()
    listUp = ListUp()
    conf = Conf()

    conf.existence()

    listUp.listUp()

    modeFlag = mode.selectMode()
    while modeFlag == "EOF":
        modeFlag = mode.selectMode()

    if modeFlag == "loop":
        print("\n")
        musicList.musicList()
        print("\n")
        musicStart.loop()

    if modeFlag == "single":
        print("\n")
        musicList.musicList()
        number = selectMusic.selectMusic()
        print("\n")
        musicStart.single(number)
Exemplo n.º 14
0
    def __init__(self):
        self.SCHEDULER = BlockingScheduler()
        conf = Conf()
        confs = conf.get_confs()

        for conf in confs:
            self.add_corn_trigger(conf)
Exemplo n.º 15
0
def main():
    ds = JTATestingSet(cnf=Conf(exp_name='default'))

    for i in range(len(ds)):
        frame, gt_3d, _, _, _, _, frame_path = ds[i]
        gt_3d = json.loads(gt_3d)
        print(f'Example #{i}: frame.shape={tuple(frame.shape)}, gt_3d.len={len(gt_3d)}')
        print(f'\t>> {frame_path}')
Exemplo n.º 16
0
    def setUpClass(cls):

        cls.log = Log.getLogger()
        cls.driver = PhantomJS_()
        cls.conf = Conf()
        cls.log.info("\n\n" + __class__.__name__ + "." +
                     sys._getframe().f_code.co_name +
                     " finished.\n---------- start ---------")
Exemplo n.º 17
0
	def __init__(self):
		sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../lib/utils")
		from conf import Conf
		self.conf = Conf()
		from log import Log as l
		self.log = l.getLogger()
		
		self.opt = Search_options()
		self.log.debug("class " + __class__.__name__ + " created.")
Exemplo n.º 18
0
def main():
    cnf = Conf(exp_name='default')
    ds = JTATrainingSet(cnf=cnf)

    for i in range(len(ds)):
        x, y = ds[i]
        print(
            f'Example #{i}: x.shape={tuple(x.shape)}, y.shape={tuple(y.shape)}'
        )
Exemplo n.º 19
0
def main():
    cnf = Conf(exp_name='../conf/cp_100_jta.yaml',
               conf_file_path='../conf/cp_100_jta.yaml')
    ds = JTATrainingSet(cnf=cnf)

    for i in range(len(ds)):
        x, y = ds[i]
        print(
            f'Example #{i}: x.shape={tuple(x.shape)}, y.shape={tuple(y.shape)}'
        )
Exemplo n.º 20
0
def main():
    ds = JTAValidationSet(cnf=Conf(exp_name='../conf/cp_100_jta.yaml',
                                   conf_file_path='../conf/cp_100_jta.yaml'))

    for i in range(len(ds)):
        frame, gt_3d, _, _, _, _, frame_path = ds[i]
        gt_3d = json.loads(gt_3d)
        print(
            f'Example #{i}: frame.shape={tuple(frame.shape)}, gt_3d.len={len(gt_3d)}'
        )
        print(f'\t>> {frame_path}')
Exemplo n.º 21
0
 def __init__(self, conf=False):
     '''
     Initiate the index object. Accepts a Conf object as an
     optional parameter.
     '''
     if (conf):
         self.conf = conf
     else:
         self.conf = Conf()
     self.data = {}
     self.compile()
Exemplo n.º 22
0
def main(argv):
    training, mode = parse_args(argv, params)
    model = Conf(params=params, mode=mode)
    if training:
        try:
            model.train()
        except ValueError as error:
            print(error, file=sys.stderr)
    else:
        os.environ["CUDA_VISIBLE_DEVICES"] = params.TEST_GPUS
        model.test()
Exemplo n.º 23
0
 def __init__(self, conf=False):
     '''
     Initiates the alias object
     Accepts a Conf object as parameter
     '''
     self.data = {}
     if (conf):
         self.conf = conf
     else:
         self.conf = Conf()
     self.compile()
Exemplo n.º 24
0
 def save_config(self):
     config = {
         "server_ip": self.edit_server_ip.text(),
         "server_port": self.edit_server_port.text(),
         "local_port": self.edit_local_port.text(),
         "ssl": str(self.cb_ssl.isChecked()),
         "log": str(self.cb_log.isChecked()),
         "autorun": str(self.cb_autorun.isChecked()),
         "proxy": str(self.cb_proxy.isChecked())
     }
     Conf().save_config(config)
Exemplo n.º 25
0
    def __init__(self):
        conf = Conf()
        username = urllib.quote("" + conf.get_db_user())
        password = urllib.quote("" + conf.get_db_password())

        connection = pymongo.MongoClient("mongodb://" \
                                         + username + ":" + password \
                                         + "@" + conf.get_connection_string())

        self._connection = connection
        self.db = self._connection[conf.get_db_name()]
Exemplo n.º 26
0
 def __init__(self, model, id=None):
     super(Audit, self).__init__(model, id)
     self.conf = Conf(model)
     self.graphs = Graphs(model)
     self.logs = Logs(model)
     self.reports = Reports(model)
     self.rules = Rules(model)
     self.syscall = Syscall(model)
     self.uri_fmt = '/audit/%s'
     self.load_rules = self.generate_action_handler('load_rules',
                                                    ['auditrule_file'])
     self.log_map = AUDIT_REQUESTS
Exemplo n.º 27
0
def main():
    import utils
    cnf = Conf(exp_name='default')
    ds = JTAHMapDS(mode='val', cnf=cnf)
    loader = DataLoader(dataset=ds, batch_size=1, num_workers=0, shuffle=False)

    for i, sample in enumerate(loader):
        x, y, _ = sample
        y = json.loads(y[0])

        utils.visualize_3d_hmap(x[0, 0])
        print(f'({i}) Dataset example: x.shape={tuple(x.shape)}, y={y}')
Exemplo n.º 28
0
    def __init__(self, conf=False):
        '''
        The constructor optionally accepts a configuration.
        If none is provided it creates a default configuration.

        Parameters:
        conf - A dictionary containing configuration options
        '''
        if (conf):
            self._conf = conf
        else:
            self._conf = Conf()
        self.clean = True
Exemplo n.º 29
0
def scan_languages(dir=template_dir):
    languages = os.listdir(os.path.join(program_dir, template_dir))
    toreturn = dict({})
    for lang in languages:
        try:
            toreturn[lang] = (Conf(
                os.path.join(program_dir, dir, lang,
                             language_configuration_file_name)))
        except Exception as err:
            Error("Possibility the language {} is doesn't have language.conf".
                  format(lang))
            traceback.print_exc()

    return toreturn
Exemplo n.º 30
0
def getTraj(
    c=d.default_c,
    env=d.default_env,
    agent=d.default_agent,
    p=d.default_p,
    conf=None,
):
    if conf is None:
        conf = Conf()
    f = tools.FileNaming.trajName(
        env.name, agent.name, c, p, conf)
    traj = Trajectory()
    traj.load(f)
    return traj