Example #1
0
def app_main():
    try:
        logger = lgr.Logger()
        print("--------application starting--------------")
        logger.info("--------application starting--------------")
        print("--------loading data----------------------")
        logger.info("--------loading data----------------------")
        dl = dataLoader.DataLoader()
        train_X, test_X = train_test_split(dl.DataFrame.copy(),
                                           test_size=0.3,
                                           random_state=42)
        # label = train_X["median_house_value"].copy()
        # housing = train_X.drop("median_house_value", axis=1)
        housing = test_X.drop("median_house_value", axis=1)
        #label_test = test_X["median_house_value"].copy()
        numeric_cols = list(housing.columns.values)
        category_cols = ["ocean_proximity"]
        numeric_cols.remove("ocean_proximity")
        dp = preproc.DataPreProcess(numeric_cols, category_cols)
        print("--------processing data-------------------")
        dataProcessed = dp.getProcessedData(housing)
        print(dataProcessed.shape)
        configMagt = cmfmagt.ConfigManager()
        engine = mlEngine.ModelEngine()
        print("------------loading model------------------")
        bestModel = engine.loadML(configMagt.config["APPSETTING"]["ml_path"])
        result = bestModel.predict(dataProcessed)
        print(result.shape)
    except Exception as e:
        print("Error : ", str(e))
Example #2
0
    def __init__(self, parent, uiObj):
        #Declare Project Variables
        self.__configFile = os.path.join(
            os.path.expanduser(os.path.join('~', ".sift")), 'sf_config.ini')
        self.loadedProjName = ''
        self.loadedProjPath = ''
        self.loadedProjType = ''

        #Determine the path to sift.py
        self.baseDir = self.initBaseDir()

        #Declare all Managers
        self.uiObj = uiObj
        self.parent = parent
        self.treeViewMgr = TreeviewManager(self, self.uiObj.treeWidget_proj,
                                           self.uiObj.treeWidget_nonProj,
                                           self.uiObj.tabWidget_treeview)
        self.fileMgr = FileManager(self)
        self.viewMgr = ViewManager(self, self.uiObj.tabWidget_viewer)
        self.messageMgr = MessageManager(self, self.uiObj.statusbar)
        self.configMgr = ConfigManager(self)

        #Pass Managers to other Managers that need them
        #(Basically this simulates the Singleton pattern since python can't do it natively)
        self.viewMgr.setFileManager(self.fileMgr)
        self.treeViewMgr.setFileManager(self.fileMgr)
        self.treeViewMgr.setViewManager(self.viewMgr)

        #Load up things needed to happen at start up, but after the managers are all loaded
        self.viewMgr.resetMainViewer()
Example #3
0
    def get():
        config = ConfigManager()
        loc = locale.getdefaultlocale()[0]
        if loc == "en_US":
            font = "Bold 'times new roman' 22 windows-1252"
        if loc == "ja_JP":
            font = "bold 'MS ゴシック' 22 windows-932"
        config["general"] = {
            "language": "",
            "fileVersion": "100",
            "locale": loc,
            "update": True,
            "timeout": 3
        }

        config["view"] = {"font": font, "colorMode": "white"}
        config["speech"] = {"reader": "AUTO"}

        config["mainView"] = {}

        config["network"] = {"auto_proxy": True}

        config["ocr"] = {
            "tmpdir": os.path.join(os.environ["TEMP"], "soc"),
            "saveSourceDir": True,
            "savedir": os.path.join(os.environ["userprofile"], "Documents")
        }
        return config
Example #4
0
 def testSetGetLists(self):
     cm = ConfigManager.ConfigManager('testSetGetLists.JSON')
     cm.set_key_values(self.key_list, self.value_list)
     saved_values = cm.get_key_values(self.key_list)
     self.assertEqual(len(saved_values), len(self.value_list))
     for index in range(0, len(saved_values)):
         self.assertEqual(self.value_list[index], saved_values[index])
Example #5
0
 def test_func_type_cast_for_bool_false( self ):
     """ Test func_type_case for bool false """
     x_answer = False
     str_value = "False"
     str_type = Arguments.C_STR_BOOL_TYPE
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     x_result = cfmg_test._func_type_cast(str_type, str_value)
     self.func_test_equals( x_answer, str(x_result) )
