<commit_before>import csv

from django.shortcuts import render
from django.http import HttpResponse

from . import services

def index(request):
    data = services.overview()
    return render(request, 'index.html', data)

def meter_runs(request):
    """Render the table of exported MeterRun results in html"""
    data = services.meterruns_export()
    return render(request, 'project_run_table.html', data)

def csv_export(request):
    """Return a dump of all the MeterRuns in CSV form"""
    response = HttpResponse(content_type="text/csv")
    response["Content-Disposition"] = 'attachment; filename="meter_runs.csv"'

    writer = csv.writer(response)
    writer.writerow(['First row', 'Foo', 'Bar'])

    return response<commit_msg>Use the meterrun_export service to power csv export<commit_after>import csv

from django.shortcuts import render
from django.http import HttpResponse

from . import services

def index(request):
    data = services.overview()
    return render(request, 'index.html', data)

def meter_runs(request):
    """Render the table of exported MeterRun results in html"""
    data = services.meterruns_export()
    return render(request, 'project_run_table.html', data)

def csv_export(request):
    """Return a dump of all the MeterRuns in CSV form"""
    response = HttpResponse(content_type="text/csv")
    response["Content-Disposition"] = 'attachment; filename="meter_runs.csv"'

    data = services.meterruns_export()

    writer = csv.DictWriter(response, fieldnames=data['headers'])
    writer.writeheader()
    for meter_run in data['meter_runs']:
        writer.writerow(meter_run)

    return response
{'fraction_non_alphanumeric': 0.10948905109489052, 'fraction_numerical': 0.0, 'mean_word_length': 4.576271186440678, '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': '7412406', 'n_tokens_mistral': 492, 'n_tokens_neox': 468, 'n_words': 137}