<commit_before>
import os
import Queue
import RPi.GPIO as GPIO
import settings
import time
import threading
import traceback
import sys


BASE_PATH = os.path.dirname(os.path.realpath(__file__))
UPPER_PATH = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
DEVICES_PATH = "%s/Hosts/" % (BASE_PATH )
THIRTYBIRDS_PATH = "%s/thirtybirds_2_0" % (UPPER_PATH )

#sys.path.append(BASE_PATH)
#sys.path.append(UPPER_PATH)

from thirtybirds_2_0.Network.manager import init as network_init

class Network(object):
    def __init__(self, hostname, network_message_handler, network_status_handler):
        self.hostname = hostname
        self.thirtybirds = network_init(
            hostname=self.hostname,
            role="server",
            discovery_multicastGroup=settings.discovery_multicastGroup,
            discovery_multicastPort=settings.discovery_multicastPort,
            discovery_responsePort=settings.discovery_responsePort,
            pubsub_pubPort=settings.pubsub_pubPort,
            message_callback=network_message_handler,
            status_callback=network_status_handler
        )

class Thirtybirds_Client_Monitor_Server(threading.Thread):
    def __init__(self, network, hostnames, update_period=30):
        threading.Thread.__init__(self)
        self.update_period = update_period
        self.current_clients = {}
        self.remembered_clients = {}
        self.network = network
        self.hostnames = hostnames
        self.queue = Queue.Queue()
        self.hosts = {}

    def empty_host_list(self):
        self.hosts = {}
        for hostname in self.hostnames:
            self.hosts[hostname] = {
                "present":False,
                "timestamp":False,
                "pickle_version":False,
                "temp":False,
                "git_pull_date":False
            }

    def add_to_queue(self, hostname, git_pull_date, temp, pickle_version):
        print  "add_to_queue", hostname, git_pull_date, temp, pickle_version
        self.queue.put((hostname, git_pull_date, pickle_version, temp, time.time()))

    def print_current_clients(self):
        print ""
        print "CURRENT CLIENTS:"
        for hostname in self.hostnames:
            print hostname, repr( self.hosts[hostname])
            #print "%s: %s : %s: %s: %s" % (hostname, self.hosts[hostname]["present"], self.hosts[hostname]["temp"], self.hosts[hostname]["timestamp"], self.hosts[hostname]["pickle_version"], self.hosts[hostname]["git_pull_date"])

    def run(self):
        previous_hosts = {}
        while True:
            self.empty_host_list()
            self.network.thirtybirds.send("client_monitor_request", "")
            time.sleep(self.update_period)
            while not self.queue.empty():
                [hostname, git_pull_date, pickle_version, temp, timestamp] = self.queue.get(True)
                print ">>", hostname, temp, git_pull_date, pickle_version, timestamp
                self.hosts[hostname]["present"] = True
                self.hosts[hostname]["timestamp"] = timestamp
                self.hosts[hostname]["pickle_version"] = pickle_version
                self.hosts[hostname]["temp"] = temp
                self.hosts[hostname]["git_pull_date"] = git_pull_date
            #if not cmp(previous_hosts,self.hosts):
            #    self.print_current_clients()
            #previous_hosts = self.hosts
            self.print_current_clients()





