<commit_before>#!/usr/bin/env python2

import time
import datetime
from Nonin import *

def csv_filename(device_id=0):
    dt = datetime.datetime.now()
    dt_str = dt.strftime('%Y-%m-%dT%H:%M:%S')
    filename = '/tmp/wristox-sessions.%d.%s.csv' % (device_id, dt_str)
    return filename

POLL_INTERVAL = 150 # seconds

device = Nonin3150.get_device()
nonin = Nonin3150(device)

# time.sleep(5) # wait for the device to finish changing modes if necessary

while True:
    # Read, Save and Clear session data from the device
    print "Reading data..."
    try:
        sessions = nonin.read_sessions()
        if sessions is not None:
            exporter = Exporter(sessions)
            filename = csv_filename(device_id=2)
            print "Saving session data to %s" % filename
            exporter.export(format='csv', filename=filename)

            print "Clearing device memory"
            nonin.clear_sessions()

            print "Waiting for %d seconds" % POLL_INTERVAL
            time.sleep(POLL_INTERVAL)
    except Exception:
        print "Exception raised, probably an ACK required"

#import pdb
#pdb.set_trace()
for session in sessions[0]: print session
print "Finished!"
<commit_msg>Changes to the data-poller for the sleep test<commit_after>#!/usr/bin/env python2

import re
import sys
import time
import datetime
from Nonin import *

POLL_INTERVAL = 105 # seconds

def csv_filename(device_id=0):
    # device_id can be a dev node like /dev/rfcomm0
    try:
        device_id = int(device_id)

    except ValueError:
        device_id = re.sub('^\D+', '', device_id)

    dt = datetime.datetime.now()
    dt_str = dt.strftime('%Y-%m-%dT%H:%M:%S')
    filename = '/home/wais/tmp/wristox-sessions.%d.%s.csv' % (device_id, dt_str)
    return filename


ack_problem = True
nonin = None

while ack_problem:
    try:
        # device = Nonin3150.get_device()
        device = sys.argv[1]
        nonin = Nonin3150(device)
        ack_problem = False

    except Exception:
        ack_problem = True
        time.sleep(1)

# no ack_problem and nonin is now guaranteed to be a valid Nonin3150
while True:
    # Read, Save and Clear session data from the device
    print "Reading data..."
    try:
        sessions = nonin.read_sessions()
        if sessions is not None:
            exporter = Exporter(sessions)
            filename = csv_filename(device_id=2)
            print "Saving session data to %s" % filename
            exporter.export(format='csv', filename=filename)

            print "Clearing device memory"
            nonin.clear_sessions()

            print "Waiting for %d seconds" % POLL_INTERVAL
            time.sleep(POLL_INTERVAL)
    except Exception:
        time.sleep(1)
        print "Exception raised, probably an ACK required"

#import pdb
#pdb.set_trace()
#for session in sessions[0]: print session
#print "Finished!"

{'fraction_non_alphanumeric': 0.09968630184733357, 'fraction_numerical': 0.013593586615545486, 'mean_word_length': 2.698453608247423, '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': '3360588', 'n_tokens_mistral': 939, 'n_tokens_neox': 892, 'n_words': 257}