Example #6
0
 def test_func_type_cast_for_float( self ):
     """ Test func_type_case for float """
     x_answer = 0.0
     str_value = "0.0"
     str_type = Arguments.C_STR_FLOAT_TYPE
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     x_result = cfmg_test._func_type_cast(str_type, str_value)
     self.func_test_equals( x_answer, str(x_result) )
Example #7
0
 def test_func_type_cast_for_int( self ):
     """ Test func_type_case for int """
     x_answer = 1
     str_value = "1"
     str_type = Arguments.C_STR_INT_TYPE
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     x_result = cfmg_test._func_type_cast(str_type, str_value)
     self.func_test_equals( x_answer, str(x_result) )
Example #8
0
 def test_func_type_cast_for_none_2( self ):
     """ Test func_type_case for none 2 """
     str_answer = "None"
     x_value = "None"
     str_type = Arguments.C_STR_INT_TYPE
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     str_result = cfmg_test._func_type_cast(str_type, x_value)
     self.func_test_equals( str_answer, str(str_result) )
Example #9
0
 def test_func_type_cast_for_string( self ):
     """ Test func_type_case for bool string """
     x_answer = "string"
     str_value = "string"
     str_type = Arguments.C_STR_STRING_TYPE
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     x_result = cfmg_test._func_type_cast(str_type, str_value)
     self.func_test_equals( x_answer, str(x_result) )
Example #10
0
 def test_func_type_cast_for_list( self ):
     """ Test func_type_case for list """
     x_answer = sorted([1,1.22,"hello",[]])
     str_value = '[[],"hello",1,1.22]'
     str_type = Arguments.C_STR_LIST_TYPE
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     x_result = sorted(cfmg_test._func_type_cast(str_type, str_value))
     self.func_test_equals( x_answer, str(x_result) )
Example #11
0
 def test_func_normalize_argument_for_present_string( self ):
     """ Test func_normalize_argument for a string that is present """
     str_env = os.path.join(self.str_test_directory, "func_normalize_argument_for_present_string")
     str_answer = "copy"
     str_argument = "COPY"
     dict_args = {"COPY":"copy"}
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     str_result = cfmg_test.func_normalize_argument(str_argument, dict_args )
     self.func_test_equals( str_answer, str_result )
Example #12
0
 def init_vm(self):
     """init vm controller configuration. """
     self.vm_control = VMControl.VMController()
     self.vm_control.init_config()
     vmc = ConfigManager.ConfigManager()
     self.strace_log_max_lines = vmc.get('analyzer', 'max_strace_lines')
     self.strace_log_path = vmc.get('analyzer', 'strace_log_path')
     self.tshark_path = vmc.get('analyzer', 'tshark_path')
     self.tcpdump_log_path = vmc.get('analyzer', 'host_log_tcpdump')
Example #13
0
    def test_SimpleConfig(self):
        import os

        cm = ConfigManager(os.path.expanduser("~/Desktop/Configs"))
        if "testDMC" not in cm.list_configs():
            print(cm.list_configs())
            cm.add_config("testDMC", walkers = 1000)
        cf = cm.load_config("testDMC")
        self.assertEquals(cf.walkers, 1000)
Example #14
0
 def testCompareDicts(self):
     cm = ConfigManager.ConfigManager('testCompareDicts.JSON')
     cm.set_key_values(self.key_list, self.value_list)
     saved_values = cm.get_key_values(self.key_list)
     new_dict = dict()
     for index in range(0, len(self.key_list)):
         new_dict[self.key_list[index]] = saved_values[index]
     self.assertEqual(cm.compare_cfg_dict(new_dict), True)
     self.assertEqual(cm.compare_cfg_dict(self.sample_wrong_cfg), False)
Example #15
0
def connect():
    CONFIG = ConfigManager.ConfigManager('config.json')
    client = pymongo.MongoClient(CONFIG.get('host'), CONFIG.get('port'))
    db = client[CONFIG.get('db')]
    db.authenticate(CONFIG.get('user'), CONFIG.get('passwd'))
    collection = db[CONFIG.get('collection')]
    #for document in collection.find():
    #    pprint.pprint(document)
    #print("Count: ", collection.count())
    return collection
