<commit_before>#!/usr/bin/env python
import sys, operator, string, os, threading, re
from util import getch, cls, get_input
from time import sleep

lock = threading.Lock()

#
# The active view
#
class FreqObserver(threading.Thread):
    def __init__(self, freqs):
        threading.Thread.__init__(self)
        self.daemon = True
        self._end = False
        # freqs is the part of the model to be observed
        self._freqs = freqs
        self._freqs_0 = sorted(self._freqs.iteritems(), key=operator.itemgetter(1), reverse=True)
        self.start()

    def run(self):
        while not self._end:
            self._update_view()
            sleep(0.1)
        self._update_view()

    def stop(self):
        self._end = True

    def _update_view(self):
        lock.acquire()
        freqs_1 = sorted(self._freqs.iteritems(), key=operator.itemgetter(1), reverse=True)
        lock.release()
        if (freqs_1[0:25] != self._freqs_0[0:25]):
            self._update_display(freqs_1[0:25])
        self._freqs_0 = freqs_1

    def _update_display(self, tuples):
        def refresh_screen(data):
            # clear screen
            cls()
            print data
            sys.stdout.flush()

        data_str = ""
        for tf in tuples:
            data_str += str(tf[0]) + ' - ' + str(tf[1]) + '\n'
        refresh_screen(data_str)

#<commit_msg>Minor<commit_after>#!/usr/bin/env python
import sys, operator, string, os, threading, re
from util import getch, cls, get_input
from time import sleep

lock = threading.Lock()

#
# The active view
#
class FreqObserver(threading.Thread):
    def __init__(self, freqs):
        threading.Thread.__init__(self)
        self.daemon = True
        self._end = False
        # freqs is the part of the model to be observed
        self._freqs = freqs
        self._freqs_0 = sorted(self._freqs.iteritems(), key=operator.itemgetter(1), reverse=True)
        self.start()

    def run(self):
        while not self._end:
            self._update_view()
            sleep(0.1)

    def stop(self):
        self._end = True

    def _update_view(self):
        lock.acquire()
        freqs_1 = sorted(self._freqs.iteritems(), key=operator.itemgetter(1), reverse=True)
        lock.release()
        if (freqs_1[0:25] != self._freqs_0[0:25]):
            self._update_display(freqs_1[0:25])
        self._freqs_0 = freqs_1

    def _update_display(self, tuples):
        def refresh_screen(data):
            # clear screen
            cls()
            print data
            sys.stdout.flush()

        data_str = ""
        for (w, c) in tuples:
            data_str += str(w) + ' - ' + str(c) + '\n'
        refresh_screen(data_str)

#
{'fraction_non_alphanumeric': 0.11795252225519288, 'fraction_numerical': 0.015578635014836795, 'mean_word_length': 2.172941176470588, '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': '4077982', 'n_tokens_mistral': 896, 'n_tokens_neox': 867, 'n_words': 196}