• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.Util类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _is_ip_internal

 def _is_ip_internal(self,ip, ranges):
     result = 0
     for row in ranges:
         if Util.ip_to_int(ip) >= row[0] and Util.ip_to_int(ip) <= row[1]: 
             result = 1
             break
     return result
开发者ID:cgiraldo,项目名称:incubator-spot,代码行数:7,代码来源:flow_oa.py


示例2: prepare

    def prepare(self, word_type):
        """
        Generates trie structure containing all words from clp
        :param word_type: part of speech of which kind read words from clp data
        :return: None
        """
        old = ""
        index = 0
        keys = []
        values = []
        for i in range(16777231, 18663982):
            if Util.is_word_unneeded(i):
                continue
            if Util.is_word_appropriate_type(self.plp.label(i)[0], word_type):
                continue
            form = self.plp.bform(i)

            if old != form:
                for s in self.plp.forms(i):
                    if len(s) > 0:
                        a = Util.substring(s, form)
                        to_remove = s[len(a): len(s)]
                        to_add = form[len(a): len(form)]
                        keys.append(Util.reverse(s))
                        a = unicode(to_remove).encode('utf-8')
                        b = unicode(to_add).encode('utf-8')
                        values.append((a, b))
                index += 1

            old = self.plp.bform(i)
        return zip(keys, values)
开发者ID:mslawin,项目名称:Magisterka,代码行数:31,代码来源:stemmer.py


示例3: _get_dns_results

    def _get_dns_results(self):

        self._logger.info("Getting {0} Machine Learning Results from HDFS".format(self._date))
        dns_results = "{0}/dns_results.csv".format(self._data_path)

        # get hdfs path from conf file.
        HUSER = self._oni_conf.get('conf','HUSER').replace("'","").replace('"','')   
        hdfs_path = "{0}/dns/scored_results/{1}/scores/dns_results.csv".format(HUSER,self._date)

        # get results file from hdfs.
        get_command = Util.get_ml_results_form_hdfs(hdfs_path,self._data_path)
        self._logger.info("{0}".format(get_command))

         # valdiate files exists
        if os.path.isfile(dns_results):

            # read number of results based in the limit specified.
            self._logger.info("Reading {0} dns results file: {1}".format(self._date,dns_results))
            self._dns_results = Util.read_results(dns_results,self._limit,self._results_delimiter)[:]
            if len(self._dns_results) == 0: self._logger.error("There are not flow results.");sys.exit(1)

        else:
            self._logger.error("There was an error getting ML results from HDFS")
            sys.exit(1)

        # add headers.        
        self._logger.info("Adding headers")
        self._dns_scores_headers = [  str(key) for (key,value) in self._conf['dns_score_fields'].items() ]

        # add dns content.
        self._dns_scores = [ conn[:]  for conn in self._dns_results][:]       
开发者ID:Open-Network-Insight,项目名称:oni-oa,代码行数:31,代码来源:dns_oa.py


示例4: _initialize_members

    def _initialize_members(self,date,limit,logger):
        
        # get logger if exists. if not, create new instance.
        self._logger = logging.getLogger('OA.Flow') if logger else Util.get_logger('OA.Flow',create_file=False)

        # initialize required parameters.
        self._scrtip_path = os.path.dirname(os.path.abspath(__file__))
        self._date = date
        self._table_name = "flow"
        self._flow_results = []
        self._limit = limit
        self._data_path = None
        self._ipynb_path = None
        self._ingest_summary_path = None
        self._flow_scores = []
        self._results_delimiter = '\t'

        # get app configuration.
        self._oni_conf = Util.get_oni_conf()  

        # get scores fields conf
        conf_file = "{0}/flow_conf.json".format(self._scrtip_path)
        self._conf = json.loads(open (conf_file).read(),object_pairs_hook=OrderedDict)     
 
        # initialize data engine
        self._db = self._oni_conf.get('conf','DBNAME').replace("'","").replace('"','') 
        self._engine = Data(self._db, self._table_name,self._logger)
开发者ID:Open-Network-Insight,项目名称:oni-oa,代码行数:27,代码来源:flow_oa.py


