示例#1
0
文件: build.py 项目: Zalewa/doomstats
def _build_batch_statistics(batch):
    if _has_batch_statistics(batch):
        return
    engines = {}
    for server in batch.server_set.all():
        engine = server.engine
        if not engine.name in engines:
            e = BatchStatistics()
            e.batch = batch
            e.engine = engine
            engines[engine.name] = e
        e = engines[engine.name]
        e.server_count += 1
        e.human_player_count += Player.objects.filter(server__server=server, is_bot=False).count()
    for batchstats in engines.itervalues():
        print >>sys.stderr, "Saving batch stats: {0}".format(batchstats)
        batchstats.save()
示例#2
0
def stats_daterange_table(daterange, engine=None):
    counters = BatchStatistics.avg_in_daterange(engine, daterange)
    return Table(
        id="stats-daterange-table",
        header="Amounts in date range",
        rows=[
            ("Collected batches:", RefreshBatch.objects.filter(date__range=daterange).count()),
            ("Average server count:", DecimalCell(counters.server_count)),
            ("Average player count:", DecimalCell(counters.human_player_count))
        ])
示例#3
0
def _build_players_chart_data(daterange, engine):
    resolution = daterange_resolution(daterange)
    dateslices = RefreshBatch.slice(daterange, resolution)
    if not dateslices:
        return []
    if resolution == "day":
        dateformat = "%Y-%m-%d %a"
    elif resolution == "hour":
        if dateslices[0].date() == dateslices.last().date():
            dateformat = "%H:%M"
        else:
            dateformat = "%d %a %H:%M"
    rows = []
    for dateslice in dateslices:
        dateslice = timezone.localtime(dateslice, timezone.utc)
        if resolution == "day":
            nextdate = dateslice + timedelta(days=1)
        elif resolution == "hour":
            nextdate = dateslice + timedelta(hours=1)
        count = BatchStatistics.avg_in_daterange(engine, (dateslice, nextdate))
        rows.append((dateslice.strftime(dateformat), count.human_player_count))
    return rows