当前位置: 首页>>代码示例>>Python>>正文


Python Utils.Utils类代码示例

本文整理汇总了Python中Utils.Utils的典型用法代码示例。如果您正苦于以下问题:Python Utils类的具体用法?Python Utils怎么用?Python Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

 def post(self):
     # input
     in_json_data = request.json
     departure_time = in_json_data["departure_time"]
     arrival_time = in_json_data["arrival_time"]
     buffer_time = in_json_data["buffer_time"]
     location_flow = in_json_data["location_flow"]
     mode = in_json_data["mode"]
     # operation
     mode_obj = Mode(mode=mode, valid_mode_list=self.mode_list)
     google_api_obj = GoogleAPI(mode=mode_obj.get_mode(),
                                departure_time=datetime.datetime.now(),
                                buffer_time=buffer_time,
                                location_flow=location_flow,
                                units=None)
     proc_json_data = google_api_obj.get_google_matrix_api(api_key=self.config_obj.get_api_key_google_matrix())
     # output
     arrival_calculated_date_obj = Utils.convert_str_2_dateobj(departure_time) + \
                                   datetime.timedelta(
                                       seconds=proc_json_data["rows"][0]["elements"][0]["duration_in_traffic"]["value"]) + \
                                   datetime.timedelta(hours=buffer_time[0],
                                                      minutes=buffer_time[1],
                                                      seconds=buffer_time[2])
     arrival_expected_date_obj = Utils.convert_str_2_dateobj(arrival_time)
     if arrival_calculated_date_obj >= arrival_expected_date_obj:
         out_json = {"wake_status": True,
                     "journey_duration": proc_json_data["rows"][0]["elements"][0]["duration_in_traffic"]["value"],
                     "estimated_arrival_time": str(arrival_calculated_date_obj)}
                     #"estimated_wakeup_time": str(wakeup_calculated_date_obj)}
     else:
         out_json = {"wake_status": False,
                     "journey_duration": proc_json_data["rows"][0]["elements"][0]["duration_in_traffic"]["value"],
                     "estimated_arrival_time": str(arrival_calculated_date_obj)}
                     #"estimated_wakeup_time": str(wakeup_calculated_date_obj)}
     return out_json
开发者ID:sudhishkr,项目名称:SudTrafficAlarm,代码行数:35,代码来源:AlarmBackendAPI.py

示例2: log_connected

    def log_connected(self, conn):
        Utils.expects_type(NaptConnection, conn, 'conn')

        log     = None

        with conn.lock:
            status  = conn.tag
            protocol= status.protocol_setting
            c_remote= conn.client.socket.getpeername()
            c_local = conn.client.socket.getsockname()
            s_remote= conn.server.socket.getpeername()
            s_local = conn.server.socket.getsockname()
            log     = self.create_log(conn.id, 'connect', {
                'protocol': protocol.name,
                'client': {
                    'remote':   { 'address': c_remote[0], 'port': c_remote[1] }, 
                    'local':    { 'address': c_local[0],  'port': c_local[1] },
                },
                'server': {
                    'remote':   { 'address': s_remote[0], 'port': s_remote[1] },
                    'local':    { 'address': s_local[0],  'port': s_local[1] }
                }
            })

        self.append_log(log)

        if( self.elastic != None ) :
            self.elastic.store( log )
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:28,代码来源:NaptLogger.py

示例3: infer_decisions

 def infer_decisions(self, tree, train_list, parse, prefix_terminals):
     """
     create training data given the label data
     :param tree: the
     :param train_list: the list of training examples
     :param parse: a parse string
     :param prefix_terminals: the t-1 turn terminal action sequences
     :return:
     """
     cur_label = Utils.node_label(tree)
     if type(tree) is not Tree:
         if len(prefix_terminals) > 0:
             if cur_label == prefix_terminals[0]:
                 prefix_terminals.remove(cur_label)
             elif not self.parser.is_dummy(cur_label):
                 print "WHAT!!!"
         parse.append(cur_label)
         return
     parse.append('(')
     parse.append(cur_label)
     if len(prefix_terminals) == 0 and cur_label in self.parser.train_set.keys():
             children = [Utils.node_label(node) for node in tree]
             train_list.append({"lhs": cur_label, "rhs": children, 'parse': Utils.clean_parse(' '.join(parse))})
     for node in tree:
         self.infer_decisions(node, train_list, parse, prefix_terminals)
     parse.append(')')
开发者ID:snakeztc,项目名称:DialogParser,代码行数:26,代码来源:LogEditor.py