示例5: _get_flow_results

    def _get_flow_results(self):
               
        self._logger.info("Getting {0} Machine Learning Results from HDFS".format(self._date))
        flow_results = "{0}/flow_results.csv".format(self._data_path)

        # get hdfs path from conf file 
        HUSER = self._spot_conf.get('conf', 'HUSER').replace("'", "").replace('"', '')
        hdfs_path = "{0}/flow/scored_results/{1}/scores/flow_results.csv".format(HUSER,self._date)
        
         # get results file from hdfs
        get_command = Util.get_ml_results_form_hdfs(hdfs_path,self._data_path)
        self._logger.info("{0}".format(get_command))

        # valdiate files exists
        if os.path.isfile(flow_results):

            # read number of results based in the limit specified.
            self._logger.info("Reading {0} flow results file: {1}".format(self._date,flow_results))
            self._flow_results = Util.read_results(flow_results,self._limit,self._results_delimiter)
            if len(self._flow_results) == 0: self._logger.error("There are not flow results.");sys.exit(1)

        else:
            self._logger.error("There was an error getting ML results from HDFS")
            sys.exit(1)

        # filter results add rank.
        self._logger.info("Filtering required columns based on configuration")

        self._flow_scores.extend([ [ conn[i] for i in self._conf['column_indexes_filter'] ] + [n] for n, conn in enumerate(self._flow_results) ])
开发者ID:cgiraldo,项目名称:incubator-spot,代码行数:29,代码来源:flow_oa.py


示例6: _get_flow_results

    def _get_flow_results(self):
               
        self._logger.info("Getting {0} Machine Learning Results from HDFS".format(self._date))
        flow_results = "{0}/flow_results.csv".format(self._data_path)

        # get hdfs path from conf file 
        HUSER = self._oni_conf.get('conf','HUSER').replace("'","").replace('"','')   
        hdfs_path = "{0}/flow/scored_results/{1}/scores/flow_results.csv".format(HUSER,self._date)
               
        # get results file from hdfs
        get_command = Util.get_ml_results_form_hdfs(hdfs_path,self._data_path)
        self._logger.info("{0}".format(get_command))

        # valdiate files exists
        if os.path.isfile(flow_results):

            # read number of results based in the limit specified.
            self._logger.info("Reading {0} flow results file: {1}".format(self._date,flow_results))
            self._flow_results = Util.read_results(flow_results,self._limit,self._results_delimiter)
            if len(self._flow_results) == 0: self._logger.error("There are not flow results.");sys.exit(1)

        else:
            self._logger.error("There was an error getting ML results from HDFS")
            sys.exit(1)

        # add headers.        
        self._logger.info("Adding headers based on configuration file: score_fields.json")
        self._flow_scores = [ [ str(key) for (key,value) in self._conf['flow_score_fields'].items()] ]

        ldaab_index = self._conf["flow_results_fields"]["lda_score_ab"]
        ldaba_index = self._conf["flow_results_fields"]["lda_score_ba"]

        # filter results add sev and rank.
        self._logger.info("Filtering required columns based on configuration")
        self._flow_scores.extend([ [0] +  [ conn[i] for i in self._conf['column_indexes_filter'] ] + [(conn[ldaab_index] if (conn[ldaab_index]<= conn[ldaba_index]) else conn[ldaba_index])] + [n]  for n, conn in enumerate(self._flow_results) ])
开发者ID:Open-Network-Insight,项目名称:oni-oa,代码行数:35,代码来源:flow_oa.py


示例7: view

	def view(self):
		Util.setup3d()

		self.drawMap()
		self.drawModel()

		glFlush()
		glutSwapBuffers()
开发者ID:quintenpalmer,项目名称:squatgame,代码行数:8,代码来源:MainMenuView.py


示例8: _create_flow_scores_csv

    def _create_flow_scores_csv(self):

        flow_scores_csv = "{0}/flow_scores.csv".format(self._data_path)
        Util.create_csv_file(flow_scores_csv,self._flow_scores)

        # create bk file
        flow_scores_bu_csv = "{0}/flow_scores_bu.csv".format(self._data_path)
        Util.create_csv_file(flow_scores_bu_csv,self._flow_scores)  
开发者ID:Open-Network-Insight,项目名称:oni-oa,代码行数:8,代码来源:flow_oa.py


示例9: draw

def draw():
	Util.setup2D()

	glColor(.1,.1,.5)
	glRectf(0,Model.getWinfo().h/2,Model.getWinfo().w,Model.getWinfo().h)
	glColor(.1,.5,.1)
	glRectf(0,0,Model.getWinfo().w,Model.getWinfo().h/2)

	Util.finish2D()
开发者ID:quintenpalmer,项目名称:squatgame,代码行数:9,代码来源:Background.py


示例10: sign_for_jspay

 def sign_for_jspay(self, prepay_id):
     """jssdk调起支付时需要的sign"""
     timestamp = Util.timestamp()
     nonce_str = Util.generate_nonce(15)
     package = 'prepay_id=%s' % prepay_id
     sign_type = 'MD5'
     pay_sign = self._generate_sign(appId=self._appid, timeStamp=timestamp,
                             nonceStr=nonce_str, package=package, signType=sign_type)
     return {'timestamp':timestamp, 'nonceStr':nonce_str, 'package':package, 'signType':sign_type, 'paySign':pay_sign}
