本文整理汇总了Python中graphite.render.glyph.GraphTypes.keys方法的典型用法代码示例。如果您正苦于以下问题:Python GraphTypes.keys方法的具体用法?Python GraphTypes.keys怎么用?Python GraphTypes.keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphite.render.glyph.GraphTypes
的用法示例。
在下文中一共展示了GraphTypes.keys方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parseOptions
# 需要导入模块: from graphite.render.glyph import GraphTypes [as 别名]
# 或者: from graphite.render.glyph.GraphTypes import keys [as 别名]
def parseOptions(request):
queryParams = request.REQUEST
# Start with some defaults
graphOptions = {'width' : 330, 'height' : 250}
requestOptions = {}
graphType = queryParams.get('graphType','line')
assert graphType in GraphTypes, "Invalid graphType '%s', must be one of %s" % (graphType,GraphTypes.keys())
graphClass = GraphTypes[graphType]
# Fill in the requestOptions
requestOptions['graphType'] = graphType
requestOptions['graphClass'] = graphClass
requestOptions['pieMode'] = queryParams.get('pieMode', 'average')
requestOptions['cacheTimeout'] = int( queryParams.get('cacheTimeout', settings.DEFAULT_CACHE_DURATION) )
requestOptions['targets'] = []
# Extract the targets out of the queryParams
mytargets = []
# Normal format: ?target=path.1&target=path.2
if len(queryParams.getlist('target')) > 0:
mytargets = queryParams.getlist('target')
# Rails/PHP/jQuery common practice format: ?target[]=path.1&target[]=path.2
elif len(queryParams.getlist('target[]')) > 0:
mytargets = queryParams.getlist('target[]')
# Collect the targets
for target in mytargets:
requestOptions['targets'].append(target)
template = dict()
for key, val in queryParams.items():
if key.startswith("template["):
template[key[9:-1]] = val
requestOptions['template'] = template
if 'pickle' in queryParams:
requestOptions['format'] = 'pickle'
if 'rawData' in queryParams:
requestOptions['format'] = 'raw'
if 'format' in queryParams:
requestOptions['format'] = queryParams['format']
if 'jsonp' in queryParams:
requestOptions['jsonp'] = queryParams['jsonp']
if 'noCache' in queryParams:
requestOptions['noCache'] = True
if 'maxDataPoints' in queryParams and queryParams['maxDataPoints'].isdigit():
requestOptions['maxDataPoints'] = int(queryParams['maxDataPoints'])
requestOptions['localOnly'] = queryParams.get('local') == '1'
# Fill in the graphOptions
for opt in graphClass.customizable:
if opt in queryParams:
val = queryParams[opt]
if (val.isdigit() or (val.startswith('-') and val[1:].isdigit())) and 'color' not in opt.lower():
val = int(val)
elif '.' in val and (val.replace('.','',1).isdigit() or (val.startswith('-') and val[1:].replace('.','',1).isdigit())):
val = float(val)
elif val.lower() in ('true','false'):
val = val.lower() == 'true'
elif val.lower() == 'default' or val == '':
continue
graphOptions[opt] = val
tzinfo = pytz.timezone(settings.TIME_ZONE)
if 'tz' in queryParams:
try:
tzinfo = pytz.timezone(queryParams['tz'])
except pytz.UnknownTimeZoneError:
pass
requestOptions['tzinfo'] = tzinfo
# Get the time interval for time-oriented graph types
if graphType == 'line' or graphType == 'pie':
if 'until' in queryParams:
untilTime = parseATTime(queryParams['until'], tzinfo)
else:
untilTime = parseATTime('now', tzinfo)
if 'from' in queryParams:
fromTime = parseATTime(queryParams['from'], tzinfo)
else:
fromTime = parseATTime('-1d', tzinfo)
startTime = min(fromTime, untilTime)
endTime = max(fromTime, untilTime)
assert startTime != endTime, "Invalid empty time range"
requestOptions['startTime'] = startTime
requestOptions['endTime'] = endTime
timeRange = endTime - startTime
queryTime = timeRange.days * 86400 + timeRange.seconds # convert the time delta to seconds
if settings.DEFAULT_CACHE_POLICY and not queryParams.get('cacheTimeout'):
requestOptions['cacheTimeout'] = max(timeout for period,timeout in settings.DEFAULT_CACHE_POLICY if period <= queryTime)
return (graphOptions, requestOptions)
示例2: parseOptions
# 需要导入模块: from graphite.render.glyph import GraphTypes [as 别名]
# 或者: from graphite.render.glyph.GraphTypes import keys [as 别名]
def parseOptions(request):
queryParams = request.REQUEST
# Start with some defaults
graphOptions = {'width' : 330, 'height' : 250}
requestOptions = {}
graphType = queryParams.get('graphType','line')
assert graphType in GraphTypes, "Invalid graphType '%s', must be one of %s" % (graphType,GraphTypes.keys())
graphClass = GraphTypes[graphType]
# Fill in the requestOptions
requestOptions['graphType'] = graphType
requestOptions['graphClass'] = graphClass
requestOptions['pieMode'] = queryParams.get('pieMode', 'average')
requestOptions['targets'] = []
for target in queryParams.getlist('target'):
if target.lower().startswith('graphite.'): #Strip leading "Graphite." as a convenience
target = target[9:]
requestOptions['targets'].append(target)
requestOptions['timers'] = []
for stat in queryParams.getlist('timer'):
requestOptions['timers'].append(stat)
if 'pickle' in queryParams:
requestOptions['pickle'] = True
if 'rawData' in queryParams:
requestOptions['rawData'] = True
if 'noCache' in queryParams:
requestOptions['noCache'] = True
# Fill in the graphOptions
for opt in graphClass.customizable:
if opt in queryParams:
val = queryParams[opt]
if (val.isdigit() or (val.startswith('-') and val[1:].isdigit())) and opt not in ('fgcolor','bgcolor','fontColor'):
val = int(val)
elif '.' in val and (val.replace('.','',1).isdigit() or (val.startswith('-') and val[1:].replace('.','',1).isdigit())):
val = float(val)
elif val.lower() in ('true','false'):
val = eval( val.lower().capitalize() )
elif val.lower() == 'default' or val == '':
continue
graphOptions[opt] = val
# Get the time interval for time-oriented graph types
if graphType == 'line' or graphType == 'pie':
if 'until' in queryParams:
endTime = parseATTime( queryParams['until'] )
else:
endTime = datetime.now()
if 'from' in queryParams:
startTime = parseATTime( queryParams['from'] )
else:
startTime = endTime - timedelta(days=1)
if endTime > datetime.now():
endTime = datetime.now()
assert startTime < endTime, "Invalid time range!"
requestOptions['startTime'] = startTime
requestOptions['endTime'] = endTime
return (graphOptions, requestOptions)
示例3: parseOptions
# 需要导入模块: from graphite.render.glyph import GraphTypes [as 别名]
# 或者: from graphite.render.glyph.GraphTypes import keys [as 别名]
def parseOptions(request):
queryParams = request.GET.copy()
queryParams.update(request.POST)
# Start with some defaults
graphOptions = {"width": 330, "height": 250}
requestOptions = {}
graphType = queryParams.get("graphType", "line")
assert graphType in GraphTypes, "Invalid graphType '%s', must be one of %s" % (graphType, GraphTypes.keys())
graphClass = GraphTypes[graphType]
# Fill in the requestOptions
requestOptions["graphType"] = graphType
requestOptions["graphClass"] = graphClass
requestOptions["pieMode"] = queryParams.get("pieMode", "average")
requestOptions["cacheTimeout"] = int(queryParams.get("cacheTimeout", settings.DEFAULT_CACHE_DURATION))
requestOptions["targets"] = []
# Extract the targets out of the queryParams
mytargets = []
# Normal format: ?target=path.1&target=path.2
if len(queryParams.getlist("target")) > 0:
mytargets = queryParams.getlist("target")
# Rails/PHP/jQuery common practice format: ?target[]=path.1&target[]=path.2
elif len(queryParams.getlist("target[]")) > 0:
mytargets = queryParams.getlist("target[]")
# Collect the targets
for target in mytargets:
requestOptions["targets"].append(target)
template = dict()
for key, val in queryParams.items():
if key.startswith("template["):
template[key[9:-1]] = val
requestOptions["template"] = template
if "pickle" in queryParams:
requestOptions["format"] = "pickle"
if "rawData" in queryParams:
requestOptions["format"] = "raw"
if "format" in queryParams:
requestOptions["format"] = queryParams["format"]
if "jsonp" in queryParams:
requestOptions["jsonp"] = queryParams["jsonp"]
if "noCache" in queryParams:
requestOptions["noCache"] = True
if "maxDataPoints" in queryParams and queryParams["maxDataPoints"].isdigit():
requestOptions["maxDataPoints"] = int(queryParams["maxDataPoints"])
requestOptions["localOnly"] = queryParams.get("local") == "1"
# Fill in the graphOptions
for opt in graphClass.customizable:
if opt in queryParams:
val = queryParams[opt]
if (val.isdigit() or (val.startswith("-") and val[1:].isdigit())) and "color" not in opt.lower():
val = int(val)
elif "." in val and (
val.replace(".", "", 1).isdigit() or (val.startswith("-") and val[1:].replace(".", "", 1).isdigit())
):
val = float(val)
elif val.lower() in ("true", "false"):
val = val.lower() == "true"
elif val.lower() == "default" or val == "":
continue
graphOptions[opt] = val
tzinfo = pytz.timezone(settings.TIME_ZONE)
if "tz" in queryParams:
try:
tzinfo = pytz.timezone(queryParams["tz"])
except pytz.UnknownTimeZoneError:
pass
requestOptions["tzinfo"] = tzinfo
# Get the time interval for time-oriented graph types
if graphType == "line" or graphType == "pie":
if "until" in queryParams:
untilTime = parseATTime(queryParams["until"], tzinfo)
else:
untilTime = parseATTime("now", tzinfo)
if "from" in queryParams:
fromTime = parseATTime(queryParams["from"], tzinfo)
else:
fromTime = parseATTime("-1d", tzinfo)
startTime = min(fromTime, untilTime)
endTime = max(fromTime, untilTime)
assert startTime != endTime, "Invalid empty time range"
requestOptions["startTime"] = startTime
requestOptions["endTime"] = endTime
timeRange = endTime - startTime
queryTime = timeRange.days * 86400 + timeRange.seconds # convert the time delta to seconds
if settings.DEFAULT_CACHE_POLICY and not queryParams.get("cacheTimeout"):
requestOptions["cacheTimeout"] = max(
timeout for period, timeout in settings.DEFAULT_CACHE_POLICY if period <= queryTime
#.........这里部分代码省略.........
示例4: parseOptions
# 需要导入模块: from graphite.render.glyph import GraphTypes [as 别名]
# 或者: from graphite.render.glyph.GraphTypes import keys [as 别名]
def parseOptions(request):
queryParams = request.REQUEST
# Start with some defaults
graphOptions = {'width' : 330, 'height' : 250}
requestOptions = {}
graphType = queryParams.get('graphType','line')
assert graphType in GraphTypes, "Invalid graphType '%s', must be one of %s" % (graphType,GraphTypes.keys())
graphClass = GraphTypes[graphType]
# Fill in the requestOptions
requestOptions['graphType'] = graphType
requestOptions['graphClass'] = graphClass
requestOptions['pieMode'] = queryParams.get('pieMode', 'average')
requestOptions['cacheTimeout'] = int( queryParams.get('cacheTimeout', settings.DEFAULT_CACHE_DURATION) )
requestOptions['targets'] = []
for target in queryParams.getlist('target'):
requestOptions['targets'].append(target)
if 'pickle' in queryParams:
requestOptions['format'] = 'pickle'
if 'rawData' in queryParams:
requestOptions['format'] = 'raw'
if 'format' in queryParams:
requestOptions['format'] = queryParams['format']
if 'jsonp' in queryParams:
requestOptions['jsonp'] = queryParams['jsonp']
if 'noCache' in queryParams:
requestOptions['noCache'] = True
requestOptions['localOnly'] = queryParams.get('local') == '1'
# Fill in the graphOptions
for opt in graphClass.customizable:
if opt in queryParams:
val = queryParams[opt]
if (val.isdigit() or (val.startswith('-') and val[1:].isdigit())) and opt not in ('fgcolor','bgcolor','fontColor'):
val = int(val)
elif '.' in val and (val.replace('.','',1).isdigit() or (val.startswith('-') and val[1:].replace('.','',1).isdigit())):
val = float(val)
elif val.lower() in ('true','false'):
val = val.lower() == 'true'
elif val.lower() == 'default' or val == '':
continue
graphOptions[opt] = val
# Get the time interval for time-oriented graph types
if graphType == 'line' or graphType == 'pie':
if 'until' in queryParams:
untilTime = parseATTime( queryParams['until'] )
else:
untilTime = parseATTime('now')
if 'from' in queryParams:
fromTime = parseATTime( queryParams['from'] )
else:
fromTime = parseATTime('-1d')
startTime = min(fromTime, untilTime)
endTime = max(fromTime, untilTime)
assert startTime != endTime, "Invalid empty time range"
requestOptions['startTime'] = startTime
requestOptions['endTime'] = endTime
return (graphOptions, requestOptions)