<commit_before>import datetime
import time
import yaml
import json

from flask import current_app, session
from sqlalchemy.exc import SQLAlchemyError
from cryptokit.rpc import CoinRPCException
from decimal import Decimal as dec, Decimal

from .exceptions import CommandException, InvalidAddressException
from . import db, cache, root, redis_conn, currencies, powerpools, algos, chains
from .models import (ShareSlice, Block, Credit, UserSettings, make_upper_lower,
                     Payout)


class ShareTracker(object):
    def __init__(self, algo):
        self.types = {typ: ShareTypeTracker(typ) for typ in ShareSlice.SHARE_TYPES}
        self._algo = algo
        self.lowest = None
        self.highest = None

    @property
    def algo(self):
        return algos[self._algo]

    def count_slice(self, slc):
        self.types[slc.share_type].shares += slc.value
        if not self.lowest or slc.time < self.lowest:
            self.lowest = slc.time
        if not self.highest or slc.end_time > self.highest:
            self.highest = slc.end_time

    @property
    def accepted(self):
        return self.types["acc"].shares

    @property
    def total(self):
        return sum([self.types['dup'].shares, self.types['low'].shares, self.types['stale'].shares, self.types['acc'].shares])

    def hashrate(self, typ="acc"):
        if self.lowest:
            return self.types[typ].shares * self.algo.hashes_per_share / (self.highest - self.lowest).total_seconds()
        else:
            return 0

    @property
    def rejected(self):
        return sum([self.types['dup'].shares, self.types['low'].shares, self.types['stale'].shares])

    @property
    def stale_efficiency(self):
        rej = float(self.types['stale'].shares)
        acc = float(self.types['acc'].shares)
        if rej:
            return 100.0 * (acc / (rej + acc))
        return 100.0

    @property
    def dup_efficiency(self):
        rej = float(self.types['dup'].shares)
        acc = float(self.types['acc'].shares)
        if rej:
            return 100.0 * (acc / (rej + acc))
        return 100.0

    @property
    def low_efficiency(self):
        rej = float(self.types['low'].shares)
        acc = float(self.types['acc'].shares)
        if rej:<commit_msg>Only make stale shares part of efficiency<commit_after>import datetime
import time
import yaml
import json

from flask import current_app, session
from sqlalchemy.exc import SQLAlchemyError
from cryptokit.rpc import CoinRPCException
from decimal import Decimal as dec, Decimal

from .exceptions import CommandException, InvalidAddressException
from . import db, cache, root, redis_conn, currencies, powerpools, algos, chains
from .models import (ShareSlice, Block, Credit, UserSettings, make_upper_lower,
                     Payout)


class ShareTracker(object):
    def __init__(self, algo):
        self.types = {typ: ShareTypeTracker(typ) for typ in ShareSlice.SHARE_TYPES}
        self._algo = algo
        self.lowest = None
        self.highest = None

    @property
    def algo(self):
        return algos[self._algo]

    def count_slice(self, slc):
        self.types[slc.share_type].shares += slc.value
        if not self.lowest or slc.time < self.lowest:
            self.lowest = slc.time
        if not self.highest or slc.end_time > self.highest:
            self.highest = slc.end_time

    @property
    def accepted(self):
        return self.types["acc"].shares

    @property
    def total(self):
        return sum([self.types['dup'].shares, self.types['low'].shares, self.types['stale'].shares, self.types['acc'].shares])

    def hashrate(self, typ="acc"):
        if self.lowest:
            return self.types[typ].shares * self.algo.hashes_per_share / (self.highest - self.lowest).total_seconds()
        else:
            return 0

    @property
    def rejected(self):
        #return sum([self.types['dup'].shares, self.types['low'].shares, self.types['stale'].shares])
        return self.types['stale'].shares

    @property
    def stale_efficiency(self):
        rej = float(self.types['stale'].shares)
        acc = float(self.types['acc'].shares)
        if rej:
            return 100.0 * (acc / (rej + acc))
        return 100.0

    @property
    def dup_efficiency(self):
        rej = float(self.types['dup'].shares)
        acc = float(self.types['acc'].shares)
        if rej:
            return 100.0 * (acc / (rej + acc))
        return 100.0

    @property
    def low_efficiency(self):
        rej = float(self.types['low'].shares)
        acc = float(self.types['acc'].shares)
        if rej:
{'fraction_non_alphanumeric': 0.11737904100672597, 'fraction_numerical': 0.007376871338685182, 'mean_word_length': 2.610023492560689, 'pattern_counts': {'":': 0, '<': 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': '2838956', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1405, 'n_words': 347}