本文整理汇总了Python中utilities.Utilities类的典型用法代码示例。如果您正苦于以下问题:Python Utilities类的具体用法?Python Utilities怎么用?Python Utilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utilities类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: sendRequest
def sendRequest(self):
try:
self.params = [param.items()[0] for param in self.params];
params = urllib.urlencode(self.params);
Utilities.debug("Opening connection to "+self.base_url);
self.conn = httplib.HTTPConnection(self.base_url,80);
headers = {"User-Agent":self.getUserAgent(),
"Content-Type":"application/x-www-form-urlencoded",
"Accept":"text/json"
};
#Utilities.debug(headers);
#Utilities.debug(params);
self.conn.request("GET",self.req_file,params,headers);
resp=self.conn.getresponse()
response=resp.read();
#Utilities.debug(response);
self.done.emit(json.loads(response));
return json.loads(response);
except:
self.fail.emit()
开发者ID:MichaelShaka,项目名称:wazapp,代码行数:25,代码来源:wajsonrequest.py
示例2: close
def close(self):
"""
None -> None
Deletes residual files from the simulation
"""
Utilities.clean_retrosheet_files()
开发者ID:frahman5,项目名称:beatthestreak,代码行数:7,代码来源:simulation.py
示例3: generate
def generate(self):
def writeTweetAndGetNextTweet(tweet, tweetType, iterator):
# print tweetType, trainingTime, testTime
tweet["tweet_type"] = tweetType
Utilities.writeAsJsonToFile(tweet, self.outputCombinedFile)
return iterator.next()
trainingFileIterator = Utilities.iterateTweetsFromFileWithTerminatingNone(self.inputTrainingSetFile)
testFileIterator = Utilities.iterateTweetsFromFileWithTerminatingNone(self.inputTestSetFile)
trainingTweet, testTweet = trainingFileIterator.next(), testFileIterator.next()
trainingTime, testTime = None, None
while trainingTweet != None or testTweet != None:
if trainingTweet != None:
trainingTime = datetime.strptime(trainingTweet["created_at"], Settings.twitter_api_time_format)
if testTweet != None:
testTime = datetime.strptime(testTweet["created_at"], Settings.twitter_api_time_format)
if trainingTweet != None and testTweet != None:
if testTime < trainingTime:
testTweet = writeTweetAndGetNextTweet(testTweet, TweetType.test, testFileIterator)
else:
trainingTweet = writeTweetAndGetNextTweet(trainingTweet, TweetType.train, trainingFileIterator)
elif trainingTweet == None:
while testTweet != None:
testTweet = writeTweetAndGetNextTweet(testTweet, TweetType.test, testFileIterator)
else:
while trainingTweet != None:
trainingTweet = writeTweetAndGetNextTweet(trainingTweet, TweetType.train, trainingFileIterator)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:27,代码来源:datasets.py
示例4: to_xml
def to_xml(self, library=None):
d = self.to_dict()
res = "<book>\n"
for x in d:
if x == "authors":
if len(d["authors"]) > 0:
res = res + " <authors>\n"+ \
" <name>" + ("</name>\n <name>".join([Utilities.escape_xml(y) for y in d["authors"]])) + "</name>\n"+ \
" </authors>\n"
elif x == "categories" and library != None:
if len(d["categories"]) > 0:
res = res + " <categories>\n"
col = library.categories.collection
for i in d["categories"]:
res = res + \
" <item>\n" + \
" " + "".join(["<n color='" + col[y].color + "'>" + Utilities.escape_xml(col[y].name) + "</n>" for y in library.categories.get_full_category_ids(i)]) + "\n" +\
" </item>\n"
res = res + " </categories>\n"
elif x == "isbn10":
res = res + " <isbn10>" + ISBN.to_string(d["isbn10"], set_hyphen=False) + "</isbn10>\n"
elif x == "isbn13":
res = res + " <isbn13>" + ISBN.to_string(d["isbn13"], set_hyphen=False) + "</isbn13>\n"
elif d[x] != None:
res = res + " <" + x + ">" + Utilities.escape_xml(str(d[x])) + "</" + x + ">\n"
return res + "</book>\n"
开发者ID:koe-,项目名称:ebola,代码行数:27,代码来源:book.py
示例5: request
def request(self, method, url, data=[]):
if Iugu.getApiKey() is None:
Utilities.authFromEnv()
if Iugu.getApiKey() is None:
raise IuguAuthenticationException("Chave de API não configurada. Utilize Iugu.setApiKey(...) para configurar.")
headers = self.__defaultHeaders()
( response_body, response_code ) = self._requestWithCURL( method, url, headers, data )
try:
response = json.loads(response_body)
except ValueError:
raise IuguObjectNotFound(response_body)
if response_code == 404:
raise IuguObjectNotFound(response_body)
if response.errors is not None:
if type(response.errors) != "str" and len(response.errors) == 0:
response.errors = None
elif type(response.errors) != "str" and len(response.errors) > 0:
response.errors = response.errors
if response.errors is not None and type(response.errors) == "str":
response.errors = response.errors
iugu_last_api_response_code = response_code
return response
开发者ID:ararog,项目名称:iugu-python,代码行数:26,代码来源:api_request.py
示例6: __init__
def __init__(self, currentTime, dataType, numberOfExperts):
self.currentTime = currentTime
self.numberOfExperts = numberOfExperts
self.inputTrainingSetFile = Utilities.getTrainingFile(currentTime, dataType, self.numberOfExperts)
self.inputTestSetFile = Utilities.getTestFile(currentTime, dataType, self.numberOfExperts, bottom=True)
self.outputCombinedFile = Utilities.getStreamingSetsFile(currentTime, dataType, numberOfExperts)
Utilities.createDirectory(self.outputCombinedFile)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:7,代码来源:datasets.py
示例7: __init__
def __init__(self,inputstream,dictionary):
Utilities.debug('Reader init');
self.tokenMap = dictionary;
self.rawIn = inputstream;
self.inn = ByteArray();
self.buf = bytearray(1024);
self.bufSize = 0;
self.readSize = 1;
开发者ID:admhouss,项目名称:wazapp,代码行数:8,代码来源:protocoltreenode.py
示例8: nextTree
def nextTree(self):
stanzaSize = self.readInt16(self.rawIn,1);
self.inn.buf = [];
self.fillBuffer(stanzaSize);
ret = self.nextTreeInternal();
Utilities.debug("<<")
if ret is not None:
'''Utilities.debug(ret.toString());'''
return ret;
开发者ID:admhouss,项目名称:wazapp,代码行数:9,代码来源:protocoltreenode.py
示例9: message_status_update
def message_status_update(self,fmsg):
Utilities.debug("Message status updated {0}".format(fmsg.status));
contact = fmsg.getContact();
modelData = fmsg.getModelData();
modelData["Contact"] = contact.getModelData();
if fmsg.status == WAXMPP.message_store.store.Message.STATUS_SENT:
self.messageSent.emit(modelData);
elif fmsg.status == WAXMPP.message_store.store.Message.STATUS_DELIVERED:
self.messageDelivered.emit(modelData);
开发者ID:MichaelShaka,项目名称:wazapp,代码行数:9,代码来源:waxmpp.py
示例10: __init__
def __init__(self, conn, reader, writer, digest):
super(WALogin, self).__init__()
self.conn = conn
self.out = writer
self.inn = reader
self.digest = digest
Utilities.debug("WALOGIN INIT")
开发者ID:nivertech,项目名称:wazapp,代码行数:9,代码来源:walogin.py
示例11: generateStatsForGlobalClassifier
def generateStatsForGlobalClassifier():
classifier = GlobalClassifier()
classifier.load()
currentDay = Settings.startTime
while currentDay<=Settings.endTime:
data = {'day': datetime.strftime(currentDay, Settings.twitter_api_time_format), 'metric': 'aucm', 'data_type': DocumentType.typeRuuslUnigram, 'test_data_days': 1}
data['value'] = classifier.getAUCM(TestDocuments(currentTime=currentDay, numberOfExperts=Settings.numberOfExperts, dataType=DocumentType.typeRuuslUnigram, noOfDays=1).iterator())
Utilities.writeAsJsonToFile(data, Settings.stats_for_global_classifier)
currentDay+=timedelta(days=1)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:9,代码来源:experiments.py
示例12: generateStatsForTrainingDataPerDay
def generateStatsForTrainingDataPerDay():
currentDay = Settings.startTime
noOfDays = 1
while currentDay<=Settings.endTime:
classDistribution = defaultdict(int)
for d in Utilities.getTweets(fileNameMethod=Utilities.getTrainingFile, dataDirection=DataDirection.past, currentTime=currentDay, numberOfExperts=Settings.numberOfExperts, dataType=DocumentType.typeRuuslUnigram, noOfDays=noOfDays):
classDistribution[d[1]]+=1
data = {'day': datetime.strftime(currentDay, Settings.twitter_api_time_format), 'class_distribution': classDistribution}
Utilities.writeAsJsonToFile(data, Settings.stats_for_training_data)
currentDay+=timedelta(days=1)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:10,代码来源:experiments.py
示例13: write
def write(self, node,needsFlush = 0):
if node is None:
self.out.write(0);
else:
Utilities.debug(">>");
'''Utilities.debug(node.toString());'''
self.writeInternal(node);
self.flushBuffer(needsFlush);
self.out.buf = [];
开发者ID:admhouss,项目名称:wazapp,代码行数:10,代码来源:protocoltreenode.py
示例14: setup
def setup(self):
"""
None -> None
Downloads and parses necessary retrosheet data for the simulation
"""
retro = Retrosheet(self.simYear)
Utilities.ensure_gamelog_files_exist(self.simYear)
Utilities.ensure_boxscore_files_exist(self.simYear, 'HOU')
retro.clean_used_files()
开发者ID:frahman5,项目名称:beatthestreak,代码行数:10,代码来源:simulation.py
示例15: __repr__
def __repr__(self):
"""
Give a verbose representation for a word in the format <form>@<lemma><categories>, for example: [email protected]('pl',)"
@rtype: str
"""
z = Utilities.unidecode(self.__form) + "@" + ` self.__lemma `
if len(self.categories) == 0:
return z
else:
return z + Utilities.tuple_str(self.categories)
开发者ID:BackupTheBerlios,项目名称:pylilac-svn,代码行数:11,代码来源:lexicon.py
示例16: generateStatsToDetermineFixedWindowLength
def generateStatsToDetermineFixedWindowLength():
global maxLength
currentDay = Settings.startTime
while currentDay<=Settings.endTime:
for noOfDays in Utilities.getClassifierLengthsByDay(currentDay, maxLength):
classifier = FixedWindowClassifier(currentTime=currentDay, numberOfExperts=Settings.numberOfExperts, dataType=DocumentType.typeRuuslUnigram, noOfDays=noOfDays)
classifier.load()
data = {'day': datetime.strftime(currentDay, Settings.twitter_api_time_format), 'classifier_length': noOfDays, 'metric': 'aucm', 'number_of_experts': Settings.numberOfExperts, 'data_type': DocumentType.typeRuuslUnigram, 'test_data_days': 1}
data['value'] = classifier.getAUCM(TestDocuments(currentTime=currentDay+timedelta(days=1), numberOfExperts=Settings.numberOfExperts, dataType=DocumentType.typeRuuslUnigram, noOfDays=1).iterator())
Utilities.writeAsJsonToFile(data, Settings.stats_to_determine_fixed_window_length)
currentDay+=timedelta(days=1)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:11,代码来源:experiments.py
示例17: generateStatsForTopFeatures
def generateStatsForTopFeatures():
global maxLength
currentDay = Settings.startTime
noOfDays = 1
while currentDay<=Settings.endTime:
classifier = FixedWindowClassifier(currentTime=currentDay, numberOfExperts=Settings.numberOfExperts, dataType=DocumentType.typeRuuslUnigram, noOfDays=noOfDays)
classifier.load()
data = {'day': datetime.strftime(currentDay, Settings.twitter_api_time_format), 'classifier_length': noOfDays, 'number_of_experts': Settings.numberOfExperts, 'data_type': DocumentType.typeRuuslUnigram}
data['features']=classifier.showMostInformativeFeatures(2000)
Utilities.writeAsJsonToFile(data, Settings.stats_for_most_informative_features)
currentDay+=timedelta(days=1)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:11,代码来源:experiments.py
示例18: streamStart
def streamStart(self):
stanzaSize = self.readInt16(self.rawIn,1);
self.fillBuffer(stanzaSize);
tag = self.inn.read();
size = self.readListSize(tag);
tag = self.inn.read();
if tag != 1:
Utilities.debug(tag);
raise Exception("expecting STREAM_START in streamStart");
attribCount = (size - 2 + size % 2) / 2;
attributes = self.readAttributes(attribCount);
开发者ID:admhouss,项目名称:wazapp,代码行数:11,代码来源:protocoltreenode.py
示例19: generateDataSetStats125
def generateDataSetStats125():
currentDay = Settings.startTime
while currentDay<=Settings.endTime:
data = {'day': datetime.strftime(currentDay, Settings.twitter_api_time_format), 'train_classes': defaultdict(int), 'test_classes': defaultdict(int)}
inputTrainingSetFile = Utilities.getTrainingFile(currentDay, DocumentType.typeRuuslUnigram, Settings.numberOfExperts)
inputTestSetFile = Utilities.getTestFile(currentDay, DocumentType.typeRuuslUnigram, Settings.numberOfExperts, bottom=True)
for file, tweetType in [(inputTrainingSetFile, 'training'), (inputTestSetFile, 'test')]:
for tweet in Utilities.iterateTweetsFromFile(file):
if tweetType=='training': data['train_classes'][tweet['class']]+=1
else: data['test_classes'][tweet['class']]+=1
Utilities.writeAsJsonToFile(data, Settings.stats_for_dataset_125)
currentDay+=timedelta(days=1)
开发者ID:kykamath,项目名称:twitter_classifier,代码行数:12,代码来源:experiments.py
示例20: checkConnection
def checkConnection(self):
try:
if self.conn.state == 0:
raise Exception("Not connected");
elif self.conn.state == 2:
self.conn.sendPing();
except:
print "Connection crashed, reason: %s"%sys.exc_info()[1]
self.networkDisconnected()
self.networkAvailable();
Utilities.debug("CHECK PASSEDDDDDDDDDDDDDDD")
开发者ID:MichaelShaka,项目名称:wazapp,代码行数:12,代码来源:waxmpp.py
注:本文中的utilities.Utilities类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论