from hashlib import md5

from django.db.models import Count, Sum
from django.http import JsonResponse
from django.shortcuts import render
from django.utils.translation import ugettext as _

from judge.models import Language


def language_data(request):
    language_count = Language.objects.annotate(count=Count('submission'))
    languages = language_count.filter(count__gte=1000).values('key', 'name', 'short_name', 'count').order_by('-count')
    data = []
    for language in languages:
        hash = md5(language['key']).hexdigest()[:6]
        r, g, b = int(hash[:2], 16), int(hash[2:4], 16), int(hash[4:6], 16),
        data.append({
            'value': language['count'], 'label': language['name'],
            'color': '#%02X%02X%02X' % (r, g, b),
            'highlight': '#%02X%02X%02X' % (min(int(r * 1.2), 255),
                                            min(int(g * 1.2), 255),
                                            min(int(b * 1.2), 255))
        })
    data.append({
        'value': language_count.filter(count__lt=1000).aggregate(total=Sum('count'))['total'],
        'label': 'Other', 'color': '#FDB45C', 'highlight': '#FFC870',
    })
    return JsonResponse(data, safe=False)


def language(request):
    return render(request, 'stats/language.jade', {
        'title': _('Language statistics'), 'tab': 'language'
    })

@@ -2,26 +2,38 @@
 rom 
-hashlib import md5
+itertools import repeat, chain
 %0A%0Afr
@@ -234,746 +234,1247 @@
 ge%0A%0A
-%0Adef language_data(request):%0A    language_count = Language.objects.annotate(count=Count('submission'))%0A    languages = language_count.filter(count__gte=1000).values('key', 'name', 'short_name', 'count').order_by('-count')%0A    data = %5B%5D%0A    for language in languages:%0A        hash = md5(language%5B'key'%5D).hexdigest()%5B:6%5D%0A        r, g, b = int(hash%5B:2%5D, 16), int(hash%5B2:4%5D, 16), int(hash%5B4:6%5D, 16),%0A        data.append(%7B%0A            'value': language%5B'count'%5D, 'label': language%5B'name'%5D,%0A            'color': '#%2502X%2502X%2502X' %25 (r, g, b),%0A            'highlight': '#%2502X%2502X%2502X' %25 (min(int(r * 1.2), 255),%0A                                            min(int(g * 1.2), 255),%0A                                            min(int(b * 1.2), 255))
+chart_colors = %5B0x3366CC, 0xDC3912, 0xFF9900, 0x109618, 0x990099, 0x3B3EAC, 0x0099C6, 0xDD4477, 0x66AA00, 0xB82E2E,%0A                0x316395, 0x994499, 0x22AA99, 0xAAAA11, 0x6633CC, 0xE67300, 0x8B0707, 0x329262, 0x5574A6, 0x3B3EAC%5D%0Ahighlight_colors = %5B%5D%0A%0A%0Adef _highlight_colors():%0A    for color in chart_colors:%0A        r, g, b = color %3E%3E 16, (color %3E%3E 8) & 0xFF, color & 0xFF%0A        highlight_colors.append('#%2502X%2502X%2502X' %25 (min(int(r * 1.2), 255),%0A                                                   min(int(g * 1.2), 255),%0A                                                   min(int(b * 1.2), 255)))%0A%0A_highlight_colors()%0Adel _highlight_colors%0A%0Achart_colors = map('#%2506X'.__mod__, chart_colors)%0A%0A%0Adef repeat_chain(iterable):%0A    return chain.from_iterable(repeat(iterable))%0A%0A%0Adef language_data(request):%0A    language_count = Language.objects.annotate(count=Count('submission'))%0A    languages = language_count.filter(count__gte=1000).values('key', 'name', 'short_name', 'count').order_by('-count')%0A    data = %5B%5D%0A    for language, color, highlight in zip(languages, chart_colors, highlight_colors):%0A        data.append(%7B%0A            'value': language%5B'count'%5D, 'label': language%5B'name'%5D,%0A            'color': color, 'highlight': highlight,
 %0A   

Use google chart colours instead of md5 #237