<commit_before>from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required

from servicerating.models import Response

import math
import csv


def empty_response_map():
    response_map = {
        'question_1_friendliness':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            },
        'question_2_waiting_times_feel':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            },
        'question_3_waiting_times_length':
            {
                'less-than-an-hour': 0,
                'between-1-and-3-hours': 0,
                'more-than-4-hours': 0,
                'all-day': 0
            },
        'question_4_cleanliness':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            },
        'question_5_privacy':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            }
    }
    return response_map


@login_required
def dashboard(request):
    averages = {}

    all_responses = Response.objects.all()
    num_questions = 5.0
    total_responses = 0

    response_map = empty_response_map()

    for response in all_responses:
        total_responses += 1
        response_map[response.key][response.value] += 1

    num_ratings = math.ceil(total_responses / num_questions)

    averages_questions = [
        'question_1_friendliness',
        'question_2_waiting_times_feel',
        'question_4_cleanliness',
        'question_5_privacy'
    ]

    waiting_times = {
        'less_than_an_hour': round(
            (response_map['question_3_waiting_times_length']['less-than-an-hour'] / num_ratings * 100), 1),
        'between_1_and_3_hours': round((response_map['question_3_waiting_times_length']['between-1-and-3-hours'] / num_ratings * 100), 1),
        'more_than_4_hours': round((response_map['question_3_waiting_times_length']['more-than-4-hours'] / num_ratings * 100), 1),
        'all_day': round((response_map['question_3_waiting_times_length']['all-day'] / num_ratings * 100), 1)
    }

    for question in averages_questions:
        averages[question] = round((
            (response_map[question]['very-satisfied'] * 4) +
            (response_map[question]['satisfied'] * 3) +
            (response_map[question]['not-satisfied'] * 2) +<commit_msg>PEP8 The Last Thing - thanks @jerith<commit_after>from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required

from servicerating.models import Response

import math
import csv


def empty_response_map():
    response_map = {
        'question_1_friendliness':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            },
        'question_2_waiting_times_feel':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            },
        'question_3_waiting_times_length':
            {
                'less-than-an-hour': 0,
                'between-1-and-3-hours': 0,
                'more-than-4-hours': 0,
                'all-day': 0
            },
        'question_4_cleanliness':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            },
        'question_5_privacy':
            {
                'very-satisfied': 0,
                'satisfied': 0,
                'not-satisfied': 0,
                'very-unsatisfied': 0
            }
    }
    return response_map


@login_required
def dashboard(request):
    averages = {}

    all_responses = Response.objects.all()
    num_questions = 5.0
    total_responses = 0

    response_map = empty_response_map()

    for response in all_responses:
        total_responses += 1
        response_map[response.key][response.value] += 1

    num_ratings = math.ceil(total_responses / num_questions)

    averages_questions = [
        'question_1_friendliness',
        'question_2_waiting_times_feel',
        'question_4_cleanliness',
        'question_5_privacy'
    ]

    opt1 = response_map['question_3_waiting_times_length']['less-than-an-hour']
    opt2 = response_map['question_3_waiting_times_length'][
        'between-1-and-3-hours']
    opt3 = response_map['question_3_waiting_times_length']['more-than-4-hours']
    opt4 = response_map['question_3_waiting_times_length']['all-day']
    waiting_times = {
        'less_than_an_hour': round(
            (opt1 / num_ratings * 100), 1),
        'between_1_and_3_hours': round((opt2 / num_ratings * 100), 1),
        'more_than_4_hours': round((opt3 / num_ratings * 100), 1),
        'all_day': round((opt4 / num_ratings * 100), 1)
    }

    for question in averages_questions:
        averages[question] = round((
            (response_map[question]['very-satisfied'] * 4) +
            (response_map[question]['satisfied'] * 3) +
            (response_map[question]['not-satisfied'] * 2) +
{'fraction_non_alphanumeric': 0.11594202898550725, 'fraction_numerical': 0.025543478260869567, 'mean_word_length': 1.9382650345928685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5734705', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1630, 'n_words': 278}