Beispiel #1
0
    def serverstats_svg(self, curr_url=None):
        if not config.config.HTTP_CONFIG.enable_svg_generation:
            return ""
        stats = self.lastStat
        ppd = list(stats['numPlayersOnlinePerDay'])
        x = []
        y = []
        major_x = []
        idx = 0
        lastLabel = None

        if len(ppd) > 0:
            minDate = min([x['datetime'].date() for x in ppd])
            maxDate = max([x['datetime'].date() for x in ppd])

            for i in range((maxDate - minDate).days + 1):
                d = minDate + datetime.timedelta(i)
                if idx < len(ppd) and ppd[idx]['datetime'].date() == d:
                    y.append(ppd[idx]['count'])
                    idx += 1
                else:
                    y.append(0)
                x.append(d)
                if d.month != lastLabel:
                    lastLabel = d.month
                    major_x.append(d)
                else:
                    pass
                #x.append("")
            num_days = (maxDate - minDate).days + 1
        else:
            num_days = 0
        line_chart = DateLine(pygalConfig,
                              fill=True,
                              dots_size=1,
                              x_label_rotation=35)
        line_chart.title = 'Server usage over %d days' % num_days
        line_chart.add('Drivers online', zip(x, y))
        #line_chart.x_value_formatter = lambda d: d.isoformat()
        #line_chart.x_labels = list(map(line_chart.x_value_formatter, x))
        #line_chart.x_labels_major = list(map(line_chart.x_value_formatter, major_x))

        return line_chart.render()