示例#1
0
    def getStatTime(self, type):
        d = self.stats.getProgress('time')
        max = d[0]
        items = []
        h = 4 * cm  # max height

        if type == "frames":
            # header time
            items.append(
                Frame(1 * cm,
                      19.3 * cm,
                      19 * cm,
                      1 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))

            for k in d:
                if k == 0:
                    continue
                items.append(
                    Frame(1.67 * cm + (k - 1) * 21,
                          14.8 * cm,
                          6, (len(d[k]["visitors"]) * h / max["max_u"]) + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # row 1
                items.append(
                    Frame(1.67 * cm + (k - 1) * 21 + 6,
                          14.8 * cm,
                          6, (len(d[k]["different"]) * h / max["max_p"]) + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # row 1
                items.append(
                    Frame(1.67 * cm + (k - 1) * 21 + 12,
                          14.8 * cm,
                          6, (len(d[k]["items"]) * h / max["max"]) + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # row 1

            items.append(
                Frame(1 * cm,
                      13.2 * cm,
                      19 * cm,
                      2 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))  # legend
            # value table
            items.append(
                Frame(1 * cm,
                      1.0 * cm,
                      19 * cm,
                      12.5 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))

        if type == "data":
            items.append(
                Paragraph(t(self.language, "edit_stats_spreading_time"),
                          self.chartheader))

            for k in d:
                if k == 0:
                    continue
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_baruser_vert.png",
                             width=6,
                             height=len(d[k]["visitors"]) * h / max["max_u"] +
                             1))
                items.append(FrameBreak())
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_barpage_vert.png",
                             width=6,
                             height=len(d[k]["different"]) * h / max["max_p"] +
                             1))
                items.append(FrameBreak())
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_bar_vert.gif",
                             width=6,
                             height=len(d[k]["items"]) * h / max["max"] + 1))
                items.append(FrameBreak())

            t_data = []
            for i in range(0, 24):
                im = PdfImage(config.basedir + "/web/img/stat_hr" +
                              ustr(i % 12 + 1) + ".png",
                              width=14,
                              height=14)
                p = Paragraph((ustr(i) + "-" + ustr(i + 1)), self.bv)
                t_data.append([p, im])

            tb = Table([t_data], 24 * [21], [40])
            tb.setStyle(
                TableStyle([
                    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                    ('BOX', (0, 0), (-1, -1), 1, colors.black),
                    ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
                    ('FONTSIZE', (0, 0), (-1, -1), 7),
                ]))
            items.append(tb)

            t_data = [['%02d:00-%02d:00' % (i, i + 1)] for i in range(0, 24)]
            for k in d:
                if k == 0:
                    continue
                t_data[k - 1] += [len(d[k][key]) for key in d[k].keys()]
            t_data = [[
                t(self.language, "edit_stats_daytime"),
                t(self.language, "edit_stats_diffusers").replace(
                    "<br/>", "\n"),
                t(self.language, "edit_stats_pages"),
                t(self.language, "edit_stats_access")
            ]] + t_data

            tb = Table(t_data, 4 * [70], [25] + [13] * 24)
            tb.setStyle(
                TableStyle([
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                    ('BOX', (0, 0), (-1, -1), 1, colors.black),
                    ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
                    ('FONTSIZE', (0, 0), (-1, -1), 7),
                    ('BACKGROUND', (1, 0), (1, 0), colors.HexColor('#fff11d')),
                    ('BACKGROUND', (2, 0), (2, 0), colors.HexColor('#2ea495')),
                    ('BACKGROUND', (3, 0), (3, 0), colors.HexColor('#84a5ef')),
                ]))
            items.append(tb)
        return items
