コード例 #1
0
ファイル: __init__.py プロジェクト: IgorPelevanyuk/DIRAC
def graph( data, file, *args, **kw ):

  prefs = evalPrefs( *args, **kw )
  if prefs.has_key( 'graph_size' ):
    graph_size = prefs['graph_size']
  else:
    graph_size = "normal"

  if graph_size == "normal":
    defaults = graph_normal_prefs
  elif graph_size == "small":
    defaults = graph_small_prefs
  elif graph_size == "thumbnail":
    defaults = graph_thumbnail_prefs
  elif graph_size == "large":
    defaults = graph_large_prefs

  graph = Graph()
  start = time.time()
  graph.makeGraph( data, common_prefs, defaults, prefs )
  #print "AT >>>> makeGraph time",time.time()-start
  start = time.time()
  graph.writeGraph( file, 'PNG' )
  #print "AT >>>> writeGraph time",time.time()-start
  return DIRAC.S_OK({'plot':file})
コード例 #2
0
ファイル: __init__.py プロジェクト: acasajus/DIRAC
def graph(data, file, *args, **kw):

    prefs = evalPrefs(*args, **kw)
    if prefs.has_key('graph_size'):
        graph_size = prefs['graph_size']
    else:
        graph_size = "normal"

    if graph_size == "normal":
        defaults = graph_normal_prefs
    elif graph_size == "small":
        defaults = graph_small_prefs
    elif graph_size == "thumbnail":
        defaults = graph_thumbnail_prefs
    elif graph_size == "large":
        defaults = graph_large_prefs

    graph = Graph()
    start = time.time()
    graph.makeGraph(data, common_prefs, defaults, prefs)
    #print "AT >>>> makeGraph time",time.time()-start
    start = time.time()
    graph.writeGraph(file, 'PNG')
    #print "AT >>>> writeGraph time",time.time()-start
    return DIRAC.S_OK({'plot': file})
コード例 #3
0
    def __init__(self, data=None, axes=None, *aw, **kw):

        self.ax_contain = axes
        self.canvas = None
        self.figure = None
        if self.ax_contain:
            self.figure = self.ax_contain.get_figure()
            self.canvas = self.figure.canvas
            self.dpi = self.ax_contain.figure.get_dpi()
            self.ax_contain.set_axis_off()
        self.prefs = evalPrefs(*aw, **kw)
        self.coords = {}
        self.palette = Palette()
        if isinstance(data, dict):
            self.gdata = GraphData(data)
        elif isinstance(data, object) and data.__class__ == GraphData:
            self.gdata = data
コード例 #4
0
ファイル: PlotBase.py プロジェクト: DIRACGrid-test/DIRAC
  def __init__( self, data = None, axes = None, *aw, **kw ):

    self.ax_contain = axes
    self.canvas = None
    self.figure = None
    if self.ax_contain:
      self.figure = self.ax_contain.get_figure()
      self.canvas = self.figure.canvas
      self.dpi = self.ax_contain.figure.get_dpi()
      self.ax_contain.set_axis_off()
    self.prefs = evalPrefs( *aw, **kw )
    self.coords = {}
    self.palette = Palette()
    if isinstance( data, dict):
      self.gdata = GraphData( data )
    elif isinstance( data, object) and data.__class__ == GraphData:
      self.gdata = data
コード例 #5
0
def graph(data, fileName, *args, **kw):

    prefs = evalPrefs(*args, **kw)
    graph_size = prefs.get("graph_size", "normal")

    if graph_size == "normal":
        defaults = graph_normal_prefs
    elif graph_size == "small":
        defaults = graph_small_prefs
    elif graph_size == "thumbnail":
        defaults = graph_thumbnail_prefs
    elif graph_size == "large":
        defaults = graph_large_prefs

    graph = Graph()
    graph.makeGraph(data, common_prefs, defaults, prefs)
    graph.writeGraph(fileName, "PNG")
    return DIRAC.S_OK({"plot": fileName})
