<commit_before>"""
DB Benchmarking Application
===========================

Riak_db.py

This file handle all interactions with RiakDB during the benchmarking process.

"""

import riak

from load_settings import LocalSettings
from benchmark_template import BenchmarkDatabase

CONFIG = LocalSettings()


class Benchmark(BenchmarkDatabase):

    def __init__(self, setup=False, verbose=False):

        self.verbose = verbose

        if setup:
            self.setup('test')

    def setup(self, collection):
        """ `Setup()` handles all the necessary setup information for Riak.  It
        creates an instance of a Riak Client and defines the collection to use
        for reads and writes.

        :param collection:
        :return:
        """

        port = CONFIG.riak_port

        riak_servers = [
            CONFIG.riak_1,
            CONFIG.riak_2,
            CONFIG.riak_3,
        ]

        riak_nodes = []

        for server in riak_servers:

            riak_nodes.append({'host': str(server), 'http_port': port})

        self.client = riak.RiakClient(nodes=riak_nodes)

        self.bucket = self.client.bucket(collection)

    def write(self, data):

        entry = self.bucket.new('ID', data=data)

        entry.store()

    def read(self, index):

        read_entry = self.bucket.get('ID').data

        print read_entry<commit_msg>fixed a minor problem involving verbose output<commit_after>"""
DB Benchmarking Application
===========================

Riak_db.py

This file handle all interactions with RiakDB during the benchmarking process.

"""

import riak

from load_settings import LocalSettings
from benchmark_template import BenchmarkDatabase

CONFIG = LocalSettings()


class Benchmark(BenchmarkDatabase):

    def __init__(self, setup=False, verbose=False):

        self.verbose = verbose

        if setup:
            self.setup('test')

    def setup(self, collection):
        """ `Setup()` handles all the necessary setup information for Riak.  It
        creates an instance of a Riak Client and defines the collection to use
        for reads and writes.

        :param collection:
        :return:
        """

        port = CONFIG.riak_port

        riak_servers = [
            CONFIG.riak_1,
            CONFIG.riak_2,
            CONFIG.riak_3,
        ]

        riak_nodes = []

        for server in riak_servers:

            riak_nodes.append({'host': str(server), 'http_port': port})

        self.client = riak.RiakClient(nodes=riak_nodes)

        self.bucket = self.client.bucket(collection)

    def write(self, data):

        entry = self.bucket.new('ID', data=data)

        entry.store()

    def read(self, index):

        read_entry = self.bucket.get('ID').data

        if self.verbose:

            print read_entry
{'fraction_non_alphanumeric': 0.1066953097028285, 'fraction_numerical': 0.0021482277121374865, 'mean_word_length': 2.419828641370869, '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': '602059', 'n_tokens_mistral': 824, 'n_tokens_neox': 763, 'n_words': 217}