Example #16
0
	def showSavedConfiguration(self):
		home = os.environ.get("TESTERMAN_HOME")
		if not home:
			raise Exception("No Testerman installation found. Please check TESTERMAN_HOME.")

		cm = ConfigManager.ConfigManager()
		try:
			cm.read("%s/conf/testerman.conf" % home)
		except Exception, e:
			raise Exception("Unable to read saved configuration file: " + str(e))
Example #17
0
    def __init__(self):
        logging.basicConfig(level=logging.INFO)
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        # self.logger.setLevel(logging.INFO)

        self.logger.info('Initializing XFE')
        self.xfe_config = ConfigManager.ConfigManager()
        self.logger.debug('API key: %s', self.xfe_config.get_api_key())
        self.logger.debug('API pass: %s', self.xfe_config.get_api_pass())
Example #18
0
 def test_func_normalize_argument_for_empty_string( self ):
     """ Test func_normalize_argument for an empty string """
     str_env = os.path.join(self.str_test_directory,
                            "func_normalize_argument_for_empty_string")
     str_argument = ""
     dict_args = {}
     cfmg_test = ConfigManager.ConfigManager(self.str_config_default)
     try:
         cfmg_test.func_normalize_argument(str_argument,dict_args)
         self.assertTrue(False)
     except:
         self.assertTrue(True)
Example #19
0
    def setKeymap(self, identifier, ttl, keymap=None, filter=None):
        if keymap:
            try:
                keys = keymap.map[identifier.upper()]
            except KeyError:
                keys = {}
        else:
            try:
                keys = self.parent.menu.keymap.map[identifier.upper()]
            except KeyError:
                keys = {}
        keyData = {}
        menuData = {}
        for refName in defaultKeymap.defaultKeymap[identifier.upper()].keys():
            title = menuItemsDic.getValueString(refName)
            prefix = ""
            if refName.startswith("TC_"):
                prefix = _("ツイキャス")
            elif refName.startswith("SPACES_"):
                prefix = _("Twitter スペース")
            if prefix:
                title = prefix + ":" + title
            if refName in keys:
                keyData[title] = keys[refName]
            else:
                keyData[title] = _("なし")
            menuData[title] = refName

        entries = []
        for map in (self.parent.menu.keymap, self.parent.hotkey):
            for i in map.entries.keys():
                if identifier.upper() != i:  #今回の変更対象以外のビューのものが対象
                    entries.extend(map.entries[i])
        d = views.globalKeyConfig.Dialog(keyData, menuData, entries, filter)
        d.Initialize(ttl)
        if d.Show() == wx.ID_CANCEL: return False

        result = {}
        keyData, menuData = d.GetValue()

        #キーマップの既存設定を置き換える
        newMap = ConfigManager.ConfigManager()
        newMap.read(constants.KEYMAP_FILE_NAME)
        for name, key in keyData.items():
            if key != _("なし"):
                newMap[identifier.upper()][menuData[name]] = key
            else:
                newMap[identifier.upper()][menuData[name]] = ""
        if newMap.write() != errorCodes.OK:
            errorDialog(
                _("設定の保存に失敗しました。下記のファイルへのアクセスが可能であることを確認してください。") + "\n" +
                os.path.abspath(constants.KEYMAP_FILE_NAME))
        return True
Example #20
0
 def test_func_get_postcommands_for_many_command( self ):
     """ Test func_get_postcommands for many postcommands """
     str_env = os.path.join(self.str_test_directory, "func_get_postcommands_for_many_command")
     str_config_file = os.path.join(str_env, self.str_config_default_3)
     self.func_make_dummy_dir( str_env )
     x_answer = "1. postcommand\n2. postcommand"
     self.func_create_test_config(str_config_file, self.str_config_3_content)
     cfmg_test = ConfigManager.ConfigManager(str_config_file)
     x_result = cfmg_test.func_get_postcommands()
     self.func_delete_test_config(str_config_file)
     self.func_remove_dirs([str_env])
     self.func_test_equals(str(x_answer), str(x_result))