コード例 #6
0
def graph(data, fileName, *args, **kw):

    prefs = evalPrefs(*args, **kw)
    if prefs.has_key('graph_size'):
        graph_size = prefs['graph_size']
    else:
        graph_size = "normal"

    if graph_size == "normal":
        defaults = graph_normal_prefs
    elif graph_size == "small":
        defaults = graph_small_prefs
    elif graph_size == "thumbnail":
        defaults = graph_thumbnail_prefs
    elif graph_size == "large":
        defaults = graph_large_prefs

    graph = Graph()
    graph.makeGraph(data, common_prefs, defaults, prefs)
    graph.writeGraph(fileName, 'PNG')
    return DIRAC.S_OK({'plot': fileName})
コード例 #7
0
ファイル: __init__.py プロジェクト: DIRACGrid/DIRAC
def graph( data, fileName, *args, **kw ):

  prefs = evalPrefs( *args, **kw )
  if prefs.has_key( 'graph_size' ):
    graph_size = prefs['graph_size']
  else:
    graph_size = "normal"

  if graph_size == "normal":
    defaults = graph_normal_prefs
  elif graph_size == "small":
    defaults = graph_small_prefs
  elif graph_size == "thumbnail":
    defaults = graph_thumbnail_prefs
  elif graph_size == "large":
    defaults = graph_large_prefs

  graph = Graph()
  graph.makeGraph( data, common_prefs, defaults, prefs )
  graph.writeGraph( fileName, 'PNG' )
  return DIRAC.S_OK( {'plot':fileName} )
コード例 #8
0
ファイル: Graph.py プロジェクト: DIRACGrid/DIRAC
  def makeGraph(self, data, *args, **kw):

    start = time.time()

    # Evaluate all the preferences
    self.prefs = evalPrefs(*args,**kw)
    prefs = self.prefs

    if DEBUG:
      print "makeGraph time 1",time.time()-start
      start = time.time()

    if prefs.has_key('text_image'):
      self.makeTextGraph(str(prefs['text_image']))
      return

    # Evaluate the number of plots and their requested layout
    metadata = prefs.get('metadata',{})
    plot_grid = prefs.get('plot_grid','1:1')
    nx = int(plot_grid.split(':')[0])
    ny = int(plot_grid.split(':')[1])
    nPlots = nx*ny
    if nPlots == 1:
      if not isinstance( data, list ):
        data = [data]
      if not isinstance(metadata, list):
        metadata = [metadata]
    else:
      if not isinstance( data, list ):
        #return S_ERROR('Single data for multiplot graph')
        print 'Single data for multiplot graph'
        return
      if not isinstance(metadata, list):
        metaList = []
        for _ in range( nPlots ):
          metaList.append(metadata)
        metadata = metaList

    # Initialize plot data
    graphData = []
    plot_prefs = []
    for i in range(nPlots):
      plot_prefs.append(evalPrefs(prefs,metadata[i]))
      gdata = GraphData(data[i])
      if i == 0: plot_type = plot_prefs[i]['plot_type']
      if plot_prefs[i].has_key('sort_labels'):
        reverse = plot_prefs[i].get( 'reverse_labels', False )
        gdata.sortLabels(plot_prefs[i]['sort_labels'], reverse_order = reverse )
      if plot_prefs[i].has_key('limit_labels'):
        if plot_prefs[i]['limit_labels'] > 0:
          gdata.truncateLabels(plot_prefs[i]['limit_labels'])
      if plot_prefs[i].has_key('cumulate_data'):
        gdata.makeCumulativeGraph()
      plot_title = plot_prefs[i].get('plot_title','')
      if plot_title != "NoTitle":
        begin = ''
        end = ''
        if plot_prefs[i].has_key('starttime') and plot_prefs[i].has_key('endtime'):
          begin = to_timestamp(plot_prefs[i]['starttime'])
          end = to_timestamp(plot_prefs[i]['endtime'])
        elif gdata.key_type == "time" :
          begin = gdata.min_key
          end = gdata.max_key
        if begin and end:
          time_title = add_time_to_title(begin,end)
          if plot_title:
            plot_title += ":"
          plot_prefs[i]['plot_title'] = plot_title+' '+time_title
      graphData.append(gdata)

    # Do not make legend for the plot with non-string keys (except for PieGraphs)
    if not graphData[0].subplots and graphData[0].key_type != 'string' and not plot_type == 'PieGraph':
      prefs['legend'] = False
    if prefs['legend'] and graphData[0].key_type != 'string' and plot_type == 'PieGraph':
      graphData[0].initialize(key_type='string')

    legend = Legend(graphData[0],None,prefs)
    self.figure = Figure()

    # Make Water Mark
    image = prefs.get('watermark',None)
    self.drawWaterMark(image)

    legend_ax, plot_axes = self.layoutFigure(legend)

    if DEBUG:
      print "makeGraph time layout",time.time()-start
      start = time.time()

    # Make plots
    for i in range(nPlots):
      plot_type = plot_prefs[i]['plot_type']
      try:
        exec "import %s" % plot_type
      except ImportError, x:
        print "Failed to import graph type %s: %s" % ( plot_type, str( x ) )
        return None

      ax = plot_axes[i]
      plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" % (plot_type,plot_type) )
      plot.draw()
