def __process_base64(self, base_64):
        """Private method to decode and return the auto data wrapped in the base64 message

        Note:
            This will remove the blob prefix if the data is returned from a browser

        Arguments:
            base_64 (str): The base64 str that needs to be processed

        Returns: (bytes)
            The raw wav data of the base64 wrapped audio
        """

        try:
            # Web blob prefix to detect and remove
            audio_prefix = Configs.get_stt()["audio_prefix"]

            if audio_prefix is None:
                raise TypeError("AudioPrefix cannot be none")

            return b64decode(
                base_64.replace(Configs.get_stt()["audio_prefix"], ""))
        except Exception as err:
            log.error("Error processing base64 audio packet: (err: %s)" %
                      str(err))
Exemple #2
0
def initialize_configs(config_path):
    config_modules = []

    all_configs = config_names(config_path)

    if (len(all_configs) == 0):
        print("Error: no config files found in config path '{0}'".format(
            config_path),
              file=sys.stderr)
        sys.exit(1)

    config_helper = Configs(all_configs)
    config_helper.load_modules(config_modules)

    # Give at least one module the config helper
    config_modules[0].config_helper = config_helper

    # Step Four: Load jenni

    try:
        from __init__ import run
    except ImportError:
        try:
            from jenni import run
        except ImportError:
            print("Error: Couldn't find jenni to import", file=sys.stderr)
            sys.exit(1)

    # Step Five: Initialise And Run The jennies

    # @@ ignore SIGHUP
    for config_module in config_modules:
        run(config_module)  # @@ thread this
Exemple #3
0
def initialize_configs(config_path):
    config_modules = []

    all_configs = config_names(config_path)

    if(len(all_configs) == 0):
        print("Error: no config files found in config path '{0}'".format(config_path), file=sys.stderr)
        sys.exit(1)

    config_helper = Configs(all_configs)
    config_helper.load_modules(config_modules)

    # Give at least one module the config helper
    config_modules[0].config_helper = config_helper

    # Step Four: Load jenni

    try: from __init__ import run
    except ImportError:
        try: from jenni import run
        except ImportError:
            print("Error: Couldn't find jenni to import", file=sys.stderr)
            sys.exit(1)

    # Step Five: Initialise And Run The jennies

    # @@ ignore SIGHUP
    for config_module in config_modules:
        run(config_module) # @@ thread this
Exemple #4
0
    def __init__(self):
        from pymongo import MongoClient, ASCENDING, DESCENDING
        from configs import Configs
        import json
        configs = Configs()
        self.client = MongoClient(configs.get('databaseIP'),
                                  configs.get('databasePort'))
        self.db = self.client['DotaSeer']

        #self.matches = self.db['Matches'].create_index(('match_id'), unique = True)
        self.heroes = self.db['Heroes'].create_index('id')
class ReqLib:
    def __init__(self):
        self.configs = Configs()

    '''
    This function allows a user to make a request to 
    a certain endpoint, with the BASE_URL of 
    https://api.princeton.edu:443/active-directory/1.0.2

    The parameters kwargs are keyword arguments. It
    symbolizes a variable number of arguments 
    '''

    def getJSON(self, endpoint, **kwargs):
        req = requests.get(
            self.configs.BASE_URL + endpoint,
            params=kwargs if "kwargs" not in kwargs else kwargs["kwargs"],
            headers={"Authorization": "Bearer " + self.configs.ACCESS_TOKEN},
        )
        text = req.text

        # Check to see if the response failed due to invalid
        # credentials
        text = self._updateConfigs(text, endpoint, **kwargs)

        return json.loads(text)

    def _updateConfigs(self, text, endpoint, **kwargs):
        if text.startswith("<ams:fault"):
            self.configs._refreshToken(grant_type="client_credentials")

            # Redo the request with the new access token
            req = requests.get(
                self.configs.BASE_URL + endpoint,
                params=kwargs if "kwargs" not in kwargs else kwargs["kwargs"],
                headers={
                    "Authorization": "Bearer " + self.configs.ACCESS_TOKEN
                },
            )
            text = req.text

        return text

    def getXMLorTXT(self, endpoint, **kwargs):
        req = requests.get(
            self.configs.BASE_URL + endpoint,
            params=kwargs if "kwargs" not in kwargs else kwargs["kwargs"],
            headers={"Authorization": "Bearer " + self.configs.ACCESS_TOKEN},
        )
        # Check to see if the response failed due to invalid
        # credentials
        text = self._updateConfigs(req.text, endpoint, **kwargs)
        return text
Exemple #6
0
 def __init__(self) -> None:
     super().__init__()
     self._configs = Configs()
     self._pid = 0
     self._start = ""
     self._restart_count = 0
     self._in_error = False
def numeracaoU(id_numeracao):
    numeracao = DAO.search_by_id(id_numeracao, Numeracao)
    file_list = return_files_numeracao(id_numeracao, Files)
    file_path = Configs.get_file_path()
    return render_template('numeracaoU.html', titulo='Edição de Numeração', numeracao=numeracao,
                           id_numeracao=id_numeracao, files=file_list, retificacao=False, file_path=file_path,
                           insert=True)
