<commit_before>import serial
import json
import os, sys
import time
import subprocess
import itertools

class getCounts():
  """ Returns a generator function that outputs the counts from the usbcounter device. 
  t is the no. of data points to acquire. -1 for endless stream """
  def __init__(self, t):
    timestamp = time.strftime('%Y%m%d_%H%M')
    if t == -1:
      generator = (self.talk() while True)
  def talk(self):
    proc = subprocess.Popen(['./getresponse', 'COUNTS?'], stdout = subprocess.PIPE)
    output = proc.stdout.read()
    if output =="timeout while waiting for response":
      pass
    else:
      data = output.rstrip().split(' ')
      data.pop(0)<commit_msg>finished generator function<commit_after>#!/bin/python3
import serial
import json
import os, sys
import time
import subprocess
import itertools

class getCounts():
  """ Returns a generator function that outputs the counts from the usbcounter device. 
  t is the no. of data points to acquire. -1 for endless stream """
  def __init__(self, t):
    timestamp = time.strftime('%Y%m%d_%H%M')
    if t == -1:
      generator = (self.talk() for i in itertools.count(0, 1))
    else:
      generator = (self.talk() for i in range(t))
    return generator
  def talk(self):
    proc = subprocess.Popen(['./getresponse', 'COUNTS?'], stdout = subprocess.PIPE)
    output = proc.stdout.read()
    if output =="timeout while waiting for response":
      pass
    else:
      data = output.rstrip().split(' ')
      data.pop(0)
{'fraction_non_alphanumeric': 0.12450066577896138, 'fraction_numerical': 0.005992010652463382, 'mean_word_length': 3.3314121037463975, 'pattern_counts': {'":': 2, '<': 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': '321655', 'n_tokens_mistral': 467, 'n_tokens_neox': 460, 'n_words': 160}