コード例 #9
0
    def makeGraph(self, data, *args, **kw):

        start = time.time()

        # Evaluate all the preferences
        self.prefs = evalPrefs(*args, **kw)
        prefs = self.prefs

        if DEBUG:
            print "makeGraph time 1", time.time() - start
            start = time.time()

        if prefs.has_key('text_image'):
            self.makeTextGraph(str(prefs['text_image']))
            return

        # Evaluate the number of plots and their requested layout
        metadata = prefs.get('metadata', {})
        plot_grid = prefs.get('plot_grid', '1:1')
        nx = int(plot_grid.split(':')[0])
        ny = int(plot_grid.split(':')[1])
        nPlots = nx * ny
        if nPlots == 1:
            if not isinstance(data, list):
                data = [data]
            if not isinstance(metadata, list):
                metadata = [metadata]
        else:
            if not isinstance(data, list):
                #return S_ERROR('Single data for multiplot graph')
                print 'Single data for multiplot graph'
                return
            if not isinstance(metadata, list):
                metaList = []
                for _ in range(nPlots):
                    metaList.append(metadata)
                metadata = metaList

        # Initialize plot data
        graphData = []
        plot_prefs = []
        for i in range(nPlots):
            plot_prefs.append(evalPrefs(prefs, metadata[i]))
            gdata = GraphData(data[i])
            if i == 0: plot_type = plot_prefs[i]['plot_type']
            if plot_prefs[i].has_key('sort_labels'):
                reverse = plot_prefs[i].get('reverse_labels', False)
                gdata.sortLabels(plot_prefs[i]['sort_labels'],
                                 reverse_order=reverse)
            if plot_prefs[i].has_key('limit_labels'):
                if plot_prefs[i]['limit_labels'] > 0:
                    gdata.truncateLabels(plot_prefs[i]['limit_labels'])
            if plot_prefs[i].has_key('cumulate_data'):
                gdata.makeCumulativeGraph()
            plot_title = plot_prefs[i].get('plot_title', '')
            if plot_title != "NoTitle":
                begin = ''
                end = ''
                if plot_prefs[i].has_key(
                        'starttime') and plot_prefs[i].has_key('endtime'):
                    begin = to_timestamp(plot_prefs[i]['starttime'])
                    end = to_timestamp(plot_prefs[i]['endtime'])
                elif gdata.key_type == "time":
                    begin = gdata.min_key
                    end = gdata.max_key
                if begin and end:
                    time_title = add_time_to_title(begin, end)
                    if plot_title:
                        plot_title += ":"
                    plot_prefs[i]['plot_title'] = plot_title + ' ' + time_title
            graphData.append(gdata)

        # Do not make legend for the plot with non-string keys (except for PieGraphs)
        if not graphData[0].subplots and graphData[
                0].key_type != 'string' and not plot_type == 'PieGraph':
            prefs['legend'] = False
        if prefs['legend'] and graphData[
                0].key_type != 'string' and plot_type == 'PieGraph':
            graphData[0].initialize(key_type='string')

        legend = Legend(graphData[0], None, prefs)
        self.figure = Figure()

        # Make Water Mark
        image = prefs.get('watermark', None)
        self.drawWaterMark(image)

        legend_ax, plot_axes = self.layoutFigure(legend)

        if DEBUG:
            print "makeGraph time layout", time.time() - start
            start = time.time()

        # Make plots
        for i in range(nPlots):
            plot_type = plot_prefs[i]['plot_type']
            try:
                exec "import %s" % plot_type
            except ImportError, x:
                print "Failed to import graph type %s: %s" % (plot_type,
                                                              str(x))
                return None

            ax = plot_axes[i]
            plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" %
                        (plot_type, plot_type))
            plot.draw()