Exemple #8
0
def main():
    utils.print_header("MUSIC BACKUP PROGRAM")
    configs = Configs.from_json("config.json")
    analyzer = Analyzer(configs)
    dst_files = analyzer.get_backup_files()
    src_files = analyzer.get_source_files()
    analyzer.compare_directories()
    summary = ""
    if analyzer.files_to_backup > 0 and configs.backup_enabled:
        utils.print_header("COPYING TO BACKUP")
        print("Starting copying process...\n")
        copier = Copier(configs.source_path, configs.backup_path, src_files,
                        dst_files, analyzer.files_to_backup)
        backed_up_count = copier.copy()
        summary += "Backed up a total of {} files!".format(backed_up_count)
    if analyzer.files_to_backcopy > 0 and configs.backcopy_enabled:
        utils.print_header("COPYING TO LOCAL")
        print("Starting copying process...")
        copier = Copier(configs.backup_path, configs.backcopy_path, dst_files,
                        src_files, analyzer.files_to_backcopy)
        backcopied_count = copier.copy()
        summary += "Copied a total of {} files to your local!".format(
            backcopied_count)
    if summary and (configs.backcopy_enabled or configs.backup_enabled):
        utils.print_header("SUMMARY")
        print(summary)
    print("\nComplete!")
    return
Exemple #9
0
 def __init__(self, device, mod, timeout=5000):
     self.timeout = timeout
     if isinstance(device, Device):
         self.device = device
     else:
         self.device = connect_device(device)
     self.logger = createlogger(mod)
     self.log_path = create_folder()
     self.config = GetConfigs("common")
     self.product = Configs("common").get("product", "Info")
     self.appconfig = AppConfig("appinfo", self.product)
     self.appconfig.set_section(mod)
     self.adb = self.device.server.adb
     self.suc_times = 0
     try:
         self.mod_cfg = GetConfigs(mod)
         self.test_times = 0
         self.dicttesttimes = self.mod_cfg.get_test_times()
         if mod == "Email":
             for i in self.dicttesttimes:
                 self.test_times += int(self.dicttesttimes[i])
                 if i <> 'opentimes':
                     self.test_times += int(self.dicttesttimes[i])
         elif mod == "Message":
             for i in self.dicttesttimes:
                 self.test_times += int(self.dicttesttimes[i])
                 if i == 'opentimes':
                     self.test_times += int(self.dicttesttimes[i]) * 3
         else:
             for test_time in self.dicttesttimes:
                 self.test_times += int(self.dicttesttimes[test_time])
         self.logger.info("Trace Total Times " + str(self.test_times))
     except:
         pass
Exemple #10
0
    def on_downloads(self):
        self.hide()
        self.ui.lwFiles.clear()

        cfg = Configs()
        if not os.path.exists(cfg.downloads_path()):
            QtGui.QMessageBox.warning(self, 'Ошибка', 'Нет загруженных файлов!', QtGui.QMessageBox.Yes)
            return

        if platform.system() == "Linux":
            for mngr in cfg.file_managers():
                if os.path.exists("".join(("/usr/bin/", mngr))):
                    subprocess.call("".join((mngr, " ", cfg.downloads_path())), shell=True)
                    break
        else:
            import win32api
            win32api.ShellExecute(0, 'open', cfg.downloads_path(), '', '', 1)
Exemple #11
0
    def setup(self, stage):

        self.configs = Configs()
        self.dataset = CustomDataset(self.configs)
        dataset_size = len(self.dataset)
        indices = list(range(dataset_size))
        split = int(np.floor(self.configs.valSplit * dataset_size))
        self.trainIndices, self.valIndices = indices[split:], indices[:split]
Exemple #12
0
 def motor_states(self, motors, robot_name):
     # Dynamixel monitor start
     if not self.monitor_started:
         for i, m in enumerate(motors):
             if m['hardware'] == 'pololu':
                 self.pololu_boards[m['topic']] = {}
         self.start_motors_monitor(robot_name)
         self.monitor_started = True
         # Sleep some time so first results if motors are alive will have time to return
         time.sleep(0.5)
     status = {}
     pololu_boards = {}
     for i, m in enumerate(motors):
         if m['hardware'] == 'pololu':
             if not m['topic'] in self.pololu_boards.keys():
                 self.pololu_boards[m['topic']] = {}
             if m['name'] in self.pololu_boards[m['topic']].keys():
                 m['motor_state'] = {
                     'position': self.pololu_boards[m['topic']][m['name']]
                 }
                 m['error'] = 2
             else:
                 m['error'] = 1
             motor = PololuMotor(m['name'], m)
             #Conert to angles
             m['init'] = round(math.degrees(motor.get_angle(m['init'] * 4)))
             m['min'] = round(math.degrees(motor.get_angle(m['min'] * 4)))
             m['max'] = round(math.degrees(motor.get_angle(m['max'] * 4)))
         #Dynamixel motors
         else:
             if m['motor_id'] in self.dynamixel_motors_states.keys():
                 motors[i]['error'] = 0
                 motors[i]['motor_state'] = self.dynamixel_motors_states[
                     m['motor_id']]
             else:
                 # Motor is not on
                 motors[i]['error'] = 1
             m['max'] = round(
                 math.degrees(Configs.dynamixel_angle(m, m['max'])))
             m['min'] = round(
                 math.degrees(Configs.dynamixel_angle(m, m['min'])))
             # Init has to be replaced last, because calculation depends on it
             m['init'] = round(
                 math.degrees(Configs.dynamixel_angle(m, m['init'])))
     return motors