开发者ID:momingxu,项目名称:weixin-sdk,代码行数:9,代码来源:pay.py


示例11: motion

	def motion(self,x,y):
		turnh = -(x-Model.getMouseInfo().clickedx)/(Model.getWinfo().w*.31)
		turnv = (y-Model.getMouseInfo().clickedy)/(Model.getWinfo().w*.31)
		if Model.getMouseInfo().side == "left":
			Util.restoreCamera()
			Util.turnCamera(turnh,turnv)
		elif Model.getMouseInfo().side == "right":
			Util.restoreCamera()
			Util.turnCamera(turnh,turnv)
			Util.resetPlayer()
开发者ID:quintenpalmer,项目名称:squatgame,代码行数:10,代码来源:GameMotion.py


示例12: _create_dns_scores_csv

    def _create_dns_scores_csv(self):
        
        dns_scores_csv = "{0}/dns_scores.csv".format(self._data_path)
        dns_scores_final =  self._move_time_stamp(self._dns_scores)
        dns_scores_final.insert(0,self._dns_scores_headers)
        Util.create_csv_file(dns_scores_csv,dns_scores_final)   

        # create bk file
        dns_scores_bu_csv = "{0}/dns_scores_bu.csv".format(self._data_path)
        Util.create_csv_file(dns_scores_bu_csv,dns_scores_final)  
开发者ID:Open-Network-Insight,项目名称:oni-oa,代码行数:10,代码来源:dns_oa.py


示例13: change

 def change(self, name):
     if name == "maingame":
         self.horizontal = 0
         self.vertical = 0.25
         Util.resetCamera()
     elif name == "mainmenu":
         self.location = [30, 30, 0]
         self.lookAt = [-70, 10, 0]
         self.up = [0, 1, 0]
         self.horizon = 0
         self.vertical = -1.0
         self.distance = 50
开发者ID:quintenpalmer,项目名称:squatgame,代码行数:12,代码来源:Camera.py


示例14: draw

def draw():
	Util.setup2D()

	glColor(.15,.21,.41)
	barwidth = 400
	x1 = (Model.getWinfo().w/2)-(barwidth/2)
	x2 = (Model.getWinfo().w/2)+(barwidth/2)
	y1 = 20
	y2 = 50
	glRectf(x1,y1,x2,y2)

	Util.finish2D()
开发者ID:quintenpalmer,项目名称:squatgame,代码行数:12,代码来源:GameInterface.py


示例15: _generate_sign

 def _generate_sign(self, **kwargs):
     """
     签名算法,返回得到的签名字符串
     """
     valid_keys = [k for k in kwargs if kwargs[k] and k != 'sign']
     valid_keys.sort()
     kv_str = ''
     for k in valid_keys:
         kv_str += '%s=%s&' % (k, kwargs[k])
     kv_str += '%s=%s' % ('key', self._sign_key)
     kv_str = Util.encode_data(kv_str)
     sign = Util.md5(kv_str).upper()
     return sign
开发者ID:momingxu,项目名称:weixin-sdk,代码行数:13,代码来源:pay.py


示例16: view

	def view(self):
		Util.setup3d()
		Util.updateCamera()

		self.drawBackground()
		self.drawMap()
		self.drawModel(Model.getGame().getPlayer())
		self.drawOthers()
		self.drawTarget()
		self.drawInterface()

		glFlush()
		glutSwapBuffers()
开发者ID:quintenpalmer,项目名称:squatgame,代码行数:13,代码来源:GameView.py


示例17: unified_order

    def unified_order(self, trade_type, out_trade_no, body, total_fee, notify_url, **kwargs):
        """
        微信统一下单api(文档http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1)
        :param trade_type: 交易类型('JSAPI', 'APP', 'NATIVE')
        :param out_trade_no: 商户订单号,32个字符内
        :param body: 商品或支付简单描述
        :param total_fee: 金额(分),默认RMB,需要其他货币类型在kwargs内指定
        :param notify_url: 支付结果通知地址
        :return: 返回tuple(code, result), 统一下单结果
        """
        if not trade_type:
            raise WxPayError(u"缺少统一支付接口必填参数trade_type!")
        if not out_trade_no:
            raise WxPayError(u"缺少统一支付接口必填参数out_trade_no!")
        if not body:
            raise WxPayError(u"缺少统一支付接口必填参数body!")
        if not total_fee:
            raise WxPayError(u"缺少统一支付接口必填参数total_fee!")
        if not notify_url:
            raise WxPayError(u"异步通知url未设置")

        #检查ip
        if not kwargs.get('spbill_create_ip'):
            if trade_type == 'NATIVE':
                kwargs.update(spbill_create_ip=Util.get_local_ip())
            else:
                raise WxPayError(u'APP和网页支付需提交用户端ip')

        if trade_type == 'NATIVE':
            assert kwargs.get('product_id'), u'trade_type为NATIVE时,product_id为必填参数'
        elif trade_type == 'JSAPI':
            assert kwargs.get('openid'), u'trade_type为JSAPI时,openid为必填参数!'
        elif trade_type == 'APP':
            pass
        else:
            raise WxPayError(u"支付类型trade_type错误,为('JSAPI', 'APP', 'NATIVE')之一")

        kwargs.update(device_info='WEB')

        kwargs.update(appid=self._appid, mch_id=self._mchid)
        kwargs.update(trade_type=trade_type,
                      out_trade_no=out_trade_no,
                      body=body,
                      total_fee=total_fee,
                      notify_url=notify_url)
        kwargs.update(nonce_str=Util.generate_nonce(20))

        kwargs.update(sign=self._generate_sign(**kwargs)) #sign

        return self._post('/pay/unifiedorder', kwargs)
