Exemplo n.º 1
0
def dashboard(request):

    context = get_default_context(page="dashboard")

    context.update(
        {
            "operators": [
                (
                    operator,
                    HotlineEvent.objects.filter(
                        operator=operator, processed=False, event_type__in=HotlineEvent.HOTLINE_TYPES
                    ).count(),
                )
                for operator in operators()
            ]
        }
    )

    if request.method == "POST":

        try:
            nb_numbers = int(request.POST.get("nb_numbers", NB_NUMBERS))
        except ValueError:
            nb_numbers = NB_NUMBERS

        operator = request.POST.get("operator_request")
        if not operator in operators():
            context.update({"error": "L'opérateur demandé (%s) " "n'est pas correct" % operator})

        events = HotlineEvent.objects.filter(
            operator=operator, processed=False, event_type__in=HotlineEvent.HOTLINE_TYPES
        ).order_by("received_on")[:nb_numbers]

        for event in events:
            event.processed = True
            event.volunteer = request.user
            event.save()

        context.update(
            {
                "events": events,
                "requested": True,
                "operator": operator,
                # 'user_number': user_number,
                "nb_numbers": nb_numbers,
            }
        )

    return render(request, "dashboard.html", context)
Exemplo n.º 2
0
def dashboard(request):

    context = get_default_context(page='dashboard')

    context.update({
        'operators': [(operator,
                       HotlineEvent.objects.filter(
                           operator=operator,
                           processed=False,
                           event_type__in=HotlineEvent.HOTLINE_TYPES).count())
                      for operator in operators()]
    })

    if request.method == 'POST':

        try:
            nb_numbers = int(request.POST.get('nb_numbers', NB_NUMBERS))
        except ValueError:
            nb_numbers = NB_NUMBERS

        operator = request.POST.get('operator_request')
        if not operator in operators():
            context.update({
                'error':
                "L'opérateur demandé (%s) "
                "n'est pas correct" % operator
            })

        events = HotlineEvent.objects.filter(operator=operator,
                                             processed=False,
                                             event_type__in=HotlineEvent.HOTLINE_TYPES) \
                                     .order_by('received_on')[:nb_numbers]

        for event in events:
            event.processed = True
            event.volunteer = request.user
            event.save()

        context.update({
            'events': events,
            'requested': True,
            'operator': operator,
            # 'user_number': user_number,
            'nb_numbers': nb_numbers
        })

    return render(request, "dashboard.html", context)
Exemplo n.º 3
0
    def handle(self, *args, **kwargs):
        count_ext = 0
        for identity in HotlineEvent.objects.values('identity').distinct():
            indicator, number = clean_phone_number(identity.get('identity'))
            if indicator != '223':
                count_ext += 1

        count = [(operator, HotlineEvent.objects.filter(
            operator=operator).values('identity').distinct().count())
                 for operator in operators()] + [("Exterieur", count_ext)],
        for operator, opcount in count[0]:
            print(operator)
            print(opcount)
Exemplo n.º 4
0
    def handle(self, *args, **kwargs):
        count_ext = 0
        for identity in HotlineEvent.objects.values('identity').distinct():
            indicator, number = clean_phone_number(identity.get('identity'))
            if indicator != '223':
                count_ext += 1

        count = [(operator, HotlineEvent.objects.filter(operator=operator)
                                                .values('identity').distinct()
                                                .count())
                  for operator in operators()] + [("Exterieur", count_ext)],
        for operator, opcount in count[0]:
            print(operator)
            print(opcount)
