Ejemplo n.º 1
0
def dashboard(request):
    from wouso.games.quest.models import Quest, QuestGame
    from django import get_version
    from wouso.settings import WOUSO_VERSION

    future_questions = Schedule.objects.filter(
        day__gte=datetime.datetime.now())
    nr_future_questions = len(future_questions)

    questions = Question.objects.all()
    nr_questions = len(questions)
    active_quest = QuestGame().get_current()
    total_quests = Quest.objects.all().count()

    # artifacts
    artifact_groups = Group.objects.all()

    # admins
    staff_group, new = auth.Group.objects.get_or_create(name='Staff')

    return render_to_response('cpanel/index.html', {
        'nr_future_questions': nr_future_questions,
        'nr_questions': nr_questions,
        'active_quest': active_quest,
        'total_quests': total_quests,
        'module': 'home',
        'artifact_groups': artifact_groups,
        'django_version': get_version(),
        'wouso_version': WOUSO_VERSION,
        'staff': staff_group,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        from wouso.games.quest.models import Quest, QuestGame
        from django import get_version
        from wouso.settings import WOUSO_VERSION, DATABASES
        from wouso.core.config.models import Setting

        database = DATABASES['default'].copy()
        database_engine = database['ENGINE'].split('.')[-1]
        database_name = database['NAME']

        future_questions = Schedule.objects.filter(
            day__gte=datetime.datetime.now())
        nr_future_questions = len(future_questions)
        questions = Question.objects.all()
        nr_questions = len(questions)
        active_quest = QuestGame().get_current()
        total_quests = Quest.objects.all().count()

        # artifacts
        artifact_groups = ArtifactGroup.objects.all()

        # admins
        staff_group, new = auth.Group.objects.get_or_create(name='Staff')

        # wousocron last_run
        last_run = Setting.get('wousocron_lastrun').get_value()
        if last_run == "":
            last_run = "wousocron was never run"

        # online members
        oldest = datetime.datetime.now() - datetime.timedelta(minutes=10)
        online_last10 = Player.objects.filter(
            last_seen__gte=oldest).order_by('-last_seen')

        # number of players which can play
        cp_number = Player.objects.filter(race__can_play=True).count()

        context = super(DashboardView, self).get_context_data(**kwargs)
        context.update({
            'nr_future_questions': nr_future_questions,
            'nr_questions': nr_questions,
            'active_quest': active_quest,
            'total_quests': total_quests,
            'artifact_groups': artifact_groups,
            'django_version': get_version(),
            'wouso_version': WOUSO_VERSION,
            'database_engine': database_engine,
            'database_name': database_name,
            'staff': staff_group,
            'last_run': last_run,
            'online_users': online_last10,
            'cp_number': cp_number
        })
        return context
Ejemplo n.º 3
0
def dashboard(request):
    from wouso.games.quest.models import Quest, QuestGame
    from django import get_version
    from wouso.settings import WOUSO_VERSION
    from wouso.core.config.models import Setting

    future_questions = Schedule.objects.filter(
        day__gte=datetime.datetime.now())
    nr_future_questions = len(future_questions)

    questions = Question.objects.all()
    nr_questions = len(questions)
    active_quest = QuestGame().get_current()
    total_quests = Quest.objects.all().count()

    # artifacts
    artifact_groups = ArtifactGroup.objects.all()

    # admins
    staff_group, new = auth.Group.objects.get_or_create(name='Staff')

    # wousocron last_run
    last_run = Setting.get('wousocron_lastrun').get_value()
    if last_run == "":
        last_run = "wousocron was never run"

    # online members
    oldest = datetime.datetime.now() - datetime.timedelta(minutes=10)
    online_last10 = Player.objects.filter(
        last_seen__gte=oldest).order_by('-last_seen')

    # number of players which can play
    cp_number = Player.objects.filter(race__can_play=True).count()

    return render_to_response('cpanel/index.html', {
        'nr_future_questions': nr_future_questions,
        'nr_questions': nr_questions,
        'active_quest': active_quest,
        'total_quests': total_quests,
        'module': 'home',
        'artifact_groups': artifact_groups,
        'django_version': get_version(),
        'wouso_version': WOUSO_VERSION,
        'staff': staff_group,
        'last_run': last_run,
        'online_users': online_last10,
        'cp_number': cp_number,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 4
0
 def quest_points(user):
     return int(History.objects.filter(game=QuestGame.get_instance(),
         user=user).aggregate(points=Sum('amount'))['points'] or 0)
Ejemplo n.º 5
0
def extra_stats(request):
    """
    Generate extra statistics, dump them as JSON

    * Numărul de jucători care au accesat în 95% din zile site-ul
    * Numărul total de provocări rulate
    * Numărul maxim de provocări jucate într-o zi
    * Media numărul de provocări jucate într-o zi
    * Numărul de jucători care au răspuns la cel puțin 75% din QoTD-uri
    * Numărul mediu de răspunsuri pe zi la QotD
    * Media numărului de jucători care au ajuns cel puțin la nivelul 5 din
      weekly quest (vezi câți au ajuns la nivelul 5 din weekly quest în
      fiecare weekly quest și apoi faci media lor).
    * Media numărului de jucători care au ajuns la nivelul 10 din
      weekly quest
    * Pentru final quest (când se va încheia): câți jucători l-au început,
      câți l-au terminat, câți au ajuns cel puțin la nivelul 25, 20, 15.
    """
    data = {}

    # Seen
    seen_basequery = Activity.objects.filter(action='seen')
    seen_days_count = seen_basequery.dates('timestamp', 'day').count()
    s95 = int(0.95 * seen_days_count)
    su95 = 0
    for u in seen_basequery.values('user_from').distinct():
        if seen_basequery.filter(user_from=u['user_from']).dates(
                'timestamp', 'day').count() >= s95:
            su95 += 1
    data['seen_all_days'] = seen_days_count
    data['seen_more_than_95'] = su95

    # Challenge
    chall_basequery = Challenge.objects.filter(status__in=('P', 'D'))
    chall_counts = []
    for d in chall_basequery.dates('date', 'day'):
        chall_counts.append(
            chall_basequery.filter(date__range=(d, d +
                                                timedelta(days=1))).count())
    data['challenge_all'] = chall_basequery.count()
    data['challenge_all_days'] = chall_basequery.dates('date', 'day').count()
    data['challenge_min_perday'] = min(chall_counts)
    data['challenge_max_perday'] = max(chall_counts)

    # Qotd
    qotd_basequery = Activity.objects.filter(action__in=('qotd-correct',
                                                         'qotd-wrong'))
    qotd_days = qotd_basequery.dates('timestamp', 'day').count()
    q75 = int(0.75 * qotd_days)
    qu75 = 0
    for u in qotd_basequery.values('user_from').distinct():
        cnt = qotd_basequery.filter(user_from=u['user_from']).count()
        if cnt > q75:
            qu75 += 1
    data['qotd_all'] = qotd_basequery.count()
    data['qotd_all_days'] = qotd_days
    data['qotd_perday_average'] = int(1.0 * data['qotd_all'] /
                                      data['qotd_all_days'])
    data['qotd_answered_more_75'] = qu75

    # Quest
    ql5 = 0
    ql10 = 0
    for quest in Quest.objects.all():
        if quest.is_final():
            continue
        ql5 += quest.questresult_set.filter(level__gte=5).count()
        ql10 += quest.questresult_set.filter(level__gte=10).count()
    qall = Quest.objects.all().count()
    if QuestGame.final_exists():
        qall -= 1

    if qall:
        ql5 = int(1.0 * ql5 / qall)
        ql10 = int(1.0 * ql10 / qall)
    data['quest_reached_5'] = ql5
    data['quest_reached_10'] = ql10

    # Pack and print
    return HttpResponse(json.dumps(data))
Ejemplo n.º 6
0
def extra_stats(request):
    """
    Generate extra statistics, dump them as JSON

    * Numărul de jucători care au accesat în 95% din zile site-ul
    * Numărul total de provocări rulate
    * Numărul maxim de provocări jucate într-o zi
    * Media numărul de provocări jucate într-o zi
    * Numărul de jucători care au răspuns la cel puțin 75% din QoTD-uri
    * Numărul mediu de răspunsuri pe zi la QotD
    * Media numărului de jucători care au ajuns cel puțin la nivelul 5 din
      weekly quest (vezi câți au ajuns la nivelul 5 din weekly quest în
      fiecare weekly quest și apoi faci media lor).
    * Media numărului de jucători care au ajuns la nivelul 10 din
      weekly quest
    * Pentru final quest (când se va încheia): câți jucători l-au început,
      câți l-au terminat, câți au ajuns cel puțin la nivelul 25, 20, 15.
    """
    data = {}

    # Seen
    seen_basequery = Activity.objects.filter(action='seen')
    seen_days_count = seen_basequery.dates('timestamp', 'day').count()
    s95 = int(0.95 * seen_days_count)
    su95 = 0
    for u in seen_basequery.values('user_from').distinct():
        if seen_basequery.filter(user_from=u['user_from']).dates('timestamp', 'day').count() >= s95:
            su95 += 1
    data['seen_all_days'] = seen_days_count
    data['seen_more_than_95'] = su95

    # Challenge
    chall_basequery = Challenge.objects.filter(status__in=('P', 'D'))
    chall_counts = []
    for d in chall_basequery.dates('date', 'day'):
        chall_counts.append(chall_basequery.filter(date__range=(d, d + timedelta(days=1))).count())
    data['challenge_all'] = chall_basequery.count()
    data['challenge_all_days'] = chall_basequery.dates('date', 'day').count()
    data['challenge_min_perday'] = min(chall_counts)
    data['challenge_max_perday'] = max(chall_counts)

    # Qotd
    qotd_basequery = Activity.objects.filter(action__in=('qotd-correct', 'qotd-wrong'))
    qotd_days = qotd_basequery.dates('timestamp', 'day').count()
    q75 = int(0.75 * qotd_days)
    qu75 = 0
    for u in qotd_basequery.values('user_from').distinct():
        cnt = qotd_basequery.filter(user_from=u['user_from']).count()
        if cnt > q75:
            qu75 += 1
    data['qotd_all'] = qotd_basequery.count()
    data['qotd_all_days'] = qotd_days
    data['qotd_perday_average'] = int(1.0 * data['qotd_all'] / data['qotd_all_days'])
    data['qotd_answered_more_75'] = qu75

    # Quest
    ql5 = 0
    ql10 = 0
    for quest in Quest.objects.all():
        if quest.is_final():
            continue
        ql5 += quest.questresult_set.filter(level__gte=5).count()
        ql10 += quest.questresult_set.filter(level__gte=10).count()
    qall = Quest.objects.all().count()
    if QuestGame.final_exists():
        qall -= 1

    if qall:
        ql5 = int(1.0 * ql5 / qall)
        ql10 = int(1.0 * ql10 / qall)
    data['quest_reached_5'] = ql5
    data['quest_reached_10'] = ql10

    # Pack and print
    return HttpResponse(json.dumps(data))