示例4: do_stop

    def do_stop(self):
        Utils.assertion(self.lock.locked(), 'need lock')

        if self.thread is None:
            raise Exception()   # InvalidOperationException()

        self.running= False
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:7,代码来源:SocketPoller.py

示例5: recv

    def recv(self, so):
        Utils.expects_type(NaptSocket, so, 'so')

        if so.is_client:
            self.recv_client()
        else:
            self.recv_server()
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:7,代码来源:NaptConnection.py

示例6: summaryStatistics

	def summaryStatistics(self, network):
		""" Creates a text file of summary statistics that may be useful
		to presenting to preliminary meetings with our advisors/sponsors.

		"""

		flights = network.countTotalBookedPerFlight()
		networkData = [sum(flights[key].values()) for key in flights.keys()]
		networkSeries = pd.Series(networkData).describe()
		edgeData = {}

		for flight, data in flights.items():
			org_des = flight[2:]
			edgeData[org_des] = edgeData.get(org_des, [])
			edgeData[org_des].append(sum(data.values()))

		with open('ICF_Summary_Statistics.txt', 'w') as f:
			f.write('Network Summary\n')
			Utils.writeSeriesToFile(f, networkSeries, indent='	')

			f.write('\nRoute Summaries\n\n')
			for org_des, booked in edgeData.items():
				f.write(org_des[0] + ' -> ' + org_des[1] + '\n')
				statsSeries = pd.Series(booked).describe()
				Utils.writeSeriesToFile(f, statsSeries, indent='	')
				f.write('\n')
开发者ID:kmcconnaughay,项目名称:ICF-Project,代码行数:26,代码来源:Visualizer.py

示例7: comparator

 def comparator(self, a, b):
     if len(a) < len(b):
         return -1
     elif len(a) > len(b):
         return 1
     else:
         return Utils.seqLength(a) - Utils.seqLength(b)
开发者ID:ragib06,项目名称:pymsgsp,代码行数:7,代码来源:test_pymsgsp.py

示例8: do_poll

    def do_poll(self):
        empty       = True

        with self.lock:
            empty = len(self.descripters) == 0

        try:
            if(empty):
                time.sleep(self.timeout)
                return

            status = self.poller.poll(self.timeout)

            for fd, pollflag in status:
                flag    = (SocketPollFlag.Read  if bool(pollflag & select.EPOLLIN)  else SocketPollFlag.Zero) \
                        | (SocketPollFlag.Write if bool(pollflag & select.EPOLLOUT) else SocketPollFlag.Zero) \
                        | (SocketPollFlag.Error if bool(pollflag & select.EPOLLERR) else SocketPollFlag.Zero)

                #print('  signaled fd: %d' % fd, flush=True)

                fd_obj = self.fd_map[fd]

                self.invoke_callback(fd_obj, flag)
        except Exception as ex:
            # ThreadInterruptedException
            # Exception
            Utils.print_exception(ex)

            self.running = False
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:29,代码来源:SocketPoller.py

示例9: main

def main():
    projectName="";
    dir = "";
    groupId="";
    counter = 1;

    if(len(sys.argv) == 2):
        if(sys.argv[1] == "--help"):
            Utils.helpOutput();
            exit(0);
    else:
        for arg in sys.argv [1:]:
            if (arg == "--projectName"):
                projectName = sys.argv[counter+1];
            elif (arg == "--groupId"):
                groupId = sys.argv[counter+1];
            elif (arg == "--directory"):
                dir = sys.argv[counter+1];
            counter+=1;

    ScriptMonitor.message("********************************************");
    ScriptMonitor.message("Maven Project Builder")
    ScriptMonitor.message("********************************************");
    ScriptMonitor.message("projectName = "+projectName);
    ScriptMonitor.message("groupId = "+groupId);
    ScriptMonitor.message("projectDir = "+dir);
    projectGenerator = ProjectGenerator();
    projectGenerator.createProject(dir, projectName, groupId);
开发者ID:raheal,项目名称:template-104,代码行数:28,代码来源:run.py

