def get_overall_rating(date_from, date_to):
    feedback_records_list = []

    current_tz = timezone.get_current_timezone()
    date_from = current_tz.localize(
        datetime.strptime(date_from + " 00:00:00", constants.DATE_FORMAT))
    date_to = current_tz.localize(
        datetime.strptime(date_to + " 23:59:59", constants.DATE_FORMAT))

    rule = rrule.DAILY
    question = Question.objects.get(type=constants.TYPE_2)
    for single_date in rrule.rrule(rule, dtstart=date_from, until=date_to):
        feedback_options = FeedbackOption.manager.date(str(single_date.date()),
                                                       str(single_date.date()))
        feedback_options = feedback_options.question_parent_options(question)
        filtered_feedback = feedback_options.values(
            'option_id', 'option__text').annotate(count=Count('option_id'))
        list_feedback = generate_missing_options(question, filtered_feedback,
                                                 False)

        date_data = {
            'feedback_count': feedback_options.count(),
            'feedbacks': list_feedback
        }
        feedback_records_list.append({
            'date': single_date.strftime('%Y-%m-%d'),
            'data': date_data
        })

    if len(feedback_records_list) > constants.NO_OF_DAYS:
        feedback_records_list = feedback_records_list[-constants.NO_OF_DAYS:]

    return feedback_records_list
def get_opportunity_analysis(date_from, date_to):
    feedback_options = FeedbackOption.manager.question(constants.TYPE_3).date(
        date_from, date_to)
    feedback_options_dict = feedback_options.values('option_id', 'option__text', 'option__parent_id', 'option__score').\
            annotate(count=Count('option_id'))

    list_feedback = generate_missing_options(
        Question.objects.get(type=constants.TYPE_3), feedback_options_dict)
    return {
        'feedback_count': feedback_options.count(),
        'feedbacks': list_feedback
    }
def get_overall_feedback(date_from, date_to):
    feedback_options = FeedbackOption.manager.question(constants.TYPE_1).date(
        date_from, date_to)
    feedback_options_dict = feedback_options.values('option_id', 'option__text', 'option__score').\
        annotate(count=Count('option_id'))
    list_feedback = generate_missing_options(
        Question.objects.get(type=constants.TYPE_1), feedback_options_dict,
        False)

    return {
        'feedback_count':
        feedback_options.count(),
        'feedbacks':
        sorted(list_feedback, reverse=True, key=itemgetter('option__score'))
    }
Example #4
0
    def _get_recommendation_analysis(self, date_from, date_to, region_id,
                                     city_id, branch_id):
        feedback_options = FeedbackOption.manager.question(constants.TYPE_20).date(date_from, date_to).\
                filters(region_id, city_id, branch_id)
        feedback_options_dict = feedback_options.values('option_id', 'option__text', 'option__parent_id', 'option__score', 'option__color_code').\
            annotate(count=Count('option_id'))

        list_feedback = generate_missing_options(
            Question.objects.get(type=constants.TYPE_20),
            feedback_options_dict)

        return {
            'feedback_count': feedback_options.count(),
            'feedbacks': list_feedback
        }
Example #5
0
    def _get_overall_feedback(self, date_from, date_to, region_id, city_id,
                              branch_id):
        feedback_options = FeedbackOption.manager.question(
            constants.TYPE_1).date(date_from,
                                   date_to).filters(region_id, city_id,
                                                    branch_id)
        feedback_options_dict = feedback_options.values('option_id', 'option__text', 'option__parent_id', 'option__score', 'option__color_code').\
            annotate(count=Count('option_id'))
        list_feedback = generate_missing_options(
            Question.objects.get(type=constants.TYPE_1), feedback_options_dict)

        return {
            'feedback_count':
            feedback_options.count(),
            'feedbacks':
            sorted(list_feedback,
                   reverse=True,
                   key=itemgetter('option__score'))
        }
Example #6
0
    def get_qsc_count(date_from=None,
                      date_to=None,
                      region_id=None,
                      city_id=None,
                      branch_id=None):
        dict_list = FeedbackOption.manager.question(constants.TYPE_2).date(
            date_from, date_to).filters(region_id, city_id, branch_id).values(
                'option_id', 'option__text').annotate(count=Count("option_id"))

        qsc_list = []
        for dict in dict_list:
            option = Option.objects.get(pk=dict["option_id"])
            qsc_list.append({
                "count": dict["count"],
                "option__text": option.text,
                "option__id": option.id
            })

        qsc_list = generate_missing_options(
            Question.objects.get(type=constants.TYPE_2), dict_list, False)

        return qsc_list
Example #7
0
    def _get_patch_analysis(self, date_from, date_to, region_id, city_id,
                            branch_id):
        question_type = [constants.TYPE_1, constants.TYPE_2]
        region_objects = Region.objects.all()
        question_feedbacks = []

        for type in question_type:
            feedback_options = FeedbackOption.manager.question(type).date(
                date_from, date_to)
            feedbacks = []
            for object in region_objects:
                related_feedback_options = feedback_options.related_filters(
                    constants.REGIONAL_ANALYSIS, object)
                filtered_feedback_options = related_feedback_options.values(
                    'option_id', 'option__text', 'option__parent_id',
                    'option__score',
                    'option__color_code').annotate(count=Count('option_id'))
                list_feedback = generate_missing_options(
                    Question.objects.get(type=type), filtered_feedback_options)

                data = {
                    'feedback_count':
                    related_feedback_options.count(),
                    'feedbacks':
                    sorted(list_feedback,
                           reverse=True,
                           key=itemgetter('option__score'))
                }
                feedbacks.append({
                    'object': ObjectSerializer(object).data,
                    'data': data
                })
            question_feedbacks.append({'question_feedbacks': feedbacks})
        return {
            'count': region_objects.count(),
            'analysis': question_feedbacks
        }