<commit_before># Copyright (c) 2016, <NAME>
# Licensed under MIT

""" general DB handling in Kervi, store sensor values  """
import os
import time
from datetime import datetime
import json
import inspect
import sqlite3 as lite
import kervi.spine as spine
from kervi.utility.thread import KerviThread
0
SPINE = spine.Spine()
FILE_CON = None
MEMORY_CON = None

def create_file_con():
    return lite.connect('kervi.db', check_same_thread=False)

def create_memory_con():
    #return lite.connect("kervi_mem.db", check_same_thread=False)
    return lite.connect(":memory:", check_same_thread=False)


class MemoryCleanThread(KerviThread):
    def __init__(self):
        KerviThread.__init__(self)
        self.spine = spine.Spine()
        self.alive = False
        if self.spine:
            self.spine.register_command_handler("startThreads", self._start_command)
            self.spine.register_command_handler("stopThreads", self._stop_command)

    def _step(self):
        time.sleep(20)
        try:
            con = create_memory_con()
            cursor = con.cursor()
            cursor.execute("DELETE FROM dynamicData WHERE id IN (SELECT id FROM dynamicData ORDER BY id ASC LIMIT 1000);")
        except lite.Error as msg:
            SPINE.log.error("clean memory db, Command skipped: {0}, command{1}", msg)

    def _start_command(self):
        print("start storage service")
        if not self.alive:<commit_msg>switch to memory database for temp data<commit_after># Copyright (c) 2016, <NAME>
# Licensed under MIT

""" general DB handling in Kervi, store sensor values  """
import os
import time
from datetime import datetime
import json
import inspect
import sqlite3 as lite
import kervi.spine as spine
from kervi.utility.thread import KerviThread

SPINE = spine.Spine()
FILE_CON = None
MEMORY_CON = None

def create_file_con():
    return lite.connect('kervi.db', check_same_thread=False)

def create_memory_con():
    #return lite.connect("kervi_mem.db", check_same_thread=False)
    return lite.connect(":memory:", check_same_thread=False)


class MemoryCleanThread(KerviThread):
    def __init__(self):
        KerviThread.__init__(self)
        self.spine = spine.Spine()
        self.alive = False
        if self.spine:
            self.spine.register_command_handler("startThreads", self._start_command)
            self.spine.register_command_handler("stopThreads", self._stop_command)

    def _step(self):
        time.sleep(20)
        try:
            con = MEMORY_CON # create_memory_con()
            cursor = con.cursor()
            cursor.execute("DELETE FROM dynamicData WHERE id IN (SELECT id FROM dynamicData ORDER BY id ASC LIMIT 1000);")
        except lite.Error as msg:
            SPINE.log.error("clean memory db, Command skipped: {0}, command{1}", msg)

    def _start_command(self):
        print("start storage service")
        if not self.alive:
{'fraction_non_alphanumeric': 0.09633977900552486, 'fraction_numerical': 0.009323204419889503, 'mean_word_length': 3.317436661698957, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '7115768', 'n_tokens_mistral': 900, 'n_tokens_neox': 868, 'n_words': 243}