开发者ID:momingxu,项目名称:weixin-sdk,代码行数:50,代码来源:pay.py


示例18: find_basic_form

    def find_basic_form(self, strange_form):
        """
        Method finds basic form for given inflectional form
        :param strange_form: inflectional form of word
        :return: basic form of given word
        """
        similar_words = self.find_similar_words(strange_form)
        how_many_forms = dict()
        word_labels = dict()
        for word in similar_words:
            form = self.atergo_trie[word]
            if form[0] in how_many_forms:
                how_many_forms[form[0]] += 1
            else:
                how_many_forms[form[0]] = 1
            if not form[0] in word_labels:
                word_labels[form[0]] = []
            word_labels[form[0]].append(Util.reverse(word))
        max_form = max(how_many_forms.iteritems(), key=operator.itemgetter(1))[0]

        max_form0 = max_form[0].split('\x00')[0].decode('utf-8')
        max_form1 = max_form[1].split('\x00')[0].decode('utf-8')
        result = collections.namedtuple('result', ['basic_form', 'word_labels'])
        result.basic_form = strange_form[:len(strange_form) - len(max_form0)] + max_form1
        result.word_labels = word_labels[max_form]
        return result
开发者ID:mslawin,项目名称:Magisterka,代码行数:26,代码来源:stemmer.py


示例19: pack_news

 def pack_news(self, item_list):
     """
     回复图文消息
     :param item_list: 图文消息列表,每项是一个字典:{'title':'', 'description':'', 'picurl':'', 'url':''}
     :return: xml字符串
     """
     article_count = len(item_list)
     assert article_count in range(1, 11), 'news count should be in [1,10]'
     xml_data = '''
             <xml>
             <ToUserName><![CDATA[%s]]></ToUserName>
             <FromUserName><![CDATA[%s]]></FromUserName>
             <CreateTime>%s</CreateTime>
             <MsgType><![CDATA[news]]></MsgType>
             <ArticleCount>%s</ArticleCount>
             <Articles>
         ''' % (self.message.fromUserName, self.message.toUserName, Util.timestamp(), article_count)
     for item in item_list:
         item_xml = '''
                 <item>
                 <Title><![CDATA[%s]]></Title>
                 <Description><![CDATA[%s]]></Description>
                 <PicUrl><![CDATA[%s]]></PicUrl>
                 <Url><![CDATA[%s]]></Url>
                 </item>
             ''' % (item.get('title'), item.get('description'), item.get('picurl'), item.get('url'))
         xml_data += item_xml
     xml_data += "</Articles></xml>"
     return self._ensure_encrypt(xml_data)
开发者ID:momingxu,项目名称:weixin-sdk,代码行数:29,代码来源:public.py


示例20: GET

 def GET(self):
     util = Util()
     inputdata = web.input()
     if hasattr(inputdata, 'id'):
         lottery_id = inputdata.id
         item = util.getLottery(_id = inputdata.id)
         if item: return item.stringify()
         else: return web.notfound("lottery not found")
     else:
         ps = int(inputdata.ps) if hasattr(inputdata, 'ps') else 0
         pn = int(inputdata.pn) if hasattr(inputdata, 'pn') else 10
         pe = ps + pn - 1
         items = util.getAllLotteries(ps, pe)
         lottery_cnt = util.getLotteryCount()
         if not items is None: return '{' + '"data": [{0}], "ps": {1}, "pn": {2}, "total": {3}'.format(", ".join([i.stringify() for i in items]), ps, pn, lottery_cnt) + '}'
         else: return web.notfound("lotteries not found")
开发者ID:qqbot-pet-game,项目名称:lottery-statistics,代码行数:16,代码来源:main.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.Utils类代码示例发布时间:2022-05-26
下一篇:
Python utils.Timer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap