<commit_before>#!/bin/python2
from mpi4py import MPI
import time
import subprocess
import argparse
from mjolnir import Mjolnir
import numpy
import os
import json

def check_dir(directory):
	if not os.path.exists(directory):
	    os.makedirs(directory)

class apdControl():
	def __init__(self,binsize):
		self.comm = MPI.COMM_WORLD
		self.binsize = binsize
		self.start_t = time.time()
		self.c = int(binsize[0])
		self.data = []
		#meta = self.comm.recv(source = 1, tag = 1)
		self.id = None
		self.timestamp = None
		#self.grabData()
	def grabData(self):
		check_dir(self.timestamp)
		while self.c > 0:
			self.ping()
			time.sleep(0.2)
		with open(os.path.join('data', self.timestamp, str(self.id)), 'wb+') as f:
			for i in xrange(len(self.data)):
				f.write("{}\t{}\t{}\n".format(i, self.data[i][1][0], self.data[i][1][1]))
		self.comm.send("done", dest = 1, tag = 0)
        def ping(self):
                proc = subprocess.Popen(['./getresponse','COUNTS?'], stdout=subprocess.PIPE)
    	        output = proc.stdout.read()
                if output =="timeout while waiting for response":
                        pass
                else:
                        t = time.time() - self.start_t
                        data = output.rstrip().split(' ')
                        data.pop(0)
			print data
                try:
                        data = map(lambda x: float(x), data)
                        _data = [t, data]
                        self.c -= 1
                        self.data.append(_data)
                except ValueError:
                        pass
class thorControl():
	def __init__(self, step, deg):
		self.step = step
		self.deg = deg
		self.timestamp = None
	def start(self):

		comm = MPI.COMM_WORLD
		m = Mjolnir()
		x = int(self.deg[0]) * 3600
		x /= float(2.16)
		s = int(self.step[0])
		x /= s
		self.data = {}
		for i in xrange(int(x)):
			m.moveRotMotor(self.step[0])
			comm.send("next", dest = 0, tag = 0)
			comm.send([self.timestamp, i], dest = 0, tag = 1)
			#self.data[i] = comm.recv(source = 1, tag = 0)
			if comm.recv(source = 0, tag = 0) == "done":
				continue
			time.sleep(1)
		comm.send("terminated", dest = 0, tag = 0)
		print "completed"

def main(kwargs):
	comm = MPI.COMM_WORLD
	rank = comm.Get_rank()
	timestamp = time.strftime('%Y%m%d_%H%M')
	metadata = {'timestamp': timestamp,
	'bin_size': kwargs['binsize'],
	'step_size':kwargs['step'],
	'degrees_moved': kwargs['degree']}
	with open(os.path.join(timestamp, 'metadata.json'), 'w') as f:
		json.dump(metadata, f)
	if rank == 0:
		print "on fruitcake0: apd control"
		#a = apdControl(kwargs['binsize'])
		while True:
			a = comm.recv(source = 1, tag = 0)
			if a == "next":
				b = comm.recv(source = 1, tag = 1)
				c = apdControl(kwargs['binsize'])
				c.id = b[1]
				c.timestamp = b[0]
				c.grabData()
			else:
				break<commit_msg>attempts to fix line 85 no such file or dir problem<commit_after>#!/bin/python2
from mpi4py import MPI
import time
import subprocess
import argparse
from mjolnir import Mjolnir
import numpy
import os
import json

def check_dir(directory):
	if not os.path.exists(directory):
	    os.makedirs(directory)

class apdControl():
	def __init__(self,binsize):
		self.comm = MPI.COMM_WORLD
		self.binsize = binsize
		self.start_t = time.time()
		self.c = int(binsize[0])
		self.data = []
		#meta = self.comm.recv(source = 1, tag = 1)
		self.id = None
		self.timestamp = None
		#self.grabData()
	def grabData(self):
		check_dir(self.timestamp)
		while self.c > 0:
			self.ping()
			time.sleep(0.2)
		with open(os.path.join('data', self.timestamp, str(self.id)), 'wb+') as f:
			for i in xrange(len(self.data)):
				f.write("{}\t{}\t{}\n".format(i, self.data[i][1][0], self.data[i][1][1]))
		self.comm.send("done", dest = 1, tag = 0)
        def ping(self):
                proc = subprocess.Popen(['./getresponse','COUNTS?'], stdout=subprocess.PIPE)
    	        output = proc.stdout.read()
                if output =="timeout while waiting for response":
                        pass
                else:
                        t = time.time() - self.start_t
                        data = output.rstrip().split(' ')
                        data.pop(0)
			print data
                try:
                        data = map(lambda x: float(x), data)
                        _data = [t, data]
                        self.c -= 1
                        self.data.append(_data)
                except ValueError:
                        pass
class thorControl():
	def __init__(self, step, deg):
		self.step = step
		self.deg = deg
		self.timestamp = None
	def start(self):

		comm = MPI.COMM_WORLD
		m = Mjolnir()
		x = int(self.deg[0]) * 3600
		x /= float(2.16)
		s = int(self.step[0])
		x /= s
		self.data = {}
		for i in xrange(int(x)):
			m.moveRotMotor(self.step[0])
			comm.send("next", dest = 0, tag = 0)
			comm.send([self.timestamp, i], dest = 0, tag = 1)
			#self.data[i] = comm.recv(source = 1, tag = 0)
			if comm.recv(source = 0, tag = 0) == "done":
				continue
			time.sleep(1)
		comm.send("terminated", dest = 0, tag = 0)
		print "completed"

def main(kwargs):
	comm = MPI.COMM_WORLD
	rank = comm.Get_rank()
	timestamp = time.strftime('%Y%m%d_%H%M')
	metadata = {'timestamp': timestamp,
	'bin_size': kwargs['binsize'],
	'step_size':kwargs['step'],
	'degrees_moved': kwargs['degree']}
	check_dir(self.timestamp)
	with open(os.path.join(self.timestamp, 'metadata.json'), 'w') as f:
		json.dump(metadata, f)
	if rank == 0:
		print "on fruitcake0: apd control"
		#a = apdControl(kwargs['binsize'])
		while True:
			a = comm.recv(source = 1, tag = 0)
			if a == "next":
				b = comm.recv(source = 1, tag = 1)
				c = apdControl(kwargs['binsize'])
				c.id = b[1]
				c.timestamp = b[0]
				c.grabData()
			else:
				break
{'fraction_non_alphanumeric': 0.1561634349030471, 'fraction_numerical': 0.01592797783933518, 'mean_word_length': 2.348985507246377, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, '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': '59768', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2039, 'n_words': 486}