示例#1
0
 def LineGraph(self):
     self.main.Flush()
     if not self.data:
         return
     self.minGridLineHeight = 32
     timeStamps, volData, closeData, lowData, highData = self.SplitData(
         self.data)
     width, height = self.main.GetAbsoluteSize()
     width = float(width)
     height = float(height)
     n = len(self.data)
     self.maxValue = float(max(highData))
     adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(
         height, self.maxValue, self.minGridLineHeight)
     gridLineStep = height / numGridLines
     donchianHighData = graphsutil.MovingHigh(highData)
     donchianLowData = graphsutil.MovingLow(lowData)
     movingAvg = graphsutil.MovingAvg(closeData, n=20)
     labelsAndGrid = Container(parent=self.main, align=uiconst.TOALL)
     self.axisLabels = VerticalAxisLabels(parent=labelsAndGrid,
                                          align=uiconst.TORIGHT,
                                          width=80,
                                          padLeft=8,
                                          labelClass=Label,
                                          fontsize=16,
                                          maxValue=adjustedMaxValue,
                                          step=gridLineStep,
                                          count=numGridLines)
     gridAndGraphs = Container(parent=labelsAndGrid, align=uiconst.TOALL)
     self.graphContainer = Container(parent=gridAndGraphs,
                                     align=uiconst.TOALL)
     self.grid = Grid(parent=gridAndGraphs,
                      maxValue=adjustedMaxValue,
                      step=gridLineStep,
                      count=numGridLines)
     self.lowHighValue = LowHighValueGraph(parent=self.graphContainer,
                                           data=(lowData, highData,
                                                 closeData),
                                           maxValue=adjustedMaxValue,
                                           markerSize=6)
     self.donchianHigh = LineGraph(parent=self.graphContainer,
                                   lineWidth=1.25,
                                   data=donchianHighData,
                                   maxValue=adjustedMaxValue)
     self.donchianLow = LineGraph(parent=self.graphContainer,
                                  lineWidth=1.25,
                                  data=donchianLowData,
                                  maxValue=adjustedMaxValue)
     self.movingAvg = LineGraph(parent=self.graphContainer,
                                lineWidth=1.25,
                                data=movingAvg,
                                maxValue=adjustedMaxValue)
     self.donchianChannel = DonchianChannel(parent=self.graphContainer,
                                            color=(0.25, 0, 0, 0.25),
                                            data=(donchianLowData,
                                                  donchianHighData),
                                            maxValue=adjustedMaxValue)
     gridlegends.AddHorizontalGridLines(self.gridContainer, numGridLines,
                                        gridLineStep, height, width)