Exemple #13
0
def connect_device(device_name):
    """connect_device(device_id) -> Device    
    Connect a device according to device ID.
    """
    environ = os.environ
    device_id = environ.get(device_name)
    if device_id == None:
        device_id = device_name
    backend = Configs("common").get("backend", "Info")
    logger.debug("Device ID is " + device_id + " backend is " + backend)
    if backend.upper() == "MONKEY":
        from monkeyUser import MonkeyUser
        device = globals()["%sUser" % backend](device_id)
    else:
        device = Device(device_id)
    if device is None:
        logger.critical("Cannot connect device.")
        raise RuntimeError("Cannot connect %s device." % device_id)
    return device
Exemple #14
0
def connect_device(device_name):
    """connect_device(device_id) -> Device    
    Connect a device according to device ID.
    """
    environ = os.environ
    device_id = environ.get(device_name)
    if device_id == None:
        device_id = device_name       
    backend = Configs("common").get("backend","Info")
    logger.debug("Device ID is " + device_id + " backend is " + backend) 
    if backend.upper() == "MONKEY":
        from monkeyUser import MonkeyUser
        device = globals()["%sUser"%backend](device_id)
    else:
        device = Device(device_id)
    if device is None:
        logger.critical("Cannot connect device.")
        raise RuntimeError("Cannot connect %s device." % device_id)
    return device
Exemple #15
0
def file_delete(id_files, filename):
    file = os.path.join(Configs.get_upload_path(), filename)
    if os.path.isfile(file):
        os.remove(file)
    # primeiro deve ser deletado da tabela cross pq no db tem constraints que ligam as primary keys com as
    # foreigns keys, entao o db nao deixa deletar da tabela files enquanto ainda houver ligação com a tabela cross
    DAO.delete_cross_files(id_files)
    DAO.delete(id_files, Files)
    msg = 'Arquivo deletado'
    return msg
Exemple #16
0
    def __init__(self):
        twitter_config = Configs().twitter_config
        access_token = twitter_config.access_token
        access_token_secret = twitter_config.access_token_secret
        api_key = twitter_config.api_key
        api_secret_key = twitter_config.api_secret_key

        auth = tweepy.OAuthHandler(api_key, api_secret_key)
        auth.set_access_token(access_token, access_token_secret)

        self.client = tweepy.API(auth, wait_on_rate_limit=True)
    def __init__(self, name):
        self.configs = Configs()
        self.BOARD_COLS = self.configs.BOARD_COLS
        self.BOARD_ROWS = self.configs.BOARD_ROWS

        self.name = name
        self.lr = self.configs.lr
        self.decay_gamma = self.configs.decay_gamma
        self.exp_rate = self.configs.exp_rate

        self.states = []
        self.states_val = {}
Exemple #18
0
class Api:
    def __init__(self, api_base_url):
        from configs import Configs
        self.configs = Configs()
        self.api_base_url = self.configs.get(api_base_url)

    def get(self, resource, payload='') -> dict:
        uri = self.api_base_url + resource
        result = requests.get(uri, params=payload)
        result = result.json()
        logging.debug(result)
        return result
Exemple #19
0
    def __init__(self, mw, icon, parent=None):
        QtGui.QSystemTrayIcon.__init__(self, icon, parent)

        self._mw = mw

        menu = QtGui.QMenu(parent)
        cfg = Configs()

        shAction = menu.addAction("Показать")
        shAction.setIcon(QtGui.QIcon("".join((self._mw.app_path, "images/", cfg.get_icons()["Tray"]))))
        QtCore.QObject.connect(shAction, QtCore.SIGNAL("triggered()"), self.show_main)

        shAction2 = menu.addAction("О программе")
        shAction2.setIcon(QtGui.QIcon("".join((self._mw.app_path,"images/elena8d89.png"))))
        QtCore.QObject.connect(shAction2, QtCore.SIGNAL("triggered()"), self.show_about)

        shAction3 = menu.addAction("Выход")
        shAction3.setIcon(QtGui.QIcon("".join((self._mw.app_path, "images/exit.png"))))
        QtCore.QObject.connect(shAction3, QtCore.SIGNAL("triggered()"), self.close_app)

        self.setContextMenu(menu)
        QtCore.QObject.connect(self, QtCore.SIGNAL("activated()"), self.on_active)
    def __init__(self, p1, p2):
        self.configs = Configs()
        self.BOARD_COLS = self.configs.BOARD_COLS
        self.BOARD_ROWS = self.configs.BOARD_ROWS
        self.POLICIES_DIR = self.configs.POLICIES_DIR

        self.p1 = p1
        self.p2 = p2

        self.board = np.zeros((self.BOARD_COLS, self.BOARD_ROWS))
        self.boardHash = None
        self.isEnd = False
        self.playerSymbol = 1