class Pedal(object):
    def __init__(self, pin_number):
            self.pin_number = pin_number
            GPIO.setup(pin_number, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
            self.last_value = 0
    def detect_change(self):
            current_value = GPIO.input(self.pin_number)
            if current_value == self.last_value:
                return None
            else:
                self.last_value = current_value
                return current_value

class Pedals(threading.Thread):
    def __init__(self, outgoing_msg_queue):
        threading.Thread.__init__(self)
        self.outgoing_msg_queue = outgoing_msg_queue
        self.pedals = []
        pins =  [26,  19, 13, 21, 20, 16]
        GPIO.setmode(GPIO.BCM)
        for pin in pins:<commit_msg>adding temp to client monitor<commit_after>
import os
import Queue
import RPi.GPIO as GPIO
import settings
import time
import threading
import traceback
import sys


BASE_PATH = os.path.dirname(os.path.realpath(__file__))
UPPER_PATH = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
DEVICES_PATH = "%s/Hosts/" % (BASE_PATH )
THIRTYBIRDS_PATH = "%s/thirtybirds_2_0" % (UPPER_PATH )

#sys.path.append(BASE_PATH)
#sys.path.append(UPPER_PATH)

from thirtybirds_2_0.Network.manager import init as network_init

class Network(object):
    def __init__(self, hostname, network_message_handler, network_status_handler):
        self.hostname = hostname
        self.thirtybirds = network_init(
            hostname=self.hostname,
            role="server",
            discovery_multicastGroup=settings.discovery_multicastGroup,
            discovery_multicastPort=settings.discovery_multicastPort,
            discovery_responsePort=settings.discovery_responsePort,
            pubsub_pubPort=settings.pubsub_pubPort,
            message_callback=network_message_handler,
            status_callback=network_status_handler
        )

class Thirtybirds_Client_Monitor_Server(threading.Thread):
    def __init__(self, network, hostnames, update_period=30):
        threading.Thread.__init__(self)
        self.update_period = update_period
        self.current_clients = {}
        self.remembered_clients = {}
        self.network = network
        self.hostnames = hostnames
        self.queue = Queue.Queue()
        self.hosts = {}

    def empty_host_list(self):
        self.hosts = {}
        for hostname in self.hostnames:
            self.hosts[hostname] = {
                "present":False,
                "timestamp":False,
                "pickle_version":False,
                "temp":False,
                "git_pull_date":False
            }

    def add_to_queue(self, hostname, git_pull_date, temp, pickle_version):
        print  "add_to_queue", hostname, git_pull_date, temp, pickle_version
        self.queue.put((hostname, git_pull_date, pickle_version, temp, time.time()))

    def print_current_clients(self):
        print ""
        print "CURRENT CLIENTS:"
        for hostname in self.hostnames:
            print hostname, repr( self.hosts[hostname])
            #print "%s: %s : %s: %s: %s" % (hostname, self.hosts[hostname]["present"], self.hosts[hostname]["temp"], self.hosts[hostname]["timestamp"], self.hosts[hostname]["pickle_version"], self.hosts[hostname]["git_pull_date"])

    def run(self):
        previous_hosts = {}
        while True:
            self.empty_host_list()
            self.network.thirtybirds.send("client_monitor_request", "")
            time.sleep(self.update_period)
            while not self.queue.empty():
                [hostname, git_pull_date, pickle_version, temp, timestamp] = self.queue.get(True)
                print ">>", hostname, git_pull_date, pickle_version, temp, timestamp
                self.hosts[hostname]["present"] = True
                self.hosts[hostname]["timestamp"] = timestamp
                self.hosts[hostname]["pickle_version"] = pickle_version
                self.hosts[hostname]["temp"] = temp
                self.hosts[hostname]["git_pull_date"] = git_pull_date
                print "self.hosts[hostname]=", repr(self.hosts[hostname])
            #if not cmp(previous_hosts,self.hosts):
            #    self.print_current_clients()
            #previous_hosts = self.hosts
            self.print_current_clients()


class Pedal(object):
    def __init__(self, pin_number):
            self.pin_number = pin_number
            GPIO.setup(pin_number, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
            self.last_value = 0
    def detect_change(self):
            current_value = GPIO.input(self.pin_number)
            if current_value == self.last_value:
                return None
            else:
                self.last_value = current_value
                return current_value

class Pedals(threading.Thread):
    def __init__(self, outgoing_msg_queue):
        threading.Thread.__init__(self)
        self.outgoing_msg_queue = outgoing_msg_queue
        self.pedals = []
        pins =  [26,  19, 13, 21, 20, 16]
        GPIO.setmode(GPIO.BCM)
        for pin in pins:
{'fraction_non_alphanumeric': 0.10347672362993518, 'fraction_numerical': 0.004714201532115498, 'mean_word_length': 2.5881606765327696, 'pattern_counts': {'":': 10, '<': 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': '94222', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2508, 'n_words': 442}