from django.shortcuts import render
from git_admin.models import CommittedFile


def index(request):
    commit_list = list(CommittedFile.objects.all().order_by('-size')[:10])
    xdata = []
    ydata = []
    for commit in commit_list:
        xdata.append(commit.filename.split("/")[-1])
        ydata.append(commit.size)
        chartdata = {'x': xdata, 'y': ydata}
        charttype = "pieChart"
        data = {'charttype': charttype, 'chartdata': chartdata
        }
    return render(request, 'git_admin/index.html', data)