Exemple #21
0
 def motor_states(self, motors, robot_name):
     # Dynamixel monitor start
     if not self.monitor_started:
         for i,m in enumerate(motors):
             if m['hardware'] == 'pololu':
                 self.pololu_boards[m['topic']] = {}
         self.start_motors_monitor(robot_name)
         self.monitor_started = True
         # Sleep some time so first results if motors are alive will have time to return
         time.sleep(0.5)
     status = {}
     pololu_boards = {}
     for i, m in enumerate(motors):
         if m['hardware'] == 'pololu':
             if not m['topic'] in self.pololu_boards.keys():
                 self.pololu_boards[m['topic']] = {}
             if m['name'] in self.pololu_boards[m['topic']].keys():
                 m['motor_state'] = {'position': self.pololu_boards[m['topic']][m['name']]}
                 m['error'] = 2
             else:
                 m['error'] = 1
             motor = PololuMotor(m['name'], m)
             #Conert to angles
             m['init'] = round(math.degrees(motor.get_angle(m['init']*4)))
             m['min'] = round(math.degrees(motor.get_angle(m['min']*4)))
             m['max'] = round(math.degrees(motor.get_angle(m['max']*4)))
         #Dynamixel motors
         else:
             if m['motor_id'] in self.dynamixel_motors_states.keys():
                 motors[i]['error'] = 0
                 motors[i]['motor_state'] = self.dynamixel_motors_states[m['motor_id']]
             else:
                 # Motor is not on
                 motors[i]['error'] = 1
             m['max'] = round(math.degrees(Configs.dynamixel_angle(m, m['max'])))
             m['min'] = round(math.degrees(Configs.dynamixel_angle(m, m['min'])))
             # Init has to be replaced last, because calculation depends on it
             m['init'] = round(math.degrees(Configs.dynamixel_angle(m, m['init'])))
     return motors
Exemple #22
0
    def __init__(self):
        train_configs = Configs()
        self.workspace_limits = train_configs.WORKSPACE_LIMITS
        self.obj_mesh_dir = train_configs.OBJ_MESH_DIR
        self.texture_dir = train_configs.TEXTURE_DIR
        self.num_obj = train_configs.MAX_OBJ_NUM

        is_testing = False
        test_preset_cases = False
        test_preset_file = None

        # Initialize camera and robot
        self.robot = Robot(self.obj_mesh_dir, self.num_obj,
                           self.workspace_limits, is_testing,
                           test_preset_cases, test_preset_file)
Exemple #23
0
 def __init__(self, pretrained_net, n_class):
     super(FCN32s, self).__init__()
     self.n_class = n_class
     self.pretrained_net = pretrained_net
     self.configs = Configs()
     self.save_hyperparameters()
     self.relu = nn.ReLU(inplace=True)
     self.deconv1 = nn.ConvTranspose2d(512,
                                       512,
                                       kernel_size=3,
                                       stride=2,
                                       padding=1,
                                       dilation=1,
                                       output_padding=1)
     self.bn1 = nn.BatchNorm2d(512)
     self.deconv2 = nn.ConvTranspose2d(512,
                                       256,
                                       kernel_size=3,
                                       stride=2,
                                       padding=1,
                                       dilation=1,
                                       output_padding=1)
     self.bn2 = nn.BatchNorm2d(256)
     self.deconv3 = nn.ConvTranspose2d(256,
                                       128,
                                       kernel_size=3,
                                       stride=2,
                                       padding=1,
                                       dilation=1,
                                       output_padding=1)
     self.bn3 = nn.BatchNorm2d(128)
     self.deconv4 = nn.ConvTranspose2d(128,
                                       64,
                                       kernel_size=3,
                                       stride=2,
                                       padding=1,
                                       dilation=1,
                                       output_padding=1)
     self.bn4 = nn.BatchNorm2d(64)
     self.deconv5 = nn.ConvTranspose2d(64,
                                       32,
                                       kernel_size=3,
                                       stride=2,
                                       padding=1,
                                       dilation=1,
                                       output_padding=1)
     self.bn5 = nn.BatchNorm2d(32)
     self.classifier = nn.Conv2d(32, n_class, kernel_size=1)
Exemple #24
0
    def __init__(self):
        super(Recieve, self).__init__()
        self.dldWnd = DownloadWnd()
        self.updWnd = UpdateWnd()
        self.recieveTh = RecieveThread()

        self.cfg = Configs()

        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("downloadStart(QString)"), self.on_download_start)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("decryptStart()"), self.on_decrypt_start)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("decompressStart()"), self.on_decompress_start)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("downloadComplete()"), self.on_download_complete)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("fileDownloaded(QString)"), self.on_file_downloaded)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("fileCount(int)"), self.on_file_count)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("err(QString)"), self.on_err)

        self.step = 0
        self.update = False
        self.fname = str("")