示例#2
0
    def Build(self):
        self.minGridLineHeight = 32
        self.graph.Flush()
        self.legend.Flush()
        self.isBuilding = True
        minutes = 60
        self.data = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        startTime = self.data[0][0]
        endTime = startTime
        for t, cpu, mem, sched in self.data:
            mem, pymem, workingset, pagefaults, bluemem = mem
            memData.append(mem)
            pymemData.append(pymem)
            bluememData.append(bluemem)
            othermem = mem - bluemem
            othermemData.append(othermem)
            workingsetData.append(workingset)
            endTime = t

        maxValues = []
        for each in [memData,
         pymemData,
         bluememData,
         othermemData,
         workingsetData]:
            maxValues.append(max(each))

        self.overallMaxValue = max(maxValues)
        bottom = Container(parent=self.graph, align=uiconst.TOBOTTOM, height=24)
        Fill(parent=bottom, align=uiconst.TOLEFT, width=80, spriteEffect=trinity.TR2_SFX_NONE)
        self.horizontalAxisLabels = HorizontalAxisLabels(parent=bottom, align=uiconst.TOBOTTOM, height=24, padRight=8, labelClass=Label, fontsize=12, minValue=startTime, maxValue=endTime, step=64, formatter=_TimeLabel)
        self.axisLabels = VerticalAxisLabels(parent=self.graph, align=uiconst.TOLEFT, width=80, padRight=8, labelClass=Label, fontsize=16, formatter=lambda x: str(int(x * 1e-06)))
        self.grid = Grid(parent=self.graph)
        self.graphContainer = Container(parent=self.graph, align=uiconst.TOALL)
        Fill(parent=self.graph, color=(0, 0, 0, 0.25))
        Fill(parent=self.legend, align=uiconst.TOLEFT, width=80, spriteEffect=trinity.TR2_SFX_NONE)
        self.graphs = []
        graphSources = [(memData, Color.RED, 'Total memory'),
         (pymemData, Color.GREEN, 'Python memory'),
         (bluememData, Color.BLUE, 'Blue memory'),
         (othermemData, Color.YELLOW, 'Other memory'),
         (workingsetData, Color.AQUA, 'Working set')]
        for source, color, text in graphSources:
            graph = LineGraph(parent=self.graphContainer, color=color, lineWidth=1, data=source, spriteEffect=trinity.TR2_SFX_FILL)
            self.graphs.append(graph)
            self.AddLegend(color, text, graph)

        self.AdjustForSize()
        self.isBuilding = False
    def Build(self):
        self.minGridLineHeight = 32
        self.graph.Flush()
        self.isBuilding = True
        minutes = 60
        self.data = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        for t, cpu, mem, sched in self.data:
            mem, pymem, workingset, pagefaults, bluemem = mem
            memData.append(mem)
            pymemData.append(pymem)
            bluememData.append(bluemem)
            othermem = mem - bluemem
            othermemData.append(othermem)
            workingsetData.append(workingset)

        maxValues = []
        for each in [memData,
         pymemData,
         bluememData,
         othermemData,
         workingsetData]:
            maxValues.append(max(each))

        self.overallMaxValue = max(maxValues)
        width, height = self.graph.GetAbsoluteSize()
        height = float(height)
        adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(height, self.overallMaxValue, self.minGridLineHeight)
        gridLineStep = height / numGridLines
        labelsAndGrid = Container(parent=self.graph, align=uiconst.TOALL)
        self.axisLabels = VerticalAxisLabels(parent=labelsAndGrid, align=uiconst.TOLEFT, width=80, padRight=8, labelClass=Label, fontsize=16, maxValue=adjustedMaxValue, step=gridLineStep, count=numGridLines)
        self.grid = Grid(parent=labelsAndGrid, maxValue=adjustedMaxValue, step=gridLineStep, count=numGridLines)
        self.graphContainer = Container(parent=labelsAndGrid, align=uiconst.TOALL)
        Fill(parent=labelsAndGrid, color=(0, 0, 0, 0.25))
        self.graphs = []
        graphSources = [(memData, Color.RED),
         (pymemData, Color.GREEN),
         (bluememData, Color.BLUE),
         (othermemData, Color.YELLOW),
         (workingsetData, Color.AQUA)]
        for source, color in graphSources:
            graph = LineGraph(parent=self.graphContainer, color=color, lineWidth=1, data=source, maxValue=adjustedMaxValue, spriteEffect=trinity.TR2_SFX_FILL)
            self.graphs.append(graph)

        self.isBuilding = False
