<commit_before># oh boy oh boy!
# It's project HOT_PANTS
from __future__ import print_function
import Adafruit_BBIO.UART as uart
import Adafruit_BBIO.ADC as adc
from Adafruit_Thermal import *
# import TMP102 as tmp
# import VCNL4000 as vcnl
import time
from serial import Serial
import random
import atexit
import sentence_generator as sg

theObj = 'APPLE'
sensor_pin = 'P9_40'
readings = []
fake = 0

def parseLen(text):
    L = []
    # add newlines to cause text to print properly
    # we need this because we're printing upside-down text
    # "call the police, it is faint-hearted" should be printed as
    # "rted" then linebreak then "Call the police, it is faint-hea"
    # which is "rted\nCall the police, it is faint-hea"
    # "faint-hearted\nCall the police, it is"

    if len(text) > Adafruit_Thermal.maxColumn: # 32 is defined by the printer; max chars per line
        r = len(text)%32
        L.append(text[-r:]+'\n')
        for i in reversed(range(len(text)/32)):
            L.append(text[i*32:(i+1)*32]+'\n')
    else:
        L.append(text)
    return ''.join(L)

def parse(text):
    r = text.split(' ')
    curLine = ''
    fin = []
    tally = 0
    for w in r:
        if len(w)+len(curLine) > (Adafruit_Thermal.maxColumn-1):
            fin.append(curLine)
            curLine = ''
            curLine+=w
        else:
            curLine+=' '+w
    # print curLine
    fin.append(curLine)
    fin[0] = fin[0].lstrip()
    fin.reverse()
    rt = '\n'.join(fin)
    return rt+'\n'

def slowPrint(text):
    for i in text.splitlines():
        printer.print(i+'\n')
        time.sleep(0.1)

def checkSensor():
    global rPast
    global rMin
    global rMax
    global noop
    # change this to whatever get-readings call we need
    r = adc.read(sensor_pin)
    readings.append(r)
    if len(readings)>WINDOW_SIZE:
        del readings[:-WINDOW_SIZE]
    
    avg = 0
    for i in readings:
        avg += (i/float(len(readings)))

    delta = r-rPast
    # delta = r-avg
    
    if r > rMax:
        rMax = r
        # does this merit an emission? Or should delta have to be > threshold?
    if r < rMin:
        rMin = r
        # does this merit an emission? Or should delta have to be > threshold?
    
    print('%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f'%(r, delta, avg, rMin, rMax))

    if abs(delta) > emission_threshold:
        if len(readings)==WINDOW_SIZE: # this test prevents emissions before WINDOW_SIZE samples have been taken
            # print('emitting remark')
            noop = 0
            emit_remark(r, delta, avg)
        else:
            pass
    else:
        noop += 1
        if noop > noop_threshold:
            noop = 0
            # print('emitting dream')
            emit_dream(r, delta, avg)
    rPast = r

def emit_dream(r, delta, avg):
    global fake
    if fake == 5:
        fake = 0
        norm = mapVals(r, rMin, rMax, 0.0, 0.999)
        # sen = sg.generate(theObj, (1.0-norm), delta, True) # reverse the range so 1=no light, 0=full light
        sen = sg.generate(theObj, (1.0-r), delta, True) # reverse the range so 1=no light, 0=full light
        
        # printer.flush()
        printer.feed(1)
        printer.print('            . . .             ')
        printer.feed(1)

        slowPrint(parse(sen))
        
        # printer.flush()
        printer.feed(1)
        printer.print('            . . .             ')
        printer.feed(2)
    else:
        fake += 1
        norm = mapVals(r, rMin, rMax, 0.0, 0.999)
        sen = sg.generate(theObj, (1.0-norm), delta, False) # reverse the range so 1=no light, 0=full light
        slowPrint(parse(sen))
        printer.feed(2)

def emit_remark(r, delta, avg):
    norm = mapVals(r, rMin, rMax, 1.0, 0.0)
    # sen = sg.generate(theObj, (1.0-norm), delta, False) # reverse the range so 1=no light, 0=full light
    sen = sg.generate(theObj, (1.0-r), delta, False) # reverse the range so 1=no light, 0=full light
    slowPrint(parse(sen))
    # slowPrint(str(norm))
    printer.feed(2)
