<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from datetime import timedelta
from django.utils.timezone import now

from libs.sql import get_total_tree_count, get_surveyed_species, \
    get_block_count_past_week

from apps.core.models import User

from apps.event.models import Event, EventRegistration
from apps.event.event_list import all_events, EventList

from apps.home.training import training_summary

from apps.survey.models import Blockface, Survey

from apps.users import user_profile_context


def home_page(request):
    if request.user.is_authenticated():
        context = user_profile_context(request.user)
        context.update(training_summary.get_context(request.user))
        context['counts_all'] = _global_counts()
        context['counts_week'] = _global_counts(past_week=True)

        event_reg = EventRegistration.next_event_starting_soon(request.user)
        if event_reg:
            context['event'] = event_reg.event
            context['did_attend_event'] = event_reg.did_attend
    else:
        context = {
            'user': request.user,
            'counts_all': _global_counts()
        }

    all_events_list = (
        all_events
        .configure(chunk_size=10,
                   filterset_name=EventList.userFilters,
                   active_filter=EventList.Filters.ATTENDING)
        .as_context(request))

    context.update({'all_events': all_events_list})
    return context


def _global_counts(past_week=False):
    blocks_total = Blockface.objects.all().count()
    if past_week:
        blocks_mapped = get_block_count_past_week()
    else:
        blocks_mapped = Survey.objects.complete().distinct('blockface').count()
    if blocks_mapped > 0:
        fraction_mapped = float(blocks_mapped) / float(blocks_total)
        fmt = "{:.0%}" if fraction_mapped >= .1 else "{:.1%}"
        blocks_percent = fmt.format(fraction_mapped)
    else:
        blocks_percent = "0.0%"
    if past_week:
        blocks_percent = '+' + blocks_percent

    user_count = User.objects.filter(is_active=True).count()<commit_msg>Always show one decimal place in dashboard progress percentage.<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from datetime import timedelta
from django.utils.timezone import now

from libs.sql import get_total_tree_count, get_surveyed_species, \
    get_block_count_past_week

from apps.core.models import User

from apps.event.models import Event, EventRegistration
from apps.event.event_list import all_events, EventList

from apps.home.training import training_summary

from apps.survey.models import Blockface, Survey

from apps.users import user_profile_context


def home_page(request):
    if request.user.is_authenticated():
        context = user_profile_context(request.user)
        context.update(training_summary.get_context(request.user))
        context['counts_all'] = _global_counts()
        context['counts_week'] = _global_counts(past_week=True)

        event_reg = EventRegistration.next_event_starting_soon(request.user)
        if event_reg:
            context['event'] = event_reg.event
            context['did_attend_event'] = event_reg.did_attend
    else:
        context = {
            'user': request.user,
            'counts_all': _global_counts()
        }

    all_events_list = (
        all_events
        .configure(chunk_size=10,
                   filterset_name=EventList.userFilters,
                   active_filter=EventList.Filters.ATTENDING)
        .as_context(request))

    context.update({'all_events': all_events_list})
    return context


def _global_counts(past_week=False):
    blocks_total = Blockface.objects.all().count()
    if past_week:
        blocks_mapped = get_block_count_past_week()
    else:
        blocks_mapped = Survey.objects.complete().distinct('blockface').count()
    if blocks_mapped > 0:
        fraction_mapped = float(blocks_mapped) / float(blocks_total)
        blocks_percent = "{:.1%}".format(fraction_mapped)
    else:
        blocks_percent = "0.0%"
    if past_week:
        blocks_percent = '+' + blocks_percent

    user_count = User.objects.filter(is_active=True).count()
{'fraction_non_alphanumeric': 0.09176850357389901, 'fraction_numerical': 0.0036891860733225734, 'mean_word_length': 3.351053159478435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1535133', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1279, 'n_words': 252}