class MemoryMonitor(uicontrols.Window):
    __guid__ = 'form.MemoryMonitor'
    default_caption = 'Memory Monitor'
    default_minSize = (400, 200)
    default_windowID = 'MemoryMonitor'

    def ApplyAttributes(self, attributes):
        uicontrols.Window.ApplyAttributes(self, attributes)
        self.SetTopparentHeight(0)
        self.graph = Container(parent=self.sr.main, align=uiconst.TOALL)
        self.data = None
        self.graphs = []
        self.isBuilding = False
        self.isResizing = False
        uthread2.StartTasklet(self.UpdateGraph)

    def UpdateGraph(self):
        while not self.destroyed:
            if not self.isResizing:
                self.Build()
            uthread2.Sleep(0.5)

    def Build(self):
        self.minGridLineHeight = 32
        self.graph.Flush()
        self.isBuilding = True
        minutes = 60
        self.data = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        for t, cpu, mem, sched in self.data:
            mem, pymem, workingset, pagefaults, bluemem = mem
            memData.append(mem)
            pymemData.append(pymem)
            bluememData.append(bluemem)
            othermem = mem - bluemem
            othermemData.append(othermem)
            workingsetData.append(workingset)

        maxValues = []
        for each in [memData,
         pymemData,
         bluememData,
         othermemData,
         workingsetData]:
            maxValues.append(max(each))

        self.overallMaxValue = max(maxValues)
        width, height = self.graph.GetAbsoluteSize()
        height = float(height)
        adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(height, self.overallMaxValue, self.minGridLineHeight)
        gridLineStep = height / numGridLines
        labelsAndGrid = Container(parent=self.graph, align=uiconst.TOALL)
        self.axisLabels = VerticalAxisLabels(parent=labelsAndGrid, align=uiconst.TOLEFT, width=80, padRight=8, labelClass=Label, fontsize=16, maxValue=adjustedMaxValue, step=gridLineStep, count=numGridLines)
        self.grid = Grid(parent=labelsAndGrid, maxValue=adjustedMaxValue, step=gridLineStep, count=numGridLines)
        self.graphContainer = Container(parent=labelsAndGrid, align=uiconst.TOALL)
        Fill(parent=labelsAndGrid, color=(0, 0, 0, 0.25))
        self.graphs = []
        graphSources = [(memData, Color.RED),
         (pymemData, Color.GREEN),
         (bluememData, Color.BLUE),
         (othermemData, Color.YELLOW),
         (workingsetData, Color.AQUA)]
        for source, color in graphSources:
            graph = LineGraph(parent=self.graphContainer, color=color, lineWidth=1, data=source, maxValue=adjustedMaxValue, spriteEffect=trinity.TR2_SFX_FILL)
            self.graphs.append(graph)

        self.isBuilding = False

    def ResizeGraphs(self):
        if self.isBuilding:
            return
        if not self.data:
            return
        self.isResizing = True
        width, height = self.graphContainer.GetAbsoluteSize()
        adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(height, self.overallMaxValue, self.minGridLineHeight)
        for graph in self.graphs:
            graph.maxValue = adjustedMaxValue
            graph.Rebuild()

        gridLineStep = height / numGridLines
        self.axisLabels.maxValue = adjustedMaxValue
        self.axisLabels.count = numGridLines
        self.axisLabels.step = gridLineStep
        self.axisLabels.Rebuild()
        self.grid.count = numGridLines
        self.grid.step = gridLineStep
        self.grid.Rebuild()
        self.isResizing = False

    def _OnSizeChange_NoBlock(self, width, height):
        self.ResizeGraphs()
示例#5
0
 def AddGrid(self):
     self.grid = Grid(parent=self.graphCont,
                      verticalAxis=self.leftAxis,
                      horizontalAxis=self.topAxis)