Example #21
0
    def init_config(self):
        """ Init Guest VM from configuration file. """

        vmc = ConfigManager.ConfigManager()
        self.name = vmc.get('guest_vm', 'name')
        self.user = vmc.get('guest_vm', 'username')
        self.password = vmc.get('guest_vm', 'password')
        self.runpath = vmc.get('guest_vm', 'runpath')
        self.vm_log_path = vmc.get('guest_vm', 'vm_log_path')
        self.guest_analyzer_path = vmc.get('guest_vm', 'guest_analyzer_path')
        self.host_log_path = vmc.get('guest_vm', 'host_log_path')
        self.host_log_tcpdump = vmc.get('guest_vm', 'host_log_tcpdump')
        self.vm_log_tcpdump = vmc.get('guest_vm', 'vm_log_tcpdump')
Example #22
0
 def test_func_update_script_for_an_update_append(self):
     """ Test func_update_script_path for an update and an intial path. """
     str_env = os.path.join(self.str_test_directory, "func_update_script_for_an_update")
     str_config_file = os.path.join(str_env, self.str_config_default_2)
     self.func_make_dummy_dir(str_env)
     str_script = "root"
     x_answer = "/script/path/root"
     self.func_create_test_config(str_config_file, self.str_config_2_content)
     cfmg_test = ConfigManager.ConfigManager(str_config_file)
     x_result = cfmg_test.func_update_script_path(str_script)
     self.func_delete_test_config(str_config_file)
     self.func_remove_dirs([str_env])
     self.func_test_equals(str(x_answer), str(x_result))
Example #23
0
 def test_func_update_script_for_false(self):
     """ Test func_update_script_path for no update """
     str_env = os.path.join(self.str_test_directory, "func_update_script_for_false")
     str_config_file = os.path.join(str_env, self.str_config_default)
     self.func_make_dummy_dir(str_env)
     str_script = ""
     x_answer = str_script
     self.func_create_test_config(str_config_file, self.str_config_content)
     cfmg_test = ConfigManager.ConfigManager(str_config_file)
     x_result = cfmg_test.func_update_script_path(str_script)
     self.func_delete_test_config(str_config_file)
     self.func_remove_dirs([str_env])
     self.func_test_equals(str(x_answer), str(x_result))
Example #24
0
    def contains_meat(self):
        '''
        Determines if the recipe contains meat.
        :return: Boolean that says whether the current recipe contains meat or not.
        '''

        manager = cm.ConfigManager()
        meat_set = manager.load_meat_ingredients()

        for ing in self.ingredients:
            if ing.name in meat_set:
                return True

        return False
Example #25
0
    def transform_healthy(self):
        '''
        Transforms the recipe to be more healthy.
        :return: The transformed recipe. A dictionary mapping original ingredients to their substitution/scaled version.
        '''

        # Make a copy of the current recipe
        transformed_recipe = copy.deepcopy(self)

        # Init dictionary of substitutions that are actually performed by the transformation
        actual_substitutions = {}

        for orig_ing in self.ingredients:
            if orig_ing.name in SUB['to_healthy']:

                # Get a list of all possible substitutions for this ingredient
                substitution_candidates = copy.deepcopy(
                    SUB['to_healthy'][orig_ing.name])

                # Remove all candidates that already exist within the recipe
                valid_candidates = []
                ingredient_names = [
                    ing.name for ing in transformed_recipe.ingredients
                ]
                for candidate in substitution_candidates:
                    if candidate not in ingredient_names:
                        valid_candidates.append(candidate)

                # Pick a new ingredient to substitute in
                if len(valid_candidates) > 0:
                    new_ing_name = random.choice(valid_candidates)

                    # Perform the ingredient substitution
                    transformed_recipe.substitute_ingredients(
                        orig_ing, new_ing_name)

                    # make a note of which ingredient was substituted for what (so we can report that to the user)
                    actual_substitutions[orig_ing.name] = new_ing_name

        # Half the amount of condiments or unhealthy spices/herbs
        manager = cm.ConfigManager()
        unhealthy_ingredients_set = manager.load_unhealthy_ingredients()

        for ing in transformed_recipe.ingredients:
            if ing.name in unhealthy_ingredients_set:
                old_ing = copy.deepcopy(ing)
                ing.scale(0.5)
                actual_substitutions[old_ing.__str__()] = ing.__str__()

        return transformed_recipe, actual_substitutions