コード例 #10
0
ファイル: Graph.py プロジェクト: DIRACGrid/DIRAC
    def makeGraph(self, data, *args, **kw):

        start = time.time()

        # Evaluate all the preferences
        self.prefs = evalPrefs(*args, **kw)
        prefs = self.prefs

        if DEBUG:
            print "makeGraph time 1", time.time() - start
            start = time.time()

        if prefs.has_key("text_image"):
            self.makeTextGraph(str(prefs["text_image"]))
            return

        # Evaluate the number of plots and their requested layout
        metadata = prefs.get("metadata", {})
        plot_grid = prefs.get("plot_grid", "1:1")
        nx = int(plot_grid.split(":")[0])
        ny = int(plot_grid.split(":")[1])
        nPlots = nx * ny
        if nPlots == 1:
            if type(data) != types.ListType:
                data = [data]
            if type(metadata) != types.ListType:
                metadata = [metadata]
        else:
            if type(data) != types.ListType:
                # return S_ERROR('Single data for multiplot graph')
                print "Single data for multiplot graph"
                return
            if type(metadata) != types.ListType:
                metaList = []
                for _ in range(nPlots):
                    metaList.append(metadata)
                metadata = metaList

        # Initialize plot data
        graphData = []
        plot_prefs = []
        for i in range(nPlots):
            plot_prefs.append(evalPrefs(prefs, metadata[i]))
            gdata = GraphData(data[i])
            if i == 0:
                plot_type = plot_prefs[i]["plot_type"]
            if plot_prefs[i].has_key("sort_labels"):
                reverse = plot_prefs[i].get("reverse_labels", False)
                gdata.sortLabels(plot_prefs[i]["sort_labels"], reverse_order=reverse)
            if plot_prefs[i].has_key("limit_labels"):
                if plot_prefs[i]["limit_labels"] > 0:
                    gdata.truncateLabels(plot_prefs[i]["limit_labels"])
            if plot_prefs[i].has_key("cumulate_data"):
                gdata.makeCumulativeGraph()
            plot_title = plot_prefs[i].get("plot_title", "")
            if plot_title != "NoTitle":
                begin = ""
                end = ""
                if plot_prefs[i].has_key("starttime") and plot_prefs[i].has_key("endtime"):
                    begin = to_timestamp(plot_prefs[i]["starttime"])
                    end = to_timestamp(plot_prefs[i]["endtime"])
                elif gdata.key_type == "time":
                    begin = gdata.min_key
                    end = gdata.max_key
                if begin and end:
                    time_title = add_time_to_title(begin, end)
                    if plot_title:
                        plot_title += ":"
                    plot_prefs[i]["plot_title"] = plot_title + " " + time_title
            graphData.append(gdata)

        # Do not make legend for the plot with non-string keys (except for PieGraphs)
        if not graphData[0].subplots and graphData[0].key_type != "string" and not plot_type == "PieGraph":
            prefs["legend"] = False
        if prefs["legend"] and graphData[0].key_type != "string" and plot_type == "PieGraph":
            graphData[0].initialize(key_type="string")

        legend = Legend(graphData[0], None, prefs)
        self.figure = Figure()

        # Make Water Mark
        image = prefs.get("watermark", None)
        self.drawWaterMark(image)

        legend_ax, plot_axes = self.layoutFigure(legend)

        if DEBUG:
            print "makeGraph time layout", time.time() - start
            start = time.time()

        # Make plots
        for i in range(nPlots):
            plot_type = plot_prefs[i]["plot_type"]
            try:
                exec "import %s" % plot_type
            except ImportError, x:
                print "Failed to import graph type %s: %s" % (plot_type, str(x))
                return None

            ax = plot_axes[i]
            plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" % (plot_type, plot_type))
            plot.draw()
