本文整理汇总了Python中query.Query.metric方法的典型用法代码示例。如果您正苦于以下问题:Python Query.metric方法的具体用法?Python Query.metric怎么用?Python Query.metric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query.Query
的用法示例。
在下文中一共展示了Query.metric方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jsonReport
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import metric [as 别名]
def jsonReport(self,reportJSON):
"""Creates a report from JSON. Accepts either JSON or a string. Useful for deserializing requests"""
q = Query(self)
#TODO: Add a method to the Account Object to populate the report suite this call will ignore it on purpose
if type(reportJSON) == str:
reportJSON = json.loads(reportJSON)
reportJSON = reportJSON['reportDescription']
if reportJSON.has_key('dateFrom') and reportJSON.has_key('dateTo'):
q = q.range(reportJSON['dateFrom'],reportJSON['dateTo'])
elif reportJSON.has_key('dateFrom'):
q = q.range(reportJSON['dateFrom'])
elif reportJSON.has_key('date'):
q = q.range(reportJSON['date'])
else:
q = q
if reportJSON.has_key('dateGranularity'):
q = q.granularity(reportJSON['dateGranularity'])
if reportJSON.has_key('source'):
q = q.set('source',reportJSON['source'])
if reportJSON.has_key('metrics'):
for m in reportJSON['metrics']:
q = q.metric(m['id'])
if reportJSON.has_key('elements'):
for e in reportJSON['elements']:
id = e['id']
del e['id']
q= q.element(id, **e)
if reportJSON.has_key('locale'):
q = q.set('locale',reportJSON['locale'])
if reportJSON.has_key('sortMethod'):
q = q.set('sortMethod',reportJSON['sortMethod'])
if reportJSON.has_key('sortBy'):
q = q.sortBy(reportJSON['sortBy'])
#WARNING This doesn't carry over segment IDs meaning you can't manipulate the segments in the new object
#TODO Loop through and add segment ID with filter method (need to figure out how to handle combined)
if reportJSON.has_key('segments'):
q = q.set('segments', reportJSON['segments'])
if reportJSON.has_key('anomalyDetection'):
q = q.set('anomalyDetection',reportJSON['anomalyDetection'])
if reportJSON.has_key('currentData'):
q = q.set('currentData',reportJSON['currentData'])
if reportJSON.has_key('elementDataEncoding'):
q = q.set('elementDataEncoding',reportJSON['elementDataEncoding'])
return q