<commit_msg>weird problems with mapVals and photocell sentence generation<commit_after># oh boy oh boy!
# It's project HOT_PANTS
from __future__ import print_function
import Adafruit_BBIO.UART as uart
import Adafruit_BBIO.ADC as adc
from Adafruit_Thermal import *
# import TMP102 as tmp
# import VCNL4000 as vcnl
import time
from serial import Serial
import random
import atexit
import sentence_generator as sg

theObj = 'APPLE'
sensor_pin = 'P9_40'
readings = []
fake = 0

def parseLen(text):
    L = []
    # add newlines to cause text to print properly
    # we need this because we're printing upside-down text
    # "call the police, it is faint-hearted" should be printed as
    # "rted" then linebreak then "Call the police, it is faint-hea"
    # which is "rted\nCall the police, it is faint-hea"
    # "faint-hearted\nCall the police, it is"

    if len(text) > Adafruit_Thermal.maxColumn: # 32 is defined by the printer; max chars per line
        r = len(text)%32
        L.append(text[-r:]+'\n')
        for i in reversed(range(len(text)/32)):
            L.append(text[i*32:(i+1)*32]+'\n')
    else:
        L.append(text)
    return ''.join(L)

def parse(text):
    r = text.split(' ')
    curLine = ''
    fin = []
    tally = 0
    for w in r:
        if len(w)+len(curLine) > (Adafruit_Thermal.maxColumn-1):
            fin.append(curLine)
            curLine = ''
            curLine+=w
        else:
            curLine+=' '+w
    # print curLine
    fin.append(curLine)
    fin[0] = fin[0].lstrip()
    fin.reverse()
    rt = '\n'.join(fin)
    return rt+'\n'

def slowPrint(text):
    for i in text.splitlines():
        printer.print(i+'\n')
        time.sleep(0.1)

def checkSensor():
    global rPast
    global rMin
    global rMax
    global noop
    # change this to whatever get-readings call we need
    r = adc.read(sensor_pin)
    readings.append(r)
    if len(readings)>WINDOW_SIZE:
        del readings[:-WINDOW_SIZE]
    
    avg = 0
    for i in readings:
        avg += (i/float(len(readings)))

    delta = r-rPast
    # delta = r-avg
    
    if r > rMax:
        rMax = r
        # does this merit an emission? Or should delta have to be > threshold?
    if r < rMin:
        rMin = r
        # does this merit an emission? Or should delta have to be > threshold?
    
    print('%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f'%(r, delta, avg, rMin, rMax))

    if abs(delta) > emission_threshold:
        if len(readings)==WINDOW_SIZE: # this test prevents emissions before WINDOW_SIZE samples have been taken
            # print('emitting remark')
            noop = 0
            emit_remark(r, delta, avg)
        else:
            pass
    else:
        noop += 1
        if noop > noop_threshold:
            noop = 0
            # print('emitting dream')
            emit_dream(r, delta, avg)
    rPast = r

def emit_dream(r, delta, avg):
    global fake
    if fake == 5:
        fake = 0
        # norm = mapVals(r, rMin, rMax, 0.0, 0.999)
        # sen = sg.generate(theObj, (1.0-norm), delta, True) # reverse the range so 1=no light, 0=full light
        sen = sg.generate(theObj, (1.0-r), delta, True) # reverse the range so 1=no light, 0=full light
        
        # printer.flush()
        printer.feed(1)
        printer.print('            . . .             ')
        printer.feed(1)

        slowPrint(parse(sen))
        
        # printer.flush()
        printer.feed(1)
        printer.print('            . . .             ')
        printer.feed(2)
    else:
        fake += 1
        # norm = mapVals(r, rMin, rMax, 0.0, 0.999)
        sen = sg.generate(theObj, (1.0-r), delta, False) # reverse the range so 1=no light, 0=full light
        slowPrint(parse(sen))
        printer.feed(2)

def emit_remark(r, delta, avg):
    norm = mapVals(r, rMin, rMax, 1.0, 0.0)
    # sen = sg.generate(theObj, (1.0-norm), delta, False) # reverse the range so 1=no light, 0=full light
    sen = sg.generate(theObj, (1.0-r), delta, False) # reverse the range so 1=no light, 0=full light
    slowPrint(parse(sen))
    # slowPrint(str(norm))
    printer.feed(2)

{'fraction_non_alphanumeric': 0.12054726981387896, 'fraction_numerical': 0.021447060273634907, 'mean_word_length': 2.137664346481052, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '314547', 'n_tokens_mistral': 2933, 'n_tokens_neox': 2763, 'n_words': 803}