コード例 #11
0
ファイル: Graph.py プロジェクト: DIRACGrid/DIRAC
    def makeGraph(self, data, *args, **kw):

        start = time.time()

        # Evaluate all the preferences
        self.prefs = evalPrefs(*args, **kw)
        prefs = self.prefs

        if DEBUG:
            print("makeGraph time 1", time.time() - start)
            start = time.time()

        if "text_image" in prefs:
            self.makeTextGraph(str(prefs["text_image"]))
            return

        # Evaluate the number of plots and their requested layout
        metadata = prefs.get("metadata", {})
        plot_grid = prefs.get("plot_grid", "1:1")
        nx = int(plot_grid.split(":")[0])
        ny = int(plot_grid.split(":")[1])
        nPlots = nx * ny
        if nPlots == 1:
            if not isinstance(data, list):
                data = [data]
            if not isinstance(metadata, list):
                metadata = [metadata]
        else:
            if not isinstance(data, list):
                # return S_ERROR('Single data for multiplot graph')
                print("Single data for multiplot graph")
                return
            if not isinstance(metadata, list):
                metaList = []
                for _ in range(nPlots):
                    metaList.append(metadata)
                metadata = metaList

        # Initialize plot data
        graphData = []
        plot_prefs = []
        for i in range(nPlots):
            plot_prefs.append(evalPrefs(prefs, metadata[i]))
            gdata = GraphData(data[i])
            if i == 0:
                plot_type = plot_prefs[i]["plot_type"]
            if "sort_labels" in plot_prefs[i]:
                reverse = plot_prefs[i].get("reverse_labels", False)
                gdata.sortLabels(plot_prefs[i]["sort_labels"],
                                 reverse_order=reverse)
            if "limit_labels" in plot_prefs[i]:
                if plot_prefs[i]["limit_labels"] > 0:
                    gdata.truncateLabels(plot_prefs[i]["limit_labels"])
            if "cumulate_data" in plot_prefs[i]:
                gdata.makeCumulativeGraph()
            plot_title = plot_prefs[i].get("plot_title", "")
            if plot_title != "NoTitle":
                begin = ""
                end = ""
                if "starttime" in plot_prefs[i] and "endtime" in plot_prefs[i]:
                    begin = to_timestamp(plot_prefs[i]["starttime"])
                    end = to_timestamp(plot_prefs[i]["endtime"])
                elif gdata.key_type == "time":
                    begin = gdata.min_key
                    end = gdata.max_key
                if begin and end:
                    time_title = add_time_to_title(begin, end)
                    if plot_title:
                        plot_title += ":"
                    plot_prefs[i]["plot_title"] = plot_title + " " + time_title
            graphData.append(gdata)

        # Do not make legend for the plot with non-string keys (except for PieGraphs)
        if not graphData[0].subplots and graphData[
                0].key_type != "string" and not plot_type == "PieGraph":
            prefs["legend"] = False
        if prefs["legend"] and graphData[
                0].key_type != "string" and plot_type == "PieGraph":
            graphData[0].initialize(key_type="string")

        legend = Legend(graphData[0], None, prefs)
        self.figure = Figure()

        # Make Water Mark
        image = prefs.get("watermark", None)
        self.drawWaterMark(image)

        legend_ax, plot_axes = self.layoutFigure(legend)

        if DEBUG:
            print("makeGraph time layout", time.time() - start)
            start = time.time()

        # Make plots
        for i in range(nPlots):
            plot_type = plot_prefs[i]["plot_type"]
            try:
                # TODO: Remove when we moved to python3
                exec("import %s" % plot_type)
            except ImportError:
                print("Trying to use python like import")
                try:
                    exec("from . import  %s" % plot_type)
                except ImportError as x:
                    print("Failed to import graph type %s: %s" %
                          (plot_type, str(x)))
                    return None

            ax = plot_axes[i]
            plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" %
                        (plot_type, plot_type))
            plot.draw()

        if DEBUG:
            print("makeGraph time plots", time.time() - start)
            start = time.time()

        # Make legend
        if legend_ax:
            legend.setAxes(legend_ax)
            legend.draw()

        if DEBUG:
            print("makeGraph time legend", time.time() - start)
            start = time.time()