Exemple #25
0
    def __init__(self, device, mod):
        self.product = Configs("common").get("product", "Info")
        self.device = connect_device(device)
        self.appconfig = AppConfig("appinfo")
        self.logger = createlogger(mod)
        self.camera = Camera(self.device, "media_camera")
        self.record = Recorder(self.device, "media_recorder")
        #self.browser = Browser(self.device,"media_browser")
        self.chrome = Chrome(self.device, "media_chrome")
        if self.product == "Sprints":
            self.music = PlayMusic(self.device, "media_music")
        else:
            self.music = Music(self.device, "media_music")
        self.suc_times = 0
        self.mod_cfg = GetConfigs(mod)
        self.test_times = 0
        self.dicttesttimes = self.mod_cfg.get_test_times()

        for i in self.dicttesttimes:
            self.test_times += int(self.dicttesttimes[i])
            if i.upper() in ('VIDEOTIMES', 'RECORDER', 'PHOTOTIMES'):
                self.test_times += int(self.dicttesttimes[i]) * 2
        self.logger.info('Trace Total Times ' + str(self.test_times))
Exemple #26
0
                    help="Number of compilation threads for make")

parser.add_argument(
    "--config-file",
    dest="config_file",
    action="store",
    type=str,
    default='',
    required=True,
    help=
    "configuration file in json format specifying paths of prigams needed to compile CC3D"
)

args = parser.parse_args()
# -------------- end of parsing command line
CFG = Configs(json_fname=args.config_file)

MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION, INSTALLER_BUILD = version_str_to_tuple(
    args.version)

version_str = version_tuple_to_str(version_component_sequence=(MAJOR_VERSION,
                                                               MINOR_VERSION,
                                                               BUILD_VERSION),
                                   number_of_version_components=3)

installer_version_str = version_tuple_to_str(
    version_component_sequence=(MAJOR_VERSION, MINOR_VERSION, BUILD_VERSION,
                                INSTALLER_BUILD),
    number_of_version_components=3)

CURRENT_DIR = os.getcwd()
Exemple #27
0
def create_twitter_client(kafka_producer, configs):
    listener = StdOutListener(kafka_producer, configs.kafka_topic)
    auth = OAuthHandler(configs.consumer_key, configs.consumer_secret)
    auth.set_access_token(configs.access_token_key, configs.access_token_secret)

    return Stream(auth, listener)


def create_kafka_producer():
    # https://www.confluent.io/blog/introduction-to-apache-kafka-for-python-programmers/
    from confluent_kafka import Producer

    p = Producer({'bootstrap.servers': 'localhost:9092',
                  'acks': 'all',
                  'enable.idempotence': 'true',
                  'compression.type': 'snappy'})
    return p


configs = Configs()
producer = None
try:
    producer = create_kafka_producer()
    client = create_twitter_client(producer, configs)

    client.filter(track=configs.twitter_topics)

finally:
    exit_gracefully(producer)
Exemple #28
0
import re
import os
import json
import time
import urllib

import requests
from celery import exceptions as celery_exceptions
from celery import Celery

from models import get_global_session
from models import GameLog, GameLogAndPlayer, Player, GameRecord, GameRecordAndPlayer
from configs import Configs, ConfigsError

configs = Configs.instance()

if not configs.celery_backend_url or not configs.celery_broker_url:
    raise ConfigsError(message="ConfigsError: celery setting was null")

module_name = os.path.splitext(os.path.split(__file__)[1])[0]
celery = Celery(module_name, backend=configs.celery_backend_url, broker=configs.celery_broker_url)

REF_REGEX = re.compile(configs.tenhou_ref_regex)
RESULT_PT_REGEX = re.compile(configs.tenhou_result_pt_regex)
RECORDS_REGEX = re.compile(configs.tenhou_records_regex)


@celery.task(name='task.celery_test')
def celery_test():
    return "ok"
Exemple #29
0
import os
import shutil
from shutil import copyfile, rmtree, copytree

from configs import Configs

if __name__ == "__main__":
    configs = Configs(mode="export")
    params = configs.params
    working_dir = os.path.join("dist", params.path)
    rmtree(working_dir)
    os.makedirs(working_dir)

    src_files = [
        ("train.py", "train.py"),
        ("eval.py", "eval.py"),
        ("infer.py", "infer.py"),
        (os.path.join("models", params.model + ".py"), "model.py"),
        (os.path.join("datasets", params.dataset.name + ".py"), "dataset.py")
    ]
    for src, dst in src_files:
        copyfile(os.path.join("src", src), os.path.join(working_dir, dst))

    copytree(
        os.path.join("src", "utils"),
        os.path.join(working_dir, "utils"),
        ignore=shutil.ignore_patterns("__pycache__")
    )
Exemple #30
0
 def load_config(self, filename):
     with open(filename) as configFile:
         configDict = json.load(configFile)
     self.config = Configs(configDict)
     self.fitnesses = np.zeros((self.config.pop_size))
Exemple #31
0
import sys

from preprocess import dataframe_preprocess
from dataset import SegmentationDataset
from pytorch_lightning_module import ClassifyModel
from models import kaeru_classify_model
from configs import Configs
from utils import fix_seed

