<commit_before>import time
from datetime import datetime

from django.http import HttpResponse, HttpResponseServerError
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.utils import simplejson
from django.core import serializers

from django.contrib.admin.views.decorators import staff_member_required

from couchdbkit import Server

from memopol2.main.models import Mep, Position
from memopol2 import settings
from memopol2.util import get_couch_doc_or_404

def index_names(request):
    couch = Server(settings.COUCHDB)

    map_fun = """
    function(d) {
        emit(null, {first: d.infos.name.first, last: d.infos.name.last, group: d.infos.group.abbreviation});
    }
    """

    couch_meps = couch["meps"]
    meps_list = couch_meps.temp_view({"map": map_fun})
    meps_list.fetch()
    meps_list = meps_list.all()

    return render_to_response('index.html', {'meps_list': meps_list}, context_instance=RequestContext(request))

def index_groups(request):
    couch = Server(settings.COUCHDB)

    map_fun = """
    function(d) {
        emit(d.infos.group.abbreviation, { name: d.infos.group.name,  count: 1 });
    }
    """<commit_msg>new object to manage interactions with the database<commit_after>import time
from datetime import datetime

from django.http import HttpResponse, HttpResponseServerError
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.utils import simplejson
from django.core import serializers

from django.contrib.admin.views.decorators import staff_member_required

from couchdbkit import Server

from memopol2.main.models import Mep, Position
from memopol2 import settings
from memopol2.util import get_couch_doc_or_404

class Database(object):
    def __init__(self):
        self.couch = Server(settings.COUCHDB)


def index_names(request):
    couch = Server(settings.COUCHDB)

    map_fun = """
    function(d) {
        emit(null, {first: d.infos.name.first, last: d.infos.name.last, group: d.infos.group.abbreviation});
    }
    """

    couch_meps = couch["meps"]
    meps_list = couch_meps.temp_view({"map": map_fun})
    meps_list.fetch()
    meps_list = meps_list.all()

    return render_to_response('index.html', {'meps_list': meps_list}, context_instance=RequestContext(request))

def index_groups(request):
    couch = Server(settings.COUCHDB)

    map_fun = """
    function(d) {
        emit(d.infos.group.abbreviation, { name: d.infos.group.name,  count: 1 });
    }
    """
{'fraction_non_alphanumeric': 0.10147744945567652, 'fraction_numerical': 0.007776049766718507, 'mean_word_length': 4.416842105263158, 'pattern_counts': {'":': 2, '<': 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': '4974044', 'n_tokens_mistral': 842, 'n_tokens_neox': 822, 'n_words': 185}