<commit_before>from pymongo import MongoClient
from pymongo.errors import ConnectionFailure
from bson.objectid import ObjectId
from datetime import datetime

import events
import config
from config import Bunch

class Mongo():

    __started = False

    def __init__(self):
        if Mongo.__started:
            return

        try:
            self.connection = MongoClient(host=config.mongo.host, port=config.mongo.port)
            self.db = self.connection.tally
            self.tallies = self.db.tallies
            self.tally_events = self.db.tally_events
        except ConnectionFailure:
            self.connection = Bunch(alive=lambda: False)

        events.on_new_tally(self.insert_tally)
        events.on_value_changed_all(self.update_value)

        Mongo.__started = True

    def insert_tally(self, tally=None):
        if self.connection.alive():
            # add the tally to the tally collection
            s = tally._serialise()
            s['_id'] = s['key']<commit_msg>Mongo is a thoroughly modern python object. Oh yes.<commit_after>from pymongo import MongoClient
from pymongo.errors import ConnectionFailure
from bson.objectid import ObjectId
from datetime import datetime

import events
import config
from config import Bunch

class Mongo(object):

    __started = False

    def __init__(self):
        if Mongo.__started:
            return

        try:
            self.connection = MongoClient(host=config.mongo.host, port=config.mongo.port)
            self.db = self.connection.tally
            self.tallies = self.db.tallies
            self.tally_events = self.db.tally_events
        except ConnectionFailure:
            self.connection = Bunch(alive=lambda: False)

        events.on_new_tally(self.insert_tally)
        events.on_value_changed_all(self.update_value)

        Mongo.__started = True

    def insert_tally(self, tally=None):
        if self.connection.alive():
            # add the tally to the tally collection
            s = tally._serialise()
            s['_id'] = s['key']
{'fraction_non_alphanumeric': 0.07835455435847209, 'fraction_numerical': 0.0, 'mean_word_length': 2.4923076923076923, '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': '6909459', 'n_tokens_mistral': 603, 'n_tokens_neox': 568, 'n_words': 143}