示例#6
0
class MemoryGraph(Container):
    horizontalLabelWidth = 64

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.isBuilding = True
        info = Container(parent=self, align=uiconst.TOTOP, height=64)
        EngineInfoPanel(parent=info, align=uiconst.TOLEFT_PROP, width=0.8)
        infoRight = Container(parent=info, align=uiconst.TOALL)
        refreshRate = blue.pyos.performanceUpdateFrequency / 10000000.0
        self.refreshRateEdit = SinglelineEdit(parent=infoRight, align=uiconst.TOTOP, label='Refresh rate (seconds):', setvalue=refreshRate, floats=(0.1, 10.0), OnChange=OnRefreshRateEdit)
        self.legend = Container(parent=self, align=uiconst.TOBOTTOM, height=16)
        self.graph = Container(parent=self, align=uiconst.TOALL)
        self.data = None
        self.graphs = []
        self.isBuilding = False
        self.isResizing = False

    def UpdateGraph(self):
        while not self.destroyed:
            if not self.isResizing:
                self.Build()
            uthread2.Sleep(0.5)

    def AddLegend(self, color, text, graph):
        fill = Fill(parent=self.legend, color=color, align=uiconst.TOLEFT, state=uiconst.UI_NORMAL, width=16)
        fill.OnMouseEnter = lambda : _OnMouseEnterLegend(graph)
        fill.OnMouseExit = lambda : _OnMouseExitLegend(graph)
        Label(parent=self.legend, text=text, align=uiconst.TOLEFT, padLeft=8, padRight=16)

    def Build(self):
        self.minGridLineHeight = 32
        self.graph.Flush()
        self.legend.Flush()
        self.isBuilding = True
        minutes = 60
        self.data = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        startTime = self.data[0][0]
        endTime = startTime
        for t, cpu, mem, sched in self.data:
            mem, pymem, workingset, pagefaults, bluemem = mem
            memData.append(mem)
            pymemData.append(pymem)
            bluememData.append(bluemem)
            othermem = mem - bluemem
            othermemData.append(othermem)
            workingsetData.append(workingset)
            endTime = t

        maxValues = []
        for each in [memData,
         pymemData,
         bluememData,
         othermemData,
         workingsetData]:
            maxValues.append(max(each))

        self.overallMaxValue = max(maxValues)
        bottom = Container(parent=self.graph, align=uiconst.TOBOTTOM, height=24)
        Fill(parent=bottom, align=uiconst.TOLEFT, width=80, spriteEffect=trinity.TR2_SFX_NONE)
        self.horizontalAxisLabels = HorizontalAxisLabels(parent=bottom, align=uiconst.TOBOTTOM, height=24, padRight=8, labelClass=Label, fontsize=12, minValue=startTime, maxValue=endTime, step=64, formatter=_TimeLabel)
        self.axisLabels = VerticalAxisLabels(parent=self.graph, align=uiconst.TOLEFT, width=80, padRight=8, labelClass=Label, fontsize=16, formatter=lambda x: str(int(x * 1e-06)))
        self.grid = Grid(parent=self.graph)
        self.graphContainer = Container(parent=self.graph, align=uiconst.TOALL)
        Fill(parent=self.graph, color=(0, 0, 0, 0.25))
        Fill(parent=self.legend, align=uiconst.TOLEFT, width=80, spriteEffect=trinity.TR2_SFX_NONE)
        self.graphs = []
        graphSources = [(memData, Color.RED, 'Total memory'),
         (pymemData, Color.GREEN, 'Python memory'),
         (bluememData, Color.BLUE, 'Blue memory'),
         (othermemData, Color.YELLOW, 'Other memory'),
         (workingsetData, Color.AQUA, 'Working set')]
        for source, color, text in graphSources:
            graph = LineGraph(parent=self.graphContainer, color=color, lineWidth=1, data=source, spriteEffect=trinity.TR2_SFX_FILL)
            self.graphs.append(graph)
            self.AddLegend(color, text, graph)

        self.AdjustForSize()
        self.isBuilding = False

    def AdjustForSize(self):
        width, height = self.graphContainer.GetAbsoluteSize()
        adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(height, self.overallMaxValue, self.minGridLineHeight)
        for graph in self.graphs:
            graph.maxValue = adjustedMaxValue
            graph.Rebuild()

        gridLineStep = height / numGridLines
        self.axisLabels.maxValue = adjustedMaxValue
        self.axisLabels.count = numGridLines
        self.axisLabels.step = gridLineStep
        self.axisLabels.Rebuild()
        self.horizontalAxisLabels.count = width / self.horizontalLabelWidth
        self.horizontalAxisLabels.Rebuild()
        self.grid.count = numGridLines
        self.grid.step = gridLineStep
        self.grid.Rebuild()

    def ResizeGraphs(self):
        if self.isBuilding:
            return
        if not self.data:
            return
        self.isResizing = True
        self.AdjustForSize()
        self.isResizing = False

    def _OnSizeChange_NoBlock(self, width, height):
        self.ResizeGraphs()