示例10: run

 def run(self):
     print "Preparing the environment"
     self.prepareEnvironment()
     print "Reading in the training data"
     imageCollections = data_io.get_train_df()
     wndchrmWorker = WndchrmWorkerTrain()
     print "Getting features"
     if not self.loadWndchrm: #Last wndchrm set of features
         featureGetter = FeatureGetter()
         fileName = data_io.get_savez_name()
         if not self.load: #Last features calculated from candidates
             (namesObservations, coordinates, train) = Utils.calculateFeatures(fileName, featureGetter, imageCollections)
         else:
             (namesObservations, coordinates, train) = Utils.loadFeatures(fileName)
         print "Getting target vector"
         (indexes, target, obs) = featureGetter.getTargetVector(coordinates, namesObservations, train)
         print "Saving images"
         imageSaver = ImageSaver(coordinates[indexes], namesObservations[indexes],
                                 imageCollections, featureGetter.patchSize, target[indexes])
         imageSaver.saveImages()
         print "Executing wndchrm algorithm and extracting features"
         (train, target) = wndchrmWorker.executeWndchrm()
     else:
         (train, target) = wndchrmWorker.loadWndchrmFeatures()
     print "Training the model"
     model = RandomForestClassifier(n_estimators=500, verbose=2, n_jobs=1, min_samples_split=30, random_state=1, compute_importances=True)
     model.fit(train, target)
     print model.feature_importances_
     print "Saving the classifier"
     data_io.save_model(model)
开发者ID:koshkabb,项目名称:MitosisDetection,代码行数:30,代码来源:Trainer.py

示例11: do_select

    def do_select(self):
        empty   = True
        owner   = self.owner

        with owner.lock:
            owner.read_sockets.clear()
            owner.write_sockets.clear()
            owner.error_sockets.clear()
            owner.update_select_sockets()

            empty   = len(owner.read_sockets) == 0 \
                  and len(owner.write_sockets) == 0 \
                  and len(owner.error_sockets) == 0

        try:
            if(empty):
                time.sleep(owner.timeout)
                return

            read, write, error = select.select(owner.read_sockets, owner.write_sockets, owner.error_sockets, owner.timeout)

            for i in read:
                owner.do_recv(i)

            for i in write:
                owner.do_send(i)

            for i in error:
                owner.do_error(i)
        except Exception as ex:
            # ThreadInterruptedException
            # Exception
            Utils.print_exception(ex)
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:33,代码来源:SocketSelector.py

示例12: log_recv

    def log_recv(self, conn, data, offset, size):
        Utils.expects_type(NaptConnection, conn, 'conn')

        size2   = size
        size2   = 256 if size2 > 256 else size2
        log     = None
        store_data   = data[0:size2]

        with conn.lock:
            status  = conn.tag
            protocol= status.protocol_setting
            c_remote= conn.client.socket.getpeername()
            c_local = conn.client.socket.getsockname()

            log     = self.create_log(conn.id, 'recv', {
                'protocol': protocol.name,
                'packet_size':      size,
                'packet':           Utils.get_string_from_bytes(store_data, 'charmap'),
                'sha1':             hashlib.sha1(store_data).hexdigest(),
                'client': {
                    'remote':   { 'address': c_remote[0], 'port': c_remote[1] }, 
                    'local':    { 'address': c_local[0],  'port': c_local[1] },
                }
                #'packet':           Utils.get_string_from_bytes(data[0:size2], 'ascii')
                #'packet':           Utils.get_escaped_string(data[0:size2])
            })

        if( (self.elastic != None) and ('Telnet' not in protocol.name) ) :
            self.append_log(log)
            self.elastic.store( log )
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:30,代码来源:NaptLogger.py

示例13: log_close

    def log_close(self, conn):
        Utils.expects_type(NaptConnection, conn, 'conn')

        log     = None

        with conn.lock:
            log     = self.create_log(conn.id, 'close')
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:7,代码来源:NaptLogger.py

示例14: timeout

    def timeout(self, conn):
        Utils.expects_type(NaptConnection, conn, 'conn')

        status      = conn.tag;
        port        = status.PortSetting;
        protocol    = self.protocolt_settings.find(port.default_protocol)

        self.connect(conn, protocol)
开发者ID:rainforest-tokyo,项目名称:AutoNaptPython,代码行数:8,代码来源:AutoNapt.py

示例15: to_row

 def to_row(self):
   end_time = Utils.datefmt(self.end_time) if self.end_time is not None else "-"
   start_time = Utils.datefmt(self.start_time)
   duration = Utils.hourstohuman(self.duration)
   cwd = self.cwd if hasattr(self, 'cwd') else "-"
   if not hasattr(self, 'commit_info'):
     self.commit_info = self.getGitInfo()
   return ["",start_time,end_time,duration,cwd,self.commit_info]
开发者ID:mbenitezm,项目名称:taskr,代码行数:8,代码来源:WorkSession.py


注:本文中的Utils.Utils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。