Esempio n. 1
0
    def GetHeapGraph(self):
        if self.GetGraphType() != GRAPH_HEAP:
            return
        fontSize = 7.5
        fontFace = 'arial.ttc'
        wnd = self.GetWnd()
        wnd.sr.graph.Flush()
        w, h = wnd.sr.graph.absoluteRight - wnd.sr.graph.absoluteLeft, wnd.sr.graph.absoluteBottom - wnd.sr.graph.absoluteTop
        width = w
        height = h
        c = chart.XYChart(width, height, bgColor=chart.Transparent)
        c.setColors(chart.whiteOnBlackPalette)
        c.setBackground(chart.Transparent)
        c.setTransparentColor(-1)
        c.setAntiAlias(1, 1)
        offsX = 60
        offsY = 17
        canvasWidth = width - 1 * offsX - 50
        canvasHeight = height - offsY * 2.5
        plotArea = c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight,
                                 1711276032, -1, -1, 5592405)
        import random
        c.addLegend(85, 18, 0, fontFace,
                    fontSize).setBackground(chart.Transparent)
        random.seed(1001)
        for k, lst in self.heaphistory.iteritems():
            name = 'monitor_setting_heap_%s' % k
            if not settings.user.ui.Get(name, 1):
                continue
            memData = []
            timeData = []
            for t, n in lst:
                memData.append(n / 1024 / 1024)
                year, month, wd, day, hour, minutes, sec, ms = util.GetTimeParts(
                    t)
                timeData.append(
                    chart.chartTime(year, month, day, hour, minutes, sec))

            lines = c.addLineLayer()
            l = (random.randint(0, 15), random.randint(0, 255),
                 random.randint(0, 255))
            l = '0x%X%X%Xee' % (l[0], l[1], l[2])
            lines.addDataSet(memData, int(l, 16), '#%s' % k).setLineWidth(1)
            lines.setXData(timeData)

        c.xAxis().setDateScale3('{value|hh:nn}')
        leftAxis = c.yAxis()
        leftAxis.setTitle('Heap Size (MB)')
        buf = c.makeChart2(chart.PNG)
        hostBitmap = trinity.Tr2HostBitmap(w, h, 1,
                                           trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        hostBitmap.LoadFromPngInMemory(buf)
        linegr = uicls.Sprite(parent=wnd.sr.graph, align=uiconst.TOALL)
        linegr.GetMenu = self.GetHeapGraphMenu
        linegr.texture.atlasTexture = uicore.uilib.CreateTexture(width, height)
        linegr.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
Esempio n. 2
0
 def drawPic_mem(self, _list):
     self.num02 += 1
     self._label02.append(str(self.num02))
     self._data02.append(_list[1][0])
     c = pychartdir.XYChart(500, 400)
     c.setPlotArea(60, 40, 400, 300)
     c.addLineLayer(self._data02)
     c.xAxis().setLabels(self._label02)
     c.makeChart("tmp02.png")
     mImage = wx.Image("tmp02.png")
     mImage = mImage.Scale(500, 300)
     self.bitmap_mem.SetBitmap(wx.BitmapFromImage(mImage))
Esempio n. 3
0
 def drawPic(self, _list):
     self.num += 1
     self._label.append(str(self.num))
     self._data.append(_list[0][0])
     self.writeCsv(_list[0][0])
     c = pychartdir.XYChart(500, 400)
     c.setPlotArea(30, 20, 400, 300)
     c.addLineLayer(self._data)
     c.xAxis().setLabels(self._label)
     c.makeChart("tmp.png")
     mImage = wx.Image("tmp.png")
     mImage = mImage.Scale(500, 300)
     self.bitmap_cpu.SetBitmap(wx.BitmapFromImage(mImage))
Esempio n. 4
0
def GetPNGForUserHours(username, hours):
    '''
    @param username: Username of user for whom to get a stats PNG
    @param hours: user hours dict hour => minutes
    @return: bytes of a PNG of a chart presenting the minutes the user is
             signed on in each hour of the day.
    '''
    labels = ['%02d' % h for h in range(0, 24)]
    data = [hours[h] for h in range(0, 24)]
    chart = pychartdir.XYChart(700, 400)
    chart.addTitle('Total minutes per day for each hour for %s' % username)
    chart.setPlotArea(45, 20, 600, 300)
    chart.addBarLayer(data)
    chart.xAxis().setLabels(labels)
    chart.xAxis().setTitle('Hour during the day')
    chart.yAxis().setTitle('Average minutes per hour per day')
    return chart.makeChart2(pychartdir.PNG)
Esempio n. 5
0
 def CreateGraph(self, data, parent):
     l = [(k, v) for k, v in data.iteritems()]
     l.sort(key=lambda x: x[0])
     yData = [x[1] for x in l]
     xData = ['%.1fs' % (x[0] / 1000.0) for x in l]
     fontSize = 7.5
     fontFace = 'arial.ttc'
     width = parent.width
     height = int(parent.height * 0.4)
     c = chart.XYChart(width, height, bgColor=chart.Transparent)
     c.addTitle('Frametime in ms')
     c.setColors(chart.whiteOnBlackPalette)
     c.setBackground(chart.Transparent)
     c.setTransparentColor(-1)
     c.setAntiAlias(1, 1)
     offsX = 60
     offsY = 17
     canvasWidth = width - 1 * offsX - 50
     canvasHeight = height - offsY * 2.5
     c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight, 1711276032, -1,
                   -1, 5592405)
     c.addLegend(85, 18, 0, fontFace,
                 fontSize).setBackground(chart.Transparent)
     c.addLineLayer(yData)
     c.yAxis().setTitle('ms')
     c.xAxis().setLabels(xData)
     c.xAxis().setLabelStep(len(data) / 5)
     buf = c.makeChart2(chart.PNG)
     hostBitmap = trinity.Tr2HostBitmap(width, height, 1,
                                        trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
     hostBitmap.LoadFromPngInMemory(buf)
     graphSprite = Sprite(parent=parent, align=uiconst.TOALL)
     graphSprite.texture.atlasTexture = uicore.uilib.CreateTexture(
         width, height)
     graphSprite.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
     return graphSprite
Esempio n. 6
0
    def GetGraph(self):
        isPerf = False
        if self.GetGraphType() == GRAPH_PERFORMANCE:
            isPerf = True
        fontSize = 7.5
        fontFace = 'arial.ttc'
        wnd = self.GetWnd()
        wnd.sr.graph.Flush()
        w, h = wnd.sr.graph.absoluteRight - wnd.sr.graph.absoluteLeft, wnd.sr.graph.absoluteBottom - wnd.sr.graph.absoluteTop
        minutes = settings.user.ui.Get('monitor_setting_memory_time', 60)
        trend = blue.pyos.cpuUsage[-minutes * 60 / 10:]
        memCounters = {}
        perfCounters = {}
        mega = 1.0 / 1024.0 / 1024.0
        timeData = []
        memData = []
        pymemData = []
        bluememData = []
        othermemData = []
        workingsetData = []
        ppsData = []
        fpsData = []
        threadCpuData = []
        procCpuData = []
        lastT = lastpf = 0
        t1 = 0
        if len(trend) > 1:
            t, cpu, mem, sched = trend[0]
            lastT = t
            lastpf = mem[-1]
            t1 = trend[0][0]
        benice = blue.pyos.BeNice
        for t, cpu, mem, sched in trend:
            benice()
            elap = t - t1
            t1 = t
            mem, pymem, workingset, pagefaults, bluemem = mem
            fps, nr_1, ny, ns, dur, nr_2 = sched
            fpsData.append(fps)
            memData.append(mem * mega)
            pymemData.append(pymem * mega)
            bluememData.append(bluemem * mega)
            othermem = (mem - bluemem) * mega
            if othermem < 0:
                othermem = 0
            othermemData.append(othermem)
            workingsetData.append(workingset * mega)
            thread_u, proc_u, kernel_u, process_kernel_u = cpu
            if elap:
                thread_cpupct = thread_u / float(elap) * 100.0
                proc_cpupct = proc_u / float(elap) * 100.0
            else:
                thread_cpupct = proc_cpupct = 0.0
            threadCpuData.append(thread_cpupct)
            procCpuData.append(proc_cpupct)
            dt = t - lastT
            lastT = t
            pf = pagefaults - lastpf
            lastpf = pagefaults
            pps = pf / (dt * 1e-07) if dt else 0
            ppsData.append(pps)
            year, month, wd, day, hour, minutes, sec, ms = util.GetTimeParts(t)
            timeData.append(
                chart.chartTime(year, month, day, hour, minutes, sec))

        if len(ppsData) > 1:
            ppsData[0] = ppsData[1]
        memCounters['blue_memory'] = (False, bluememData, 3377390, 1, False)
        memCounters['other_memory'] = (False, othermemData, 16776960, 1, False)
        memCounters['python_memory'] = (False, pymemData, 65280, 1, False)
        memCounters['total_memory'] = (False, memData, 16711680, 2, False)
        memCounters['working_set'] = (False, workingsetData, 65535, 1, False)
        memCounters['thread_cpu'] = (True, threadCpuData, 6749952, 1, True)
        memCounters['fps'] = (True, fpsData, 16711680, 1, False)
        width = w
        height = h
        c = chart.XYChart(width, height, bgColor=chart.Transparent)
        c.setColors(chart.whiteOnBlackPalette)
        c.setBackground(chart.Transparent)
        c.setTransparentColor(-1)
        c.setAntiAlias(1, 1)
        offsX = 60
        offsY = 17
        canvasWidth = width - 1 * offsX - 50
        canvasHeight = height - offsY * 2.5
        plotArea = c.setPlotArea(offsX, offsY, canvasWidth, canvasHeight,
                                 1711276032, -1, -1, 5592405)
        c.addLegend(85, 18, 0, fontFace,
                    fontSize).setBackground(chart.Transparent)
        if len(timeData) > 1:
            c.xAxis().setDateScale3('{value|hh:nn}')
        lines = c.addLineLayer()
        lines2 = c.addLineLayer2()
        lines2.setUseYAxis2()
        leftAxis = c.yAxis()
        rightAxis = c.yAxis2()
        if isPerf:
            leftAxis.setTitle('Frames per second')
            rightAxis.setTitle('CPU (%)')
        else:
            leftAxis.setTitle('Memory (MB)')
        for i, k in enumerate(memCounters.keys()):
            if settings.user.ui.Get('monitor_setting_%s' % k, 1):
                title = k.replace('_', ' ').capitalize()
                if isPerf == memCounters[k][0]:
                    data = memCounters[k][1]
                    col = memCounters[k][2]
                    lineWidth = memCounters[k][3]
                    if not memCounters[k][4]:
                        l = lines
                    else:
                        l = lines2
                    l.addDataSet(data, col, title).setLineWidth(lineWidth)

        lines.setXData(timeData)
        lines2.setXData(timeData)
        if trend:
            pf = trend[-1][2][-1]
            label = 'Working set: %iMB, Virtual mem: %iMB, Page faults: %s' % (
                workingsetData[-1], memData[-1], util.FmtAmt(pf))
            c.addText(offsX, 2, label)
        buf = c.makeChart2(chart.PNG)
        hostBitmap = trinity.Tr2HostBitmap(w, h, 1,
                                           trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        hostBitmap.LoadFromPngInMemory(buf)
        linegr = uicls.Sprite(parent=wnd.sr.graph, align=uiconst.TOALL)
        linegr.GetMenu = self.GetGraphMenu
        linegr.texture.atlasTexture = uicore.uilib.CreateTexture(width, height)
        linegr.texture.atlasTexture.CopyFromHostBitmap(hostBitmap)
Esempio n. 7
0
def donor_radar_chart():

    d = request.args
    radar = d.get('radar')
    try:
        radar = json.loads(radar)  # donor_name, days, pontos_0, pontos_7
    except ValueError:
        return ''

    lowX, bigX = 0, 0
    lowY, bigY = sys.maxint, -sys.maxint - 1
    days, name, points, slope, y, x = list(), list(), list(), list(), list(
    ), list()

    for l in radar:
        days.append(l[1])
        name.append(l[0])
        points.append(float(l[2]))
        slope.append(float(l[3]) / 7)
        if len(points) == 1:
            x.append(0)
            y.append(0)
        else:
            x.append((points[-1] - points[0]) / (slope[0] - slope[-1]))
            y.append(points[-1])

    bigX = lowX + 100
    if len(x) > 1:
        if x[1] > lowX + 100: bigX = x[1]
    n = len(radar) - 1

    for i in range(n, 0, -1):
        if x[i] < bigX:
            n = i
            bigX = x[i]
            break

    x, y = list(), list()

    for i in range(0, n + 1):
        x.append([lowX, 1])
        y.append([points[i], 1])
        if y[i][0] < lowY: lowY = y[i][0]
        y[i][1] = slope[i] * bigX + points[i]
        if y[i][1] > bigY: bigY = y[i][1]
        x[i][1] = bigX

    chartX, chartY, plotX, plotY = 640, 300, 520, 220
    c = pychartdir.XYChart(chartX, chartY, pychartdir.Transparent)
    setPlotAreaObj = c.setPlotArea(80, 35, plotX, plotY)
    setPlotAreaObj.setGridColor(0xc0c0c0, 0xc0c0c0, -1, pychartdir.Transparent)
    c.setNumberFormat(',')
    layer = c.addLineLayer2()
    layer.setLineWidth(2)

    for i in range(0, n + 1):
        layer.addDataSet(y[i], -1, name[i])
        layer.setXData(x[i])

    xLabels = list()
    if bigX > 9:
        for i in range(0, 10):
            xLabels.append(locale.format('%.0f', bigX * i / 9.0, True))
    else:
        if bigX < 1: div = bigX
        else: div = int(bigX)
        i = 0
        while i <= max(1, bigX):
            xLabels.append(locale.format('%.1f', i, True))
            i += 1 if div == 0 else bigX / div

    yLabels = list()
    for i in range(0, 10):
        yLabels.append(
            locale.format('%.0f', (lowY + ((bigY - lowY) * i / 9.0)) / 100,
                          True))

    c.yAxis().setLinearScale2(lowY, bigY, yLabels)
    c.xAxis().setLinearScale2(lowX, bigX, xLabels)
    legend = c.addLegend(95, 40, 1, "normal", 11)
    legend.setBackground(pychartdir.Transparent, pychartdir.Transparent)
    legend.setFontColor(0x202020)
    c.yAxis().setLabelStyle("normal", 8)
    c.xAxis().setLabelStyle("normal", 8)
    c.yAxis().setTitle("Hundred Points", "normal", 10)
    c.xAxis().setTitle("Days", "normal", 10)

    m = pychartdir.MultiChart(chartX, chartY, 0xfafafa)
    m.addChart(0, 0, c)
    m.addTitle("Radar Scope", "normal", 13)

    response = make_response(m.makeChart2(pychartdir.PNG))
    response.headers['Content-type'] = 'image/png'
    return response
Esempio n. 8
0
def team_history_chart():

    d = request.args
    history = d.get('history')
    try:
        history = json.loads(history) # points, wus, day, dow
    except ValueError:
        return ''

    #history = history[:-1]
    day = list();
    dayX = list();
    points = list();
    pointsPerWu = list();
    i = 0;
    min_dow = min((d[3] for d in history))
    max_points = max((d[0] for d in history))
    if max_points >= 100000:
        divider = 1000
        points_title = "Points (1,000)"
        wus_title = "Points per WU (1,000)"
    else:
        divider = 1
        points_title = "Points"
        wus_title = "Points per WU"
    for i, d in enumerate(history):
        if d[3] == min_dow:
            day.append(d[2][-5:])
        else:
            day.append('-')
        dayX.append(i)
        points.append(d[0] / divider)
        if d[1] == 0:
            pointsPerWu.append(0)
        else:
            pointsPerWu.append(d[0] / d[1])

    chartX, chartY, plotX, plotY = 640, 300, 520, 220
    c = pychartdir.XYChart(chartX, chartY, pychartdir.Transparent)
    setPlotAreaObj = c.setPlotArea(60, 35, plotX, plotY)
    setPlotAreaObj.setGridColor(0xc0c0c0, 0xc0c0c0, -1, pychartdir.Transparent)
    c.setNumberFormat(',')
    legend = c.addLegend(60, 10, 0, "vera.ttf", 10)
    legend.setBackground(pychartdir.Transparent)
    layer = c.addLineLayer()
    dataSetObj = layer.addDataSet(points, 0xbb0000, points_title)
    dataSetObj.setDataSymbol(pychartdir.CircleSymbol, 5, 0xdd0000, 0xdd0000)
    layer.setLineWidth(1)

    curve = pychartdir.ArrayMath(points)
    curve.lowess()
    splineLayerObj = c.addSplineLayer(curve.result(), 0xff0000, "")
    splineLayerObj.setLineWidth(2)
    c.xAxis().setLabels(day)
    c.yAxis().setAutoScale(0.01, 0.01, 0.1)
    c.yAxis().setColors(0x000000, 0xbb0000)
    c.xAxis().setTickLength2(6,3)
    labelStyleObj = c.xAxis().setLabelStyle("normal", 8)
    labelStyleObj.setFontAngle(0)
    labelStyleObj.setPos(0, 5)
    trendLayerObj = c.addTrendLayer(points, c.dashLineColor(0xbb0000, pychartdir.DashLine), "")
    trendLayerObj.setLineWidth(2)

    c2 = pychartdir.XYChart(chartX, chartY, pychartdir.Transparent)
    c2.setPlotArea(60, 35, plotX, plotY, pychartdir.Transparent, -1, pychartdir.Transparent, pychartdir.Transparent, pychartdir.Transparent)
    c2.setNumberFormat(',')
    legend = c2.addLegend(420, 10, 0, "normal", 10)
    legend.setBackground(pychartdir.Transparent)
    c2.yAxis().setAutoScale(0.01, 0.01, 0.1)
    c2.yAxis().setColors(0x000000, 0x004400)
    c2.setYAxisOnRight()
    layer = c2.addLineLayer()
    dataSetObj = layer.addDataSet(pointsPerWu, 0x004400, wus_title)
    dataSetObj.setDataSymbol(pychartdir.CircleSymbol, 5, 0x00bb00, 0x00bb00)
    layer.setLineWidth(1)
    m = pychartdir.MultiChart(chartX, chartY, 0xfafafa)
    m.addChart(0, 0, c2)
    m.addChart(0, 0, c)
    title = m.addTitle("Daily (UTC) Production History", "normal", 13)

    response = make_response(m.makeChart2(pychartdir.PNG))
    response.headers['Content-type'] = 'image/png'
    return response
Esempio n. 9
0
def team_size_chart():

    d = request.args
    history = d.get('history')
    try:
        history = json.loads(history)  # nm, am, day
    except ValueError:
        return ''

    am, am_x, nm, nm_x = [], [], [], []

    am_title = "Active Members"
    nm_title = "New Members"

    d = history[0]
    am.append(pychartdir.NoValue if d[0] is None else d[0])
    am_x.append(dt(d[2]))
    nm.append(pychartdir.NoValue if d[1] is None else d[1])
    nm_x.append(dt(d[2]))
    for d in history[1:-2]:
        nm.append(pychartdir.NoValue if d[1] is None else d[1])
        nm_x.append(dt(d[2]))
        if d[0] is not None:
            am.append(d[0])
            am_x.append(dt(d[2]))
    d = history[-1]
    am.append(pychartdir.NoValue if d[0] is None else d[0])
    am_x.append(dt(d[2]))
    nm.append(pychartdir.NoValue if d[1] is None else d[1])
    nm_x.append(dt(d[2]))

    #return repr([am, am_x, nm, nm_x])

    chartX, chartY, plotX, plotY = 640, 300, 520, 220
    c = pychartdir.XYChart(chartX, chartY, 0xfafafa)
    c.addTitle("Team Size History", "normal", 13)
    c.yAxis().setAutoScale(0.01, 0.01, 0.1)
    c.yAxis().setColors(0x000000, 0xbb0000)
    c.xAxis().setTickLength2(6, 3)
    c.xAxis().setLabelFormat('{value|mm-dd}')
    c.setNumberFormat(',')
    setPlotAreaObj = c.setPlotArea(60, 35, plotX, plotY)
    setPlotAreaObj.setGridColor(0xc0c0c0, 0xc0c0c0, -1, pychartdir.Transparent)
    legend = c.addLegend(60 + plotX / 2, 10, 0, "vera.ttf", 10)
    legend.setBackground(pychartdir.Transparent)
    legend.setAlignment(pychartdir.Top)

    layer = c.addLineLayer()
    layer.setXData(am_x)
    dataSetObj = layer.addDataSet(am, 0xbb0000, am_title)
    dataSetObj.setDataSymbol(pychartdir.CircleSymbol, 3, 0xdd0000, 0xdd0000)
    layer.setLineWidth(1)

    curve = pychartdir.ArrayMath(am)
    curve.lowess2(am_x)
    splineLayerObj = c.addSplineLayer(curve.result(), 0xff0000, "")
    splineLayerObj.setXData(am_x)
    splineLayerObj.setLineWidth(2)

    labelStyleObj = c.xAxis().setLabelStyle("normal", 8)
    labelStyleObj.setFontAngle(0)
    labelStyleObj.setPos(0, 5)
    trendLayerObj = c.addTrendLayer(
        am, c.dashLineColor(0xbb0000, pychartdir.DashLine), "")
    trendLayerObj.setLineWidth(2)
    trendLayerObj.setXData(am_x)

    c.yAxis2().setAutoScale(0.01, 0.01, 0.1)
    c.yAxis2().setColors(0x000000, 0x004400)

    layer = c.addLineLayer()
    layer.setUseYAxis2()
    layer.setXData(nm_x)
    dataSetObj = layer.addDataSet(nm, 0x004400, nm_title)
    dataSetObj.setDataSymbol(pychartdir.CircleSymbol, 3, 0x00bb00, 0x00bb00)
    layer.setLineWidth(1)

    response = make_response(c.makeChart2(pychartdir.PNG))
    response.headers['Content-type'] = 'image/png'
    return response