<commit_before># coding=utf-8
from plugins.Plugin import Plugin
import os
import json
import sqlite3

DB_PATH = "market_data/loan_history.sqlite3"
HISTORY_DUMP = "www/history.json"

class Charts(Plugin):

    def on_bot_init(self):
        super(Charts, self).on_bot_init()

        # If there's no history database, can't use this
        if not os.path.isfile(DB_PATH):
          self.log.log_error("DB Doesn't Exist. 'AccountStats' plugin must be enabled.")
          return

        self.log.addSectionLog("plugins", "charts", { 'navbar': True })

        self.db = sqlite3.connect('market_data/loan_history.sqlite3')
        self.last_dump = 0
        self.dump_interval = int(self.config.get("CHARTS", "DumpInterval", 21600))


    def before_lending(self):
        return


    def after_lending(self):
        if self.get_db_version() > 0 and self.last_dump + self.dump_interval < sqlite3.time.time():
            self.dump_history()
            self.last_dump = sqlite3.time.time()


    def get_db_version(self):
        return self.db.execute("PRAGMA user_version").fetchone()[0]


    def dump_history(self):

        cursor = self.db.cursor()

        data = { }

        # Get distinct coins
        cursor.execute("SELECT DISTINCT currency FROM history ORDER BY currency DESC")
        for i in cursor:
            data[i[0]] = []

        # Loop over the coins and get data for each
        for coin in data:
            runningTotal = 0.0

            cursor.execute("SELECT strftime('%%s', strftime('%%Y-%%m-%%d 00:00:00', close)) ts, printf('%%.8f', SUM(interest)) i " \
                           "FROM history WHERE currency = '%s' GROUP BY ts ORDER BY ts" % (coin));
            for row in cursor:
                runningTotal += float(row[1])
                data[coin].append([ int(row[0]), float(row[1]), float(runningTotal) ])

        # Dump data to file<commit_msg>printf is only available in sqlite3>=3.8.3, this makes it work in earlier versions (#511)<commit_after># coding=utf-8
from plugins.Plugin import Plugin
import os
import json
import sqlite3

DB_PATH = "market_data/loan_history.sqlite3"
HISTORY_DUMP = "www/history.json"

class Charts(Plugin):

    def on_bot_init(self):
        super(Charts, self).on_bot_init()

        # If there's no history database, can't use this
        if not os.path.isfile(DB_PATH):
          self.log.log_error("DB Doesn't Exist. 'AccountStats' plugin must be enabled.")
          return

        self.log.addSectionLog("plugins", "charts", { 'navbar': True })

        self.db = sqlite3.connect('market_data/loan_history.sqlite3')
        self.last_dump = 0
        self.dump_interval = int(self.config.get("CHARTS", "DumpInterval", 21600))


    def before_lending(self):
        return


    def after_lending(self):
        if self.get_db_version() > 0 and self.last_dump + self.dump_interval < sqlite3.time.time():
            self.dump_history()
            self.last_dump = sqlite3.time.time()


    def get_db_version(self):
        return self.db.execute("PRAGMA user_version").fetchone()[0]


    def dump_history(self):

        cursor = self.db.cursor()

        data = { }

        # Get distinct coins
        cursor.execute("SELECT DISTINCT currency FROM history ORDER BY currency DESC")
        for i in cursor:
            data[i[0]] = []

        # Loop over the coins and get data for each
        for coin in data:
            runningTotal = 0.0

            cursor.execute("SELECT strftime('%%s', strftime('%%Y-%%m-%%d 00:00:00', close)) ts, round(SUM(interest), 8) i " \
                           "FROM history WHERE currency = '%s' GROUP BY ts ORDER BY ts" % (coin));
            for row in cursor:
                runningTotal += float(row[1])
                data[coin].append([ int(row[0]), float(row[1]), float(runningTotal) ])

        # Dump data to file
{'fraction_non_alphanumeric': 0.12321660181582361, 'fraction_numerical': 0.01634241245136187, 'mean_word_length': 2.43978590544157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6493032', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1151, 'n_words': 304}