示例#2
0
    def getStatDay(self, type):
        d = self.stats.getProgress('day')
        max = d[0]
        items = []

        h = 4 * cm  # max height
        l = 2 * cm  # left space
        b = 21.5 * cm  # bottom

        if type == "frames":
            # header weekday
            items.append(
                Frame(1 * cm,
                      26.0 * cm,
                      19 * cm,
                      1 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))
            for k in d:
                if k == 0:
                    continue
                items.append(
                    Frame(l + (k - 1) * 17,
                          b,
                          16,
                          len(d[k]["visitors"]) * h / max["max_u"] + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # col 1
                items.append(
                    Frame(l + (k - 1) * 17 + 5,
                          b,
                          16,
                          len(d[k]["different"]) * h / max["max_p"] + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # col 2
                items.append(
                    Frame(l + (k - 1) * 17 + 10,
                          b,
                          16,
                          len(d[k]["items"]) * h / max["max"] + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # col 3

            items.append(
                Frame(l + 5,
                      b - 1.1 * cm,
                      119,
                      1.5 * cm,
                      id='normal',
                      showBoundary=0))
            items.append(
                Frame(8 * cm,
                      b - 1.4 * cm,
                      11 * cm,
                      6 * cm,
                      id='normal',
                      showBoundary=0))

        if type == "data":
            items.append(
                Paragraph(t(self.language, "edit_stats_spreading_day"),
                          self.chartheader))

            for k in d:
                if k == 0:
                    continue
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_baruser_vert.png",
                             width=5,
                             height=len(d[k]["visitors"]) * h / max["max_u"] +
                             1))
                items.append(FrameBreak())
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_barpage_vert.png",
                             width=5,
                             height=len(d[k]["different"]) * h / max["max_p"] +
                             1))
                items.append(FrameBreak())
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_bar_vert.gif",
                             width=6,
                             height=len(d[k]["items"]) * h / max["max"] + 1))
                items.append(FrameBreak())

            tb = Table([[
                t(self.language, "dayname_" + ustr(x) + "_short")
                for x in range(0, 7)
            ]], 7 * [17], 17)
            tb.setStyle(
                TableStyle([
                    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                    ('BOX', (0, 0), (-1, -1), 1, colors.black),
                    ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
                    ('FONTSIZE', (0, 0), (-1, -1), 7),
                    ('BACKGROUND', (5, 0), (-1, -1),
                     colors.HexColor('#E6E6E6')),
                ]))
            items.append(tb)
            items.append(FrameBreak())

            t_data = [[t(self.language, "dayname_" + ustr(x) + "_long")]
                      for x in range(0, 7)]

            for k in d:
                if k == 0:
                    continue
                t_data[k - 1] += [len(d[k][key]) for key in d[k].keys()]
            t_data = [[
                t(self.language, "edit_stats_weekday"),
                t(self.language, "edit_stats_diffusers").replace(
                    "<br/>", "\n"),
                t(self.language, "edit_stats_pages"),
                t(self.language, "edit_stats_access")
            ]] + t_data

            tb = Table(t_data, 4 * [70], [25] + 7 * [16])
            tb.setStyle(
                TableStyle([
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                    ('BOX', (0, 0), (-1, -1), 1, colors.black),
                    ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
                    ('FONTSIZE', (0, 0), (-1, -1), 7),
                    ('BACKGROUND', (1, 0), (1, 0), colors.HexColor('#fff11d')),
                    ('BACKGROUND', (2, 0), (2, 0), colors.HexColor('#2ea495')),
                    ('BACKGROUND', (3, 0), (3, 0), colors.HexColor('#84a5ef')),
                ]))
            items.append(tb)
        return items
