<commit_before>from household.models import FinancialYear, HouseholdClass, HouseholdService


def chart_data(audited, original, budgeted):
    """
    Get all the household bill totals for all avaliable years and join
    the data so that plotly can draw the graph.
    Eg: for 2015/16 we need all the total for all the income levels
    """
    data = {}
    household_class = HouseholdClass.objects.all().values("name")
    for h_class in household_class:
        data[h_class["name"]] = {"x": [], "y": []}

    for value in audited:
        data[value["household_class__name"]]["x"].append(
            value["financial_year__budget_year"]
        )
        data[value["household_class__name"]]["y"].append(str(value["total"]))

    for value in original:
        data[value["household_class__name"]]["x"].append(
            value["financial_year__budget_year"]
        )
        data[value["household_class__name"]]["y"].append(str(value["total"]))

    for value in budgeted:
        data[value["household_class__name"]]["x"].append(
            value["financial_year__budget_year"]
        )
        data[value["household_class__name"]]["y"].append(str(value["total"]))

    return data


def stack_chart(queryset):
    """
    function to format the household service totals data to present a stack chart
    """
    data = {}
    services = HouseholdService.objects.all().values("name")
    for s in services:
        data[s["name"]] = {"x": [], "y": []}
    for result in queryset:
        if result["total"]:
            data[result["service__name"]]["x"].append(
                result["financial_year__budget_year"]
            )
            data[result["service__name"]]["y"].append(str(result["total"]))
    return data<commit_msg>chart x axis must be sorted<commit_after>from household.models import FinancialYear, HouseholdClass, HouseholdService
from collections import OrderedDict
import json


def chart_data(audited, original, budgeted):
    """
    Get all the household bill totals for all avaliable years and join
    the data so that plotly can draw the graph.
    Eg: for 2015/16 we need all the total for all the income levels
    """
    data = {}
    household_class = HouseholdClass.objects.all().values("name")
    for h_class in household_class:
        data[h_class["name"]] = {"x": [], "y": []}

    for value in audited:
        data[value["household_class__name"]]["x"].append(
            value["financial_year__budget_year"]
        )
        data[value["household_class__name"]]["y"].append(str(value["total"]))

    for value in original:
        data[value["household_class__name"]]["x"].append(
            value["financial_year__budget_year"]
        )
        data[value["household_class__name"]]["y"].append(str(value["total"]))

    for value in budgeted:
        data[value["household_class__name"]]["x"].append(
            value["financial_year__budget_year"]
        )
        data[value["household_class__name"]]["y"].append(str(value["total"]))

    return data


def stack_chart(queryset):
    """
    function to format the household service totals data to present a stack chart
    """
    data = {}
    services = HouseholdService.objects.all().values("name")
    for s in services:
        data[s["name"]] = {"x": [], "y": []}
    for result in queryset:
        if result["total"]:
            data[result["service__name"]]["x"].append(
                result["financial_year__budget_year"]
            )
            data[result["service__name"]]["y"].append(str(result["total"]))
    data = OrderedDict(
        sorted(data.items(), key=lambda item: len(item[1]["x"]), reverse=True)
    )
    return json.dumps(data)
{'fraction_non_alphanumeric': 0.14258503401360545, 'fraction_numerical': 0.0035374149659863946, 'mean_word_length': 3.1725312145289446, 'pattern_counts': {'":': 8, '<': 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': '2439634', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1092, 'n_words': 243}