示例#7
0
class GraphsTest(uicontrols.Window):
    __guid__ = 'form.GraphsTest'
    default_caption = 'Graphs Test'
    default_minSize = (400, 200)
    default_windowID = 'GraphsTest'

    def ApplyAttributes(self, attributes):
        uicontrols.Window.ApplyAttributes(self, attributes)
        self.SetTopparentHeight(0)
        self.topPanel = Container(parent=self.sr.main,
                                  align=uiconst.TOTOP,
                                  height=30)
        uicontrols.Button(parent=self.topPanel,
                          align=uiconst.TOLEFT,
                          label='Graph',
                          width=120,
                          height=30,
                          func=self.Graph)
        self.main = Container(parent=self.sr.main, align=uiconst.TOALL)
        self.data = []

    def Graph(self, *args):
        self.data = self.RandomData(60)
        self.LineGraph()

    def RandomData(self, numValues=30):
        values = []
        prev_low = random.randint(5, 300)
        for i in xrange(numValues):
            volume = random.randint(100, 100000)
            low = random.randint(max(prev_low - 30, 5), prev_low + 30)
            high = random.randint(low, low + 10)
            close = random.randint(low, high)
            timestamp = i
            values.append((timestamp, low, high, close, volume))
            prev_low = low

        return values

    def SplitData(self, values):
        timeStamps = []
        volData = []
        closeData = []
        lowData = []
        highData = []
        for x in values:
            timeStamps.append(x[0])
            volData.append(x[4])
            closeData.append(x[3])
            lowData.append(x[1])
            highData.append(x[2])

        return (timeStamps, volData, closeData, lowData, highData)

    def LineGraph(self):
        self.main.Flush()
        if not self.data:
            return
        self.minGridLineHeight = 32
        timeStamps, volData, closeData, lowData, highData = self.SplitData(
            self.data)
        width, height = self.main.GetAbsoluteSize()
        width = float(width)
        height = float(height)
        n = len(self.data)
        self.maxValue = float(max(highData))
        adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(
            height, self.maxValue, self.minGridLineHeight)
        gridLineStep = height / numGridLines
        donchianHighData = graphsutil.MovingHigh(highData)
        donchianLowData = graphsutil.MovingLow(lowData)
        movingAvg = graphsutil.MovingAvg(closeData, n=20)
        labelsAndGrid = Container(parent=self.main, align=uiconst.TOALL)
        self.axisLabels = VerticalAxisLabels(parent=labelsAndGrid,
                                             align=uiconst.TORIGHT,
                                             width=80,
                                             padLeft=8,
                                             labelClass=Label,
                                             fontsize=16,
                                             maxValue=adjustedMaxValue,
                                             step=gridLineStep,
                                             count=numGridLines)
        gridAndGraphs = Container(parent=labelsAndGrid, align=uiconst.TOALL)
        self.graphContainer = Container(parent=gridAndGraphs,
                                        align=uiconst.TOALL)
        self.grid = Grid(parent=gridAndGraphs,
                         maxValue=adjustedMaxValue,
                         step=gridLineStep,
                         count=numGridLines)
        self.lowHighValue = LowHighValueGraph(parent=self.graphContainer,
                                              data=(lowData, highData,
                                                    closeData),
                                              maxValue=adjustedMaxValue,
                                              markerSize=6)
        self.donchianHigh = LineGraph(parent=self.graphContainer,
                                      lineWidth=1.25,
                                      data=donchianHighData,
                                      maxValue=adjustedMaxValue)
        self.donchianLow = LineGraph(parent=self.graphContainer,
                                     lineWidth=1.25,
                                     data=donchianLowData,
                                     maxValue=adjustedMaxValue)
        self.movingAvg = LineGraph(parent=self.graphContainer,
                                   lineWidth=1.25,
                                   data=movingAvg,
                                   maxValue=adjustedMaxValue)
        self.donchianChannel = DonchianChannel(parent=self.graphContainer,
                                               color=(0.25, 0, 0, 0.25),
                                               data=(donchianLowData,
                                                     donchianHighData),
                                               maxValue=adjustedMaxValue)
        gridlegends.AddHorizontalGridLines(self.gridContainer, numGridLines,
                                           gridLineStep, height, width)

    def ResizeLineGraph(self):
        if not self.data:
            return
        width, height = self.graphContainer.GetAbsoluteSize()
        adjustedMaxValue, numGridLines = graphsutil.AdjustMaxValue(
            height, self.maxValue, self.minGridLineHeight)
        for graph in [
                self.donchianHigh, self.donchianLow, self.movingAvg,
                self.donchianChannel, self.lowHighValue
        ]:
            graph.maxValue = adjustedMaxValue
            graph.Rebuild()

        gridLineStep = height / numGridLines
        self.axisLabels.maxValue = adjustedMaxValue
        self.axisLabels.count = numGridLines
        self.axisLabels.step = gridLineStep
        self.axisLabels.Rebuild()
        self.grid.count = numGridLines
        self.grid.step = gridLineStep
        self.grid.Rebuild()

    def _OnSizeChange_NoBlock(self, width, height):
        self.ResizeLineGraph()