# sys.path.append(os.environ.get("TOGURO_LIB_PATH"))
# from slack import Slack
# from sheet import Sheet

start = time.time()

config = Configs()
fix_seed(config.SEED)

if __name__ == "__main__":
    df = dataframe_preprocess(os.path.join(config.input_path, "train.csv"))

    kf = KFold(n_splits=5, shuffle=True, random_state=config.SEED)
    for i, (train, test) in enumerate(kf.split(df)):
        if i == config.fold:
            train_loc, test_loc = train, test

    df_train = df.iloc[train_loc]
    df_valid = df.iloc[test_loc]

    train_dataset = SegmentationDataset(df_train,
                                        image_folder=os.path.join(
                row[leftI] = row[lExiI]
                row[statusI] = 'E'
                if isEmpty(row[roadNotesI]):
                    row[roadNotesI] = row[slNotesI][:50]
            if not isEmpty(row[rExiI]):
                row[rightI] = row[rExiI]
                row[statusI] = 'E'
                if isEmpty(row[roadNotesI]):
                    row[roadNotesI] = row[slNotesI][:50]

            cursor.updateRow(row)


if __name__ == '__main__':
    dataDirectory = r'.\data'
    Configs.setupWorkspace(dataDirectory)
    totalTime = time()

    # User provided feature classes.
    fullSgidRoads = Feature(
        r'Database Connections\Connection to utrans.agrc.utah.gov.sde\UTRANS.TRANSADMIN.Centerlines_Edit',
        'UTRANS.TRANSADMIN.StatewideStreets')
    bikeLanes = Feature(Configs.dataGdb, 'SLCountyBikeUpdate')
    distFromBikeLanes = 12  # distance to limit the road layer. Chosen after exploratory analysis.
    # Select road within a distance from bike lanes.
    subsetLayer = 'roadsCloseToBikeLanes'
    selectTime = time()
    arcpy.MakeFeatureLayer_management(fullSgidRoads.path, subsetLayer)
    arcpy.SelectLayerByLocation_management(subsetLayer, 'WITHIN_A_DISTANCE',
                                           bikeLanes.path, distFromBikeLanes)
    print 'Created subset of SGID roads: {}'.format(
Exemple #33
0
    from keras.datasets import mnist, cifar10

    conf_parser = argparse.ArgumentParser(
        description=__doc__,  # printed with -h/--help
        formatter_class=argparse.RawDescriptionHelpFormatter,
        add_help=False)

    defaults = {}

    conf_parser.add_argument("-c",
                             "--conf_file",
                             help="Specify config file",
                             metavar="FILE_PATH")
    args, remaining_argv = conf_parser.parse_known_args()

    cfg = Configs(args.conf_file) if args.conf_file else Configs()

    parser = argparse.ArgumentParser(parents=[conf_parser])
    parser.set_defaults(**defaults)
    parser.add_argument("--nb_epoch",
                        help="Number of epochs",
                        type=int,
                        metavar="INT")
    parser.add_argument("--red_only",
                        help="Use red only",
                        type=int,
                        metavar="INT")
    parser.add_argument("--block_size",
                        help="Size of each block for the VAE",
                        type=int,
                        metavar="INT")
Exemple #34
0
class Recieve(QtCore.QObject):
    downloadComplete = QtCore.pyqtSignal(bool)

    def __init__(self):
        super(Recieve, self).__init__()
        self.dldWnd = DownloadWnd()
        self.updWnd = UpdateWnd()
        self.recieveTh = RecieveThread()

        self.cfg = Configs()

        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("downloadStart(QString)"), self.on_download_start)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("decryptStart()"), self.on_decrypt_start)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("decompressStart()"), self.on_decompress_start)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("downloadComplete()"), self.on_download_complete)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("fileDownloaded(QString)"), self.on_file_downloaded)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("fileCount(int)"), self.on_file_count)
        QtCore.QObject.connect(self.recieveTh, QtCore.SIGNAL("err(QString)"), self.on_err)

        self.step = 0
        self.update = False
        self.fname = str("")

    def set_configs(self, tcpserver, tcpport, usr, pwd, update, path):
        self.update = update
        self.recieveTh.set_configs(tcpserver, tcpport, usr, pwd, update, path)
        if not self.update:
            self.dldWnd.ui.pb2.setValue(0)

    def on_download_start(self, fname):
        self.fname = fname
        if not self.update:
            self.dldWnd.ui.pb1.setValue(0)
            self.dldWnd.ui.lbFile.setText("<html><head/><body><p><span style='color:#00ffd5;'>" + "Загрузка: "
                                          + fname + "</span></p></body></html>")
        else:
            self.updWnd.ui.lbFile.setText("<html><head/><body><p><span style='color:#00d2ff;'>Загрузка: " + fname
                                          + "</span></p></body></html>")

    def on_decrypt_start(self):
        if not self.update:
            self.dldWnd.ui.pb1.setValue(33)
            self.dldWnd.ui.lbFile.setText("<html><head/><body><p><span style='color:#00ffd5;'>" + "Дешифрование: "
                                          + self.fname + "</span></p></body></html>")

    def on_decompress_start(self):
        if not self.update:
            self.dldWnd.ui.lbFile.setText("<html><head/><body><p><span style='color:#00ffd5;'>" + "Распаковка: "
                                          + self.fname + "</span></p></body></html>")
            self.dldWnd.ui.pb1.setValue(66)

    def on_file_downloaded(self, fname):
        if not self.update:
            self.dldWnd.ui.lbFile.setText(
                "<html><head/><body><p><span style='color:#00ffd5;'>Готово.</span></p></body></html>")

            parts = fname.split('.')
            ext = parts[len(parts) - 1].lower()
            ico = ""
            try:
                ico = self.cfg.get_icons()["FileIcons"][ext]
            except:
                ico = self.cfg.get_icons()["FileIcons"]["default"]

            item = QtGui.QListWidgetItem()
            item.setIcon(QtGui.QIcon( "".join((self.dldWnd.app_path, "images/ext/", ico))))
            item.setText(self.fname)

            self.dldWnd.ui.lwFiles.insertItem(0, item)
            self.dldWnd.ui.pb1.setValue(100)
            self.dldWnd.ui.pb2.setValue(self.dldWnd.ui.pb2.value() + self.step)

    def on_file_count(self, cnt):
        self.step = round(100 / cnt)

    def on_err(self, text):
        QtGui.QMessageBox.critical(self.dldWnd, 'Complete', text, QtGui.QMessageBox.Yes)

    def on_download_complete(self):
        if not self.update:
            self.dldWnd.ui.pb2.setValue(100)
            QtGui.QMessageBox.information(self.dldWnd, 'Complete', 'Приняты новые файлы!', QtGui.QMessageBox.Yes)
        self.downloadComplete.emit(self.update)

    def start(self):
        if not self.update:
            self.dldWnd.show()
        else:
            self.updWnd.show()
        self.recieveTh.start()
