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


Python glyph.GraphTypes类代码示例

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


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

示例1: parseOptions

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)
开发者ID:Squarespace,项目名称:graphite-web,代码行数:98,代码来源:views.py

示例2: parseOptions

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)
开发者ID:jbrownbridge,项目名称:graphite-render,代码行数:64,代码来源:views.py

示例3: parseOptions

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
#.........这里部分代码省略.........
开发者ID:gpurkins-ias,项目名称:graphite-web,代码行数:101,代码来源:views.py

示例4: parseOptions

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)
开发者ID:3ofcoins,项目名称:graphite_stack,代码行数:66,代码来源:views.py


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