Exemplo n.º 5
0
def get_status_context():
    ''' return the context for status '''
    context = {}
    try:
        last_event = HotlineEvent.objects.latest('received_on')
    except HotlineEvent.DoesNotExist:
        last_event = []

    total_events = HotlineEvent.objects.count()
    total_unique_number = HotlineEvent.objects.values(
        'identity').distinct().count()

    per_event_type = {}
    for event_type in HotlineEvent.TYPES:
        per_event_type.update({
            event_type[0]:
            (event_type[1],
             HotlineEvent.objects.filter(event_type=event_type[0]).count())
        })

    untreated_count = HotlineEvent.objects.filter(processed=False).count()
    not_archived = count_unarchived_sms()
    sex_unknown = HotlineResponse.objects.filter(sex=HotlineResponse.SEX_UNKNOWN).count() + \
                                          len([1 for e in HotlineEvent.objects.all() if not e.archived])
    sex_male = HotlineResponse.objects.filter(
        sex=HotlineResponse.SEX_MALE).count()
    sex_female = HotlineResponse.objects.filter(
        sex=HotlineResponse.SEX_FEMALE).count()

    unknown_count = HotlineResponse.objects.filter(location=None).count()
    total = HotlineResponse.objects.all().count()
    try:
        unknown_percent = unknown_count * 100 / total
    except ZeroDivisionError:
        unknown_percent = 0

    under_18 = stats_per_age(0, 18)
    stats_19_25 = stats_per_age(19, 25)
    stats_26_30 = stats_per_age(26, 30)
    stats_31_35 = stats_per_age(31, 35)
    stats_36_40 = stats_per_age(36, 40)
    stats_41_45 = stats_per_age(41, 45)
    stats_46_50 = stats_per_age(46, 50)
    stats_55_56 = stats_per_age(51, 55)
    other_56 = stats_per_age(56, 180)

    unknown_age = HotlineResponse.objects.filter(age=None).count()
    try:
        unknown_age_percent = unknown_age * 100 / total
    except ZeroDivisionError:
        unknown_age_percent = 0

    context.update({
        'last_event':
        last_event,
        'total_events':
        total_events,
        'total_unique_number':
        total_unique_number,
        'per_event_type':
        per_event_type,
        'untreated_count':
        untreated_count,
        'sex_unknown':
        sex_unknown,
        'sex_male':
        sex_male,
        'sex_female':
        sex_female,
        'operators':
        [(operator, HotlineEvent.objects.filter(operator=operator).count())
         for operator in operators()],
        'under_18':
        under_18,
        'stats_19_25':
        stats_19_25,
        'stats_26_30':
        stats_26_30,
        'stats_31_35':
        stats_31_35,
        'stats_36_40':
        stats_36_40,
        'stats_41_45':
        stats_41_45,
        'stats_46_50':
        stats_46_50,
        'stats_55_56':
        stats_55_56,
        'other_56':
        other_56,
        'unknown_age':
        unknown_age,
        'unknown_age_percent':
        unknown_age_percent,
        'topics_stats_details':
        topic_stats_details(),
        'regions_located_responses': [
            regions_located_responses(region)
            for region in list(Entity.objects.filter(type='region'))
        ] + [("Inconnue", unknown_count, unknown_percent)],
        'not_archived':
        not_archived
    })
    return context
Exemplo n.º 6
0
def get_status_context():
    """ return the context for status """
    context = {}
    try:
        last_event = HotlineEvent.objects.latest("received_on")
    except HotlineEvent.DoesNotExist:
        last_event = []

    total_events = HotlineEvent.objects.count()
    total_unique_number = HotlineEvent.objects.values("identity").distinct().count()

    per_event_type = {}
    for event_type in HotlineEvent.TYPES:
        per_event_type.update(
            {event_type[0]: (event_type[1], HotlineEvent.objects.filter(event_type=event_type[0]).count())}
        )

    untreated_count = HotlineEvent.objects.filter(processed=False).count()
    not_archived = count_unarchived_sms()
    sex_unknown = HotlineResponse.objects.filter(sex=HotlineResponse.SEX_UNKNOWN).count() + len(
        [1 for e in HotlineEvent.objects.all() if not e.archived]
    )
    sex_male = HotlineResponse.objects.filter(sex=HotlineResponse.SEX_MALE).count()
    sex_female = HotlineResponse.objects.filter(sex=HotlineResponse.SEX_FEMALE).count()

    unknown_count = HotlineResponse.objects.filter(location=None).count()
    total = HotlineResponse.objects.all().count()
    try:
        unknown_percent = unknown_count * 100 / total
    except ZeroDivisionError:
        unknown_percent = 0

    under_18 = stats_per_age(0, 18)
    stats_19_25 = stats_per_age(19, 25)
    stats_26_30 = stats_per_age(26, 30)
    stats_31_35 = stats_per_age(31, 35)
    stats_36_40 = stats_per_age(36, 40)
    stats_41_45 = stats_per_age(41, 45)
    stats_46_50 = stats_per_age(46, 50)
    stats_55_56 = stats_per_age(51, 55)
    other_56 = stats_per_age(56, 180)

    unknown_age = HotlineResponse.objects.filter(age=None).count()
    try:
        unknown_age_percent = unknown_age * 100 / total
    except ZeroDivisionError:
        unknown_age_percent = 0

    context.update(
        {
            "last_event": last_event,
            "total_events": total_events,
            "total_unique_number": total_unique_number,
            "per_event_type": per_event_type,
            "untreated_count": untreated_count,
            "sex_unknown": sex_unknown,
            "sex_male": sex_male,
            "sex_female": sex_female,
            "operators": [
                (operator, HotlineEvent.objects.filter(operator=operator).count()) for operator in operators()
            ],
            "under_18": under_18,
            "stats_19_25": stats_19_25,
            "stats_26_30": stats_26_30,
            "stats_31_35": stats_31_35,
            "stats_36_40": stats_36_40,
            "stats_41_45": stats_41_45,
            "stats_46_50": stats_46_50,
            "stats_55_56": stats_55_56,
            "other_56": other_56,
            "unknown_age": unknown_age,
            "unknown_age_percent": unknown_age_percent,
            "topics_stats_details": topic_stats_details(),
            "regions_located_responses": [
                regions_located_responses(region) for region in list(Entity.objects.filter(type="region"))
            ]
            + [("Inconnue", unknown_count, unknown_percent)],
            "not_archived": not_archived,
        }
    )
    return context