import cv2
from imagedata import ImageData

import time

from configs import Configs

from detectors.retina import FaceDetector
from exec_backends.trt_backend import RetinaInfer as RetinaInferTRT
from exec_backends.onnxrt_backend import RetinaInfer as RetinaInferORT
'''
ATTENTION!!! This script is for testing purposes only. Work in progress.
'''

config = Configs(models_dir='/models')

iters = 100

#model_name = 'retinaface_mnet025_v2'
model_name = 'retinaface_r50_v1'
input_shape = [1024, 768]

# 'plan' for TensorRT or 'onnx' for ONNX
backend = 'plan'

retina_backends = {'onnx': RetinaInferORT, 'plan': RetinaInferTRT}

model_dir, model_path = config.build_model_paths(model_name, backend)

retina_backend = retina_backends[backend](rec_name=model_path)
Exemple #36
0
class SendFilesThread(QtCore.QThread):
    connectionStart = QtCore.pyqtSignal()
    err = QtCore.pyqtSignal(str)
    compressStart = QtCore.pyqtSignal(str)
    cryptStart = QtCore.pyqtSignal(str)
    sendStart = QtCore.pyqtSignal(str)
    sendComplete = QtCore.pyqtSignal()
    sendFileComplete = QtCore.pyqtSignal()

    def __init__(self):
        super(SendFilesThread, self).__init__()
        self.cfg = Configs()
        self.app_path = AppPath().main()
        self.a_key = AES256_cert_read("".join((self.app_path, "transf.crt")))

    def send(self, wnd, TCPServer, TCPPort, flist, toUsr):
        """
        Set connection configs
		"""
        self._wnd = wnd
        self._server = TCPServer
        self._port = TCPPort
        self.fileList = flist
        self._toUsr = toUsr

    def run(self):
        toUser = str("")
        self.client = TcpClient()

        mdb = MariaDB()
        if not mdb.connect(self._wnd.MDBServer, self._wnd.MDBUser, self._wnd.MDBPasswd, self._wnd.MDBBase):
            self.err.emit('Ошибка соединения с Базой Данных!')
            return
        toUser = mdb.get_user_by_alias(self._toUsr)
        mdb.close()

        if not os.path.exists("".join((self._wnd.app_path, "sendfiles"))):
            os.makedirs("".join((self._wnd.app_path,"sendfiles")))

        self.connectionStart.emit()
        if not self.client.connect(self._server, self._port, self._wnd.user, self._wnd.passwd):
            print("fail connection")
            self.err.emit("Ошибка соединения с сервером!")
            return

        exts = []
        try:
            exts = self.cfg.unzip_formats()
        except:
            Log().local("Error reading unzip formats")

        c_exts = []
        try:
            c_exts = self.cfg.uncrypt_formats()
        except:
            Log().local("Error reading uncrypted formats")

        print("start send")
        self.client.begin_send_files(toUser)

        for sfile in self.fileList:
            lsf = sfile.split("/")
            l = len(lsf)
            fname = lsf[l - 1]

            """
            Checking extension
			"""
            isCompress = True
            isCrypt = True

            tmp_fname = fname.split(".")
            ext = tmp_fname[len(tmp_fname) - 1].lower()

            for ex in exts:
                if ex == ext:
                    isCompress = False
                    break

            for ex in c_exts:
                if ex == ext:
                    isCrypt = False
                    break

            """
            Rename file
            """
            while True:
                try:
                    parts = fname.split("'")
                    fname = ""
                    l = len(parts)
                    i = 0
                    for part in parts:
                        i += 1
                        if i < l:
                            fname = fname + part + "_"
                        else:
                            fname = fname + part
                    break
                except:
                    break

            self.compressStart.emit(fname)
            if isCompress:
                if not zlib_compress_file(sfile, "".join((self._wnd.app_path, "sendfiles/", fname, ".z"))):
                    Log().local("Error compressing send file: " + fname)
                    print("error compressing")
                    self.client.close()
                    self.err.emit("Ошибка при сжатии файла")
                    return
                else:
                    print("".join((fname, " compressed")))
            else:
                print(fname + " not compressed")
                shutil.copy2(sfile, "sendfiles/" + fname + ".z")

            if isCrypt:
                self.cryptStart.emit(fname)
                if not AES256_encode_file("".join((self._wnd.app_path, "sendfiles/", fname, ".z")),
                                          "".join((self._wnd.app_path, "sendfiles/", fname, ".bin")),
                                          self.a_key):
                    Log().local("Error encrypting send file: " + fname)
                    print("error crypting")
                    self.client.close()
                    self.err.emit("Ошибка при шифровании сообщения")
                else:
                    print("".join((fname, " crypted")))
            else:
                print(fname + " not crypt")
                shutil.copy2("".join((self._wnd.app_path,"sendfiles/", fname, ".z")),
                             "".join((self._wnd.app_path,"sendfiles/", fname, ".bin")))

            self.sendStart.emit(fname)
            self.client.send_file("".join((self._wnd.app_path, "sendfiles/", fname)))
            self.sendFileComplete.emit()

            try:
                os.remove("".join((self._wnd.app_path, "sendfiles/", fname, ".z")))
                os.remove("".join((self._wnd.app_path, "sendfiles/", fname, ".bin")))
            except:
                Log().local("Error filename")
                self.err.emit("Ошибка в имени файла!")

        self.client.end_send_files()

        self.sendComplete.emit()
        print("send complete")
        self.client.close()