示例#3
0
    def getStatCountry(self, type):
        items = []
        d = self.stats.getProgress('country')
        max = float(d[0]["max"])

        if type == "frames":
            # header country
            items.append(
                Frame(1 * cm,
                      26.0 * cm,
                      19 * cm,
                      1 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))
            i = 0
            for v in sorted([(len(d[k]['items']), k)
                             for k in filter(lambda x: x != 0, d.keys())],
                            reverse=True):
                if v[0] != 0:
                    items.append(
                        Frame(1 * cm, (25.1 - (i * 0.5)) * cm,
                              3 * cm,
                              25,
                              leftPadding=0,
                              rightPadding=0,
                              id='normal',
                              showBoundary=0))  # label
                    items.append(
                        Frame(4 * cm, (25.2 - (i * 0.5)) * cm,
                              v[0] * 400 / max,
                              25,
                              leftPadding=0,
                              rightPadding=0,
                              id='normal',
                              showBoundary=0))  # bar
                    items.append(
                        Frame(4 * cm + (v[0] * 400 / max) + 5,
                              (25.1 - (i * 0.5)) * cm,
                              40,
                              25,
                              leftPadding=0,
                              rightPadding=0,
                              id='normal',
                              showBoundary=0))  # number
                    i += 1

        if type == "data":
            items.append(
                Paragraph(t(self.language, "edit_stats_country"),
                          self.chartheader))
            items.append((FrameBreak()))

            for v in sorted([(len(d[k]['items']), k)
                             for k in filter(lambda x: x != 0, d.keys())],
                            reverse=True)[:50]:
                if v[0] != 0:
                    items.append(Paragraph(ustr(v[1]), self.bv))
                    items.append((FrameBreak()))
                    items.append(
                        PdfImage(config.basedir + "/web/img/stat_bar.png",
                                 width=v[0] * 400 / max,
                                 height=10))
                    items.append((FrameBreak()))
                    items.append(Paragraph(ustr(v[0]), self.bv))
                    items.append((FrameBreak()))

            items = items[:-1]
        return items
示例#4
0
    def getStatDate(self, type):
        items = []
        d = self.stats.getProgress()
        max = d[0]

        if type == "frames":
            # header date
            items.append(
                Frame(1 * cm,
                      26.0 * cm,
                      19 * cm,
                      1 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))
            x = (32 -
                 len(d)) * 8  # add left space if month with less than 31 days

            for k in d:
                if k == 0:
                    continue
                items.append(
                    Frame(1 * cm + (k - 1) * 17 + 9 + x,
                          18.9 * cm,
                          5,
                          len(d[k]["visitors"]) * (6 * cm) / max["max_u"] + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # col 1
                items.append(
                    Frame(1 * cm + (k - 1) * 17 + 14 + x,
                          18.9 * cm,
                          5,
                          len(d[k]["different"]) * (6 * cm) / max["max_p"] +
                          16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # col 2
                items.append(
                    Frame(1 * cm + (k - 1) * 17 + 19 + x,
                          18.9 * cm,
                          5,
                          len(d[k]["items"]) * (6 * cm) / max["max"] + 16,
                          leftPadding=0,
                          rightPadding=0,
                          id='normal',
                          showBoundary=0))  # col 3

            # legend table with days
            items.append(
                Frame(1 * cm,
                      17.8 * cm,
                      19 * cm,
                      1.5 * cm,
                      leftPadding=4,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))
            # table with values
            items.append(
                Frame(1 * cm,
                      1 * cm,
                      19 * cm,
                      16 * cm,
                      leftPadding=4,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))

        if type == "data":
            items.append(
                Paragraph(t(self.language, "edit_stats_spreading"),
                          self.chartheader))
            items.append(FrameBreak())

            for k in d:
                if k == 0:
                    continue
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_baruser_vert.png",
                             width=5,
                             height=((len(d[k]["visitors"]) *
                                      (6 * cm) / max["max_u"] + 1) or 1)))
                items.append(FrameBreak())
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_barpage_vert.png",
                             width=5,
                             height=((len(d[k]["different"]) *
                                      (6 * cm) / max["max_p"] + 1) or 1)))
                items.append(FrameBreak())
                items.append(
                    PdfImage(config.basedir + "/web/img/stat_bar_vert.gif",
                             width=5,
                             height=((len(d[k]["items"]) *
                                      (6 * cm) / max["max"] + 1) or 1)))
                items.append(FrameBreak())

            t_data = []
            weekend = []
            for k in d:
                if k > 0:  # first item holds max values
                    if self.stats.getWeekDay(k) > 4:
                        weekend.append(('BACKGROUND', (k - 1, 0), (k - 1, -1),
                                        colors.HexColor('#E6E6E6')))
                    t_data.append(
                        '%02d \n%s' %
                        (k,
                         t(
                             self.language, "monthname_" +
                             ustr(int(self.period[-2:])) + "_short")))

            tb = Table([t_data], 31 * [17], 30)
            tb.setStyle(
                TableStyle([
                    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                    ('BOX', (0, 0), (-1, -1), 1, colors.black),
                    ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
                    ('FONTSIZE', (0, 0), (-1, -1), 7),
                ] + weekend))
            items.append(tb)
            items.append(FrameBreak())

            t_data = [[
                t(self.language, "edit_stats_day"),
                t(self.language,
                  "edit_stats_diffusers").replace("<br/>", "\n"),
                t(self.language, "edit_stats_pages"),
                t(self.language, "edit_stats_access")
            ]]  # +31*[4*[2]]
            weekend = []
            for k in d:
                if k > 0:  # first item holds max values
                    if self.stats.getWeekDay(k) > 4:
                        weekend.append(('BACKGROUND', (0, k), (-1, k),
                                        colors.HexColor('#E6E6E6')))
                    t_data.append([
                        '%02d.%s %s' % (k,
                                        t(
                                            self.language, "monthname_" +
                                            ustr(int(self.period[-2:])) +
                                            "_short"), self.period[:4]),
                        len(d[k]["visitors"]),
                        len(d[k]["different"]),
                        len(d[k]["items"])
                    ])

            tb = Table(t_data, 4 * [100], [25] + (len(d) - 1) * [12])
            tb.setStyle(
                TableStyle([
                    ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
                    ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
                    ('INNERGRID', (0, 0), (-1, -1), 1, colors.black),
                    ('BOX', (0, 0), (-1, -1), 1, colors.black),
                    ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
                    ('FONTSIZE', (0, 0), (-1, -1), 7),
                    ('BACKGROUND', (1, 0), (1, 0), colors.HexColor('#fff11d')),
                    ('BACKGROUND', (2, 0), (2, 0), colors.HexColor('#2ea495')),
                    ('BACKGROUND', (3, 0), (3, 0), colors.HexColor('#84a5ef')),
                ] + weekend))
            items.append(tb)
        return items