Example #26
0
 def get():
     config = ConfigManager()
     config["general"] = {
         "language": "ja-JP",
         "fileVersion": "101",
         "locale": "ja-JP",
         "update": True,
         "timeout": 5,
         "log_level": "0",
     }
     config["view"] = {
         "font": "bold 'MS ゴシック' 22 windows-932",
         "colorMode": "normal"
     }
     config["speech"] = {"reader": "AUTO"}
     config["mainView"] = {
         "sizeX": "800",
         "sizeY": "600",
     }
     config["player"] = {
         "outputDevice": "default",
         "startupPlayMode": "normal",
         "skipInterval": "30",
         "fadeOutOnExit": False,
         "fileInterrupt": "play",
         "playlistInterrupt": "open",
         "manualSongFeed": False,
         "startupPlaylist": ""
     }
     config["volume"] = {
         "default": "50",
     }
     config["notification"] = {
         "sound": True,
         "errorSound": True,
         "outputDevice": "same",
         "ignoreError": False
     }
     config["network"] = {
         "manual_proxy": False,
         "proxy_server": "",
         "proxy_port": 8080,
         "user_name": "",
         "software_key": "",
         "ctrl_client": True
     }
     config["filter_types"] = {}
     config["filter_patterns"] = {}
     return config
Example #27
0
 def test_func_update_python_path(self):
     """ Test func_update_python_path """
     str_env = os.path.join(self.str_test_directory, "func_update_python_path")
     str_config_file = os.path.join(str_env, self.str_config_default)
     self.func_make_dummy_dir(str_env)
     self.func_create_test_config(str_config_file, self.str_config_content)
     str_add_path = os.sep.join(["", "python", "path"])
     str_restore = self.func_prep_environ_parameter("PYTHONPATH")
     str_answer = os.environ[ "PYTHONPATH" ] + ":" + str_add_path
     cfmg_test = ConfigManager.ConfigManager(str_config_file)
     cfmg_test.func_update_python_path()
     str_result = os.environ[ "PYTHONPATH" ]
     self.func_restore_environ_parameter("PYTHONPATH",str_restore)
     self.func_delete_test_config(str_config_file)
     self.func_remove_dirs([str_env])
     self.func_test_equals(str_answer, str_result)
Example #28
0
 def get():
     config = ConfigManager()
     loc = locale.getdefaultlocale()[0].replace("_", "-")
     if loc == "en-US":
         font = "Bold 'times new roman' 22 windows-1252"
     if loc == "ja-JP":
         font = "bold 'MS ゴシック' 22 windows-932"
     config["general"] = {
         "language": "",
         "fileVersion": "100",
         "locale": loc,
         "update": True
     }
     config["view"] = {"font": font, "colorMode": 1}
     config["speech"] = {"reader": "AUTO"}
     config["mainView"] = {}
     return config
Example #29
0
 def get():
     config = ConfigManager()
     config["general"] = {
         "language": "ja-JP",
         "fileVersion": "100",
         "locale": "ja-JP",
         "autoHide": False,
         "minimizeOnExit": True,
     }
     config["view"] = {
         "font": "bold 'MS ゴシック' 22 windows-932",
         "colorMode": "normal"
     }
     config["speech"] = {"reader": "AUTO"}
     config["mainView"] = {
         "sizeX": "800",
         "sizeY": "600",
     }
     config["notification"] = {
         "baloon": True,
         "record": True,
         "openBrowser": False,
         "sound": False,
         "soundFile": "notification.ogg",
     }
     config["twitcasting"] = {
         "enable": False,
         "saveComments": False,
     }
     config["spaces"] = {
         "enable": False,
     }
     config["record"] = {
         "dir": "output\\%source%",
         "createSubDir": True,
         "subDirName": "%user%",
         "fileName": "%user%_%year%%month%%day%_%hour%%minute%%second%",
         "extension": "ts",
     }
     config["proxy"] = {
         "useManualSetting": False,
         "server": "",
         "port": 8080
     }
     return config
Example #30
0
    def get():
        config = ConfigManager()
        config["general"] = {
            "language": "ja-JP",
            "fileVersion": "100",
            "locale": "ja-JP"
        }
        config["view"] = {
            "font": "bold 'MS ゴシック' 22 windows-932",
            "colorMode": "normal"
        }
        config["speech"] = {"reader": "AUTO"}
        config["mainView"] = {
            "sizeX": "800",
            "sizeY": "600",
        }

        return config