Ejemplo n.º 1
0
def msp430():
    """
    MSP430 sensors (e.g., external temperature)
    """
    prefix = "msp430"
    while True:
        try:
            ser = serial.Serial(port='/dev/ttyACM0', baudrate=9600)
            db = sqlite.open(LOG_PATH_FORMAT % prefix)
            try:
                while True:
                    ser.write("1")
                    line = ser.readline().strip()
                    for sensor in line.split(';'):
                        name, value = sensor.split('\t')

                    db[int(time())] = \
                      [tuple(sensor.split('\t')) for sensor in line.split(';')]

                    sleep(2)
            finally:
                ser.close()
        except serial.SerialException, e:
            print e.message
        sleep(2)
Ejemplo n.º 2
0
 def __enter__(self):
     if not self.local:
         # Create a new thread for each time this memoizing agent is
         # entered. This allows a CWMemo to be reused.
         self.client = cw.client.ClientThread(self.completion, self.host)
         self.completion_thread_db = None
         self.completion_cond = self.client.jobs_cond
         self.client.start()
     self.db = sshelve.open(self.dbname)
     return self
Ejemplo n.º 3
0
 def __enter__(self):
     if not self.local:
         # Create a new thread for each time this memoizing agent is
         # entered. This allows a CWMemo to be reused.
         self.client = cw.client.ClientThread(self.completion, self.host)
         self.completion_thread_db = None
         self.completion_cond = self.client.jobs_cond
         self.client.start()
     self.db = sshelve.open(self.dbname)
     return self
Ejemplo n.º 4
0
def all_sensors():
    sensors = []
    for sensor in os.listdir(LOG_PATH):
        if not fnmatch.fnmatch(sensor, 'sensor_*'):
            continue
        file_name = os.path.join(LOG_PATH, sensor)

        if os.path.exists(file_name):
            data = sqlite.open(file_name).getlast()[0][1]
            sensors.append({"name": sensor[len("sensor_"):], "data": data})

    return render_template("all_sensors.html", data=sensors, info=get_info())
Ejemplo n.º 5
0
def index():
    sensors = {}
    if os.path.exists(LOG_PATH):
        for sensor in os.listdir(LOG_PATH):
            if not fnmatch.fnmatch(sensor, 'sensor_*'):
                continue
            file_name = os.path.join(LOG_PATH, sensor)
            if os.path.exists(file_name):
                data = sqlite.open(file_name).getlast()[0][1]
                sensors.update({sensor[len("sensor_"):]: dict(data)})

    return render_template("index.html", data=sensors, info=get_info())
Ejemplo n.º 6
0
    def completion(self, jobid, output):
        """Callback invoked when a cluster-workers job finishes. We
        store the result for a later get() call and wake up any pending
        get()s.
        """
        self.logger.info(
            u'job completed ({} pending)'.format(len(self.jobs) - 1))

        # Called in a different thread, so we need a separate SQLite
        # connection.
        if not self.completion_thread_db:
            self.completion_thread_db = sshelve.open(self.dbname)
        db = self.completion_thread_db

        # Get the arguments and save them with the result.
        with self.client.jobs_cond:
            key = self.jobs.pop(jobid)
        db[key] = output
Ejemplo n.º 7
0
    def completion(self, jobid, output):
        """Callback invoked when a cluster-workers job finishes. We
        store the result for a later get() call and wake up any pending
        get()s.
        """
        self.logger.info(u'job completed ({} pending)'.format(
            len(self.jobs) - 1
        ))

        # Called in a different thread, so we need a separate SQLite
        # connection.
        if not self.completion_thread_db:
            self.completion_thread_db = sshelve.open(self.dbname)
        db = self.completion_thread_db

        # Get the arguments and save them with the result.
        with self.client.jobs_cond:
            key = self.jobs.pop(jobid)
        db[key] = output
Ejemplo n.º 8
0
def acpi():
    """
    ACPI sensors (e.g., computer internal temperature)
    """
    sensors.init()
    print "ACPI Sensors found: %s" % list(sensors.iter_detected_chips())

    db = dict((sensor.prefix, sqlite.open(LOG_PATH_FORMAT % sensor.prefix)) for sensor 
                                in sensors.iter_detected_chips() )

    try:
        while True:
            for sensor in sensors.iter_detected_chips():
                #MONGO?
                for feature in sensor:
                    print "%s: %s=%s" % (sensor.prefix, feature.name, feature.get_value())

                db[sensor.prefix][int(time())] = \
                    [(feature.name, feature.get_value()) for feature in sensor]

            sleep(2)
    finally:
        sensors.cleanup()
Ejemplo n.º 9
0
def chart(device, sensor):
    file_name = os.path.join(LOG_PATH, device)
    if os.path.exists(file_name):
        N = 3*60*60//2
        C = 10
        d = sqlite.open(file_name).getlast(N)
        d += [(d[-1][0], [(x[0], x[1]) for x in d[-1][1]]) for x in xrange(N-len(d))]
        # print d
        data = [[(d[0][1][n][0], (d[K*(N//C)][0], sum([float(o) for o in row]) /
                (1 if len(row) == 0 else len(row)))) for n, row in
            enumerate([[x[i][1] for x in [x[1] for x in d][(K*(N//C)):(K+1)*(N//C)]] for i in
                      xrange(len(d[0][1]))])] for K in xrange(C)]
        # data = [sum(numpy.array(data[(i*(N/C)):((i+1)*(N/C))][1]))/(N/C) for i in xrange(C)]
        # data.reverse()
        print data
        keys = [int(dict(v)[sensor][0]) for v in data]
        keys = ["-%d min" % ((v-min(keys))/60) for v in keys]
        return render_template("chart.html", device_name=device,
                               sensor_name=sensor,
                               data={
                               'x': keys,
                               'y': [str(dict(v)[sensor][1])[:4] for v in data],
                               },
                               info=get_info())
Ejemplo n.º 10
0
def chart_sensors(device):
    file_name = os.path.join(LOG_PATH, device)
    if os.path.exists(file_name):
        data = sqlite.open(file_name).getlast()[0][1]
        return render_template("device_sensors.html", device_name=device,
                               sensors=sorted(dict(data).keys()), info=get_info())