示例#5
0
    def getStatTop(self, type, namecut=0):
        # frames
        items = []
        d = self.stats.getIDs()
        max = float(d[0][1])
        if max == 0:
            max += 1
        if type == "frames":
            items.append(
                Frame(1 * cm,
                      24.0 * cm,
                      19 * cm,
                      1 * cm,
                      leftPadding=0,
                      rightPadding=0,
                      id='normal',
                      showBoundary=0))  # header
            for i in range(0, 45):
                if i < len(d):
                    items.append(
                        Frame(1 * cm, (22.9 - (i * 0.5)) * cm,
                              8 * cm,
                              25,
                              leftPadding=0,
                              rightPadding=0,
                              id='normal',
                              showBoundary=0))  # label
                    items.append(
                        Frame(9 * cm, (23.0 - (i * 0.5)) * cm,
                              d[i][1] * 280 / max,
                              25,
                              leftPadding=0,
                              rightPadding=0,
                              id='normal',
                              showBoundary=0))  # bar
                    items.append(
                        Frame(9 * cm + (d[i][1] * 280 / max) + 5,
                              (22.9 - (i * 0.5)) * cm,
                              40,
                              25,
                              leftPadding=0,
                              rightPadding=0,
                              id='normal',
                              showBoundary=0))  # number

        # data
        if type == "data":
            items.append(
                Paragraph(t(self.language, "edit_stats_access"),
                          self.chartheader))
            items.append((FrameBreak()))

            for i in range(0, 45):
                if i < len(d):
                    try:
                        nodename = q(Node).get(d[i][0]).name
                        suffix = " (" + ustr(d[i][0]) + ")"
                        n = nodename + suffix
                        if namecut > 0 and len(n) > namecut:
                            delta = len(n) - namecut
                            new_length = len(nodename) - delta - 3
                            n = nodename[0:new_length] + "..." + suffix
                    except:
                        n = ustr(d[i][0])
                    items.append(Paragraph(n, self.bv))
                    items.append((FrameBreak()))
                    items.append(
                        PdfImage(config.basedir + "/web/img/stat_bar.png",
                                 width=d[i][1] * 280 / max,
                                 height=10))
                    items.append((FrameBreak()))
                    items.append(Paragraph(ustr(d[i][1]), self.bv))
                    items.append((FrameBreak()))
        return items