<commit_before>import pymongo
from base import BaseStorage
import datetime
from bson.objectid import ObjectId


class Mongo(BaseStorage):
    """docstring for Mongo"""

    def __init__(self):
        super(Mongo, self).__init__(),
        self.host = "localhost"
        self.database_name = "profiler"
        self.collection_name = 'instances'
        self.config = config

        if hasattr(self.config, "MONGO_HOST"):
            self.host = self.config.MONGO_HOST
        if hasattr(self.config, "DATABASE"):
            self.database_name = self.config.DATABASE
        if hasattr(self.config, "COLLECTION"):
            self.collection_name = self.config.COLLECTION

        self.client = pymongo.MongoClient(self.host)
        self.db = self.client[self.database_name]
        self.collection = self.db[self.collection_name]

    def filter(self, kwargs):
        query = {}

        endedAt = kwargs.get('endedAt', None)
        startedAt = kwargs.get('startedAt', None)
        elapsed = kwargs.get('elapsed', None)
        name = kwargs.get('name', None)
        method = kwargs.get('method', None)
        url = kwargs.get('url', None)

        if name:
            query['name'] = name
        if method:
            query['method'] = method
        if url:
            query['url'] = url
        if endedAt:
            query['endedAt'] = { "$lte": endedAt }
        if startedAt:
            query['startedAt'] = { "$gt": startedAt }
        if elapsed:
            query['elapsed'] = { "$gte": elapsed }

        if limit:
            cursor = self.collection.find(
                query
                ).sort(sort_key, sort_dir).skip(skip)
        else:
            cursor = self.collection.find(
                query
                ).sort(sort_key, sort_dir).skip(skip).limit(limit)
        return self.clearify(cursor)

    def insert(self, recordDictionary):
        result = self.collection.insert(recordDictionary)
        if result["n"] > 0:
            return True
        return False

    def delete(self, criteria):
        result = self.collection.remove(criteria)
        if result["n"] > 0:
            return True
        return False

    def getSummary(self,  kwargs):
        match_condition = {}
        endDate = kwargs.get('endedAt', None)
        startedAt = kwargs.get('startedAt', None)<commit_msg>adds to measurementId argument for delete measurement.<commit_after>import pymongo
from base import BaseStorage
import datetime
from bson.objectid import ObjectId


class Mongo(BaseStorage):
    """docstring for Mongo"""

    def __init__(self, config):
        super(Mongo, self).__init__(),
        self.host = "localhost"
        self.database_name = "profiler"
        self.collection_name = 'instances'
        self.config = config

        if hasattr(self.config, "MONGO_HOST"):
            self.host = self.config.MONGO_HOST
        if hasattr(self.config, "DATABASE"):
            self.database_name = self.config.DATABASE
        if hasattr(self.config, "COLLECTION"):
            self.collection_name = self.config.COLLECTION

        self.client = pymongo.MongoClient(self.host)
        self.db = self.client[self.database_name]
        self.collection = self.db[self.collection_name]

    def filter(self, kwargs):
        query = {}

        endedAt = kwargs.get('endedAt', None)
        startedAt = kwargs.get('startedAt', None)
        elapsed = kwargs.get('elapsed', None)
        name = kwargs.get('name', None)
        method = kwargs.get('method', None)
        url = kwargs.get('url', None)

        if name:
            query['name'] = name
        if method:
            query['method'] = method
        if url:
            query['url'] = url
        if endedAt:
            query['endedAt'] = { "$lte": endedAt }
        if startedAt:
            query['startedAt'] = { "$gt": startedAt }
        if elapsed:
            query['elapsed'] = { "$gte": elapsed }

        if limit:
            cursor = self.collection.find(
                query
                ).sort(sort_key, sort_dir).skip(skip)
        else:
            cursor = self.collection.find(
                query
                ).sort(sort_key, sort_dir).skip(skip).limit(limit)
        return self.clearify(cursor)

    def insert(self, recordDictionary):
        result = self.collection.insert(recordDictionary)
        if result["n"] > 0:
            return True
        return False

    def delete(self, measurementId):
        result = self.collection.remove({"_id": ObjectId(measurementId)})
        if result["n"] > 0:
            return True
        return False

    def getSummary(self,  kwargs):
        match_condition = {}
        endDate = kwargs.get('endedAt', None)
        startedAt = kwargs.get('startedAt', None)
{'fraction_non_alphanumeric': 0.11691855583543241, 'fraction_numerical': 0.0008396305625524769, 'mean_word_length': 2.03117048346056, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 7, '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': '1186574', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1347, 'n_words': 303}