Exemple #37
0
 def __init__(self):
     super(SendFilesThread, self).__init__()
     self.cfg = Configs()
     self.app_path = AppPath().main()
     self.a_key = AES256_cert_read("".join((self.app_path, "transf.crt")))
Exemple #38
0
import datetime

import birkie_fetcher
from configs import Configs
from RaceResultStore import RaceResultStore
import skinnyski_fetcher

config = Configs()

history_years = config.get_as_int("HISTORY_LENGTH")
# SEASONS = [str(datetime.date.today().year - year_delta) for year_delta in range(1, history_years)]
SEASONS = ['2015']
#DIVISIONS = {"highschool":config.get_as_string("HS_DIVISION"), "citizen":config.get_as_string("CITIZEN_DIVISION")}
DIVISIONS = {"citizen": config.get_as_string("CITIZEN_DIVISION")}
race_store = RaceResultStore()
######################
# start control flow
######################

for season in SEASONS:
    for division in DIVISIONS.values():
        # get low hanging fruit from skinnyski
        race_infos = skinnyski_fetcher.get_race_infos(season, division)

        for race_info in race_infos:
            # this doesn't solve race_infos that spawn more race_infos
            # so, downstream race_infos will also need to be checked in the store as well (todo)
            if race_info in race_store:
                print("Skipping race already present %s" % (race_info, ))
            else:
                skinnyski_fetcher.process_race(race_info, race_store)
Exemple #39
0
from datetime import timedelta

from configs import Configs

CONN_STR = Configs.get_conn_str()
SECRET_KEY = Configs.get_secret_key()
UPLOAD_PATH = Configs.get_upload_path()
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_DATABASE_URI = CONN_STR
PERMANENT_SESSION_LIFETIME = timedelta(minutes=60)
from configs import Configs
from exec_backends.trt_backend import Arcface as InsightTRT
#from exec_backends.triton_backend import Arcface as InsightTriton
from exec_backends.onnxrt_backend import Arcface as InsightORT
'''
ATTENTION!!! This script is for testing purposes only. Work in progress.
'''


def normalize(embedding):
    embedding_norm = norm(embedding)
    normed_embedding = embedding / embedding_norm
    return normed_embedding


config = Configs()

model_name = 'arcface_r100_v1'

engine = config.build_model_paths(model_name, 'plan')[1]
model_onnx = config.build_model_paths(model_name, 'onnx')[1]

model = InsightTRT(rec_name=engine)
#model = InsightTriton(rec_name=engine)
#model = InsightORT(rec_name=model_onnx)
model.prepare()

model_orig = model_zoo.get_model(model_name, root=config.mxnet_models_dir)
model_orig.prepare(-1)

im = cv2.imread('test_images/crop.jpg', cv2.IMREAD_COLOR)