コード例 #1
0
	def receivePacket(self, packet):
		"""
		Description

		:param dict(str, obj) packet: The header, data, etc., packet

		:rtype: (int, str)
		:returns: An (id, action) tuple
		"""
		if packet["type"] == "header":
			self.dataFile = DataFile("data", packet, log=True)
			return None
		if packet["type"] == "eof":
			self.dataFile.close()
			self.dataFile = None
			return None

		if not self.dataFile:
			print("Header has not been provided--rejecting packet")
			return None

		if packet["type"] == "data":
			return self.dataFile.write(packet)
		if packet["type"] == "event":
			return self.dataFile.write(packet)

		print(f'Received packet of unknown type {packet["type"]}--rejecting')
		return None
コード例 #2
0
 def __init__(self, file_name):
   DataFile.__init__(self, file_name)
   result_file_info = self._get_file_info()
   self.topic = Topic.create_or_update(result_file_info['topic_id'])
   self.user = User.create_or_update(result_file_info['user_id'])
   self.query = Query.create_or_update(result_file_info['query_id'], topic=self.topic, user=self.user)
   self.__parse()
コード例 #3
0
ファイル: bitcoin_tools.py プロジェクト: z2trillion/bitcrumbs
class BlockChain:
	def __init__(self,data_directory='/Users/mason/Library/Application Support/Bitcoin/blocks/'):
		self.data_file	=	DataFile(data_directory)
	def __iter__(self):
		return self
	def next(self):
		assert self.data_file.readHex(4)=='f9beb4d9'
		block_length=self.data_file.readInt(4)
		return Block(self.data_file.read(block_length))
コード例 #4
0
 def __init__(self, file_name):
   DataFile.__init__(self, file_name)
   result_file_info = self._get_file_info()
   self.topic = Topic.create_or_update( result_file_info['topic_id'] )
   self.user = User.create_or_update( result_file_info['user_id'] )
   self.condition = Condition.create_or_update( result_file_info['condition'] )
   self.__create_or_update_session()
   self.query = Query.create_or_update( result_file_info['query_id'], topic = self.topic, user = self.user, session = self.session )
   self.actions = self.__parse()
   self.topic.add_actions( self.actions )
   self.user.add_actions( self.actions )
   self.query.add_actions( self.actions )
   self.session.add_actions( self.actions )
   self.session.add_query( self.query )
コード例 #5
0
ファイル: hclu.py プロジェクト: jpzk/hclu
    def load_data(self, filename, cluster_indices):
        """This method is used to load data using CSV format."""

        if(not isinstance(filename, str)):
            raise TypeError("filename is not instance of str.")
        
        data_file = DataFile()
        data_file.filename = filename
        
        try:
            tmp_row = []
            reader = csv.reader(open(filename, 'rb'), delimiter=',')
            for datarow in reader:
                tmp_row.append(datarow)

            data_file.attributes = tmp_row[0]

            indices = Set(range(0, len(tmp_row[0])))
            ignored_indices = indices - Set(cluster_indices)            

            for i in xrange(1, len(tmp_row)):
                tmp_data = []               

                is_cluster_index = lambda (idx, val) : idx in cluster_indices
                is_ignored_index = lambda (idx, val) : idx in ignored_indices
                strip = lambda (idx, val) : val

                for element in map(strip,
                    filter(is_cluster_index, enumerate(tmp_row[i]))):                    
                    tmp_data.append(float(element))    
                    
                # Generating and appending Data Element
                data_file.elements.append(DataElement(
                    np.array(tmp_data), 
                    map(strip,filter(is_ignored_index, enumerate(tmp_row[i]))),  
                    map(strip,filter(is_ignored_index,\
                        enumerate(data_file.attributes)))))

        except Exception:
            traceback.print_exc(file=sys.stdout)
            raise HcluException("load data failed. terminating.")
        
        data_file.numOfElements = len(tmp_row)-1
        self.data_files.append(data_file)
        
        self.data_loaded = True
        
        print ("Loaded " + str(len(tmp_row)-1) + " datasets")
コード例 #6
0
class Server(object):
	"""
	A single-threaded server for receiving data packets
	"""

	def __init__(self):
		if hasattr(self, "dataFile") and self.dataFile:
			_closeOutfile(self.dataFile)
		self.dataFile = None

	def receivePacket(self, packet):
		"""
		Description

		:param dict(str, obj) packet: The header, data, etc., packet

		:rtype: (int, str)
		:returns: An (id, action) tuple
		"""
		if packet["type"] == "header":
			self.dataFile = DataFile("data", packet, log=True)
			return None
		if packet["type"] == "eof":
			self.dataFile.close()
			self.dataFile = None
			return None

		if not self.dataFile:
			print("Header has not been provided--rejecting packet")
			return None

		if packet["type"] == "data":
			return self.dataFile.write(packet)
		if packet["type"] == "event":
			return self.dataFile.write(packet)

		print(f'Received packet of unknown type {packet["type"]}--rejecting')
		return None
コード例 #7
0
 def __init__(self, file_name):
     DataFile.__init__(self, file_name)
     self.__parse()
コード例 #8
0
 def __init__(self, file_name):
     DataFile.__init__(self, file_name)
     self.query_counter = 0
     self.actions = self.__parse()
コード例 #9
0
 def __init__(self):
     DataFile.__init__(self)
コード例 #10
0
 def __init__(self, file_name):
   DataFile.__init__(self, file_name)
   self.__parse()
コード例 #11
0
 def create_file(self):
     self._file = DataFile()
コード例 #12
0
ファイル: bitcoin_tools.py プロジェクト: z2trillion/bitcrumbs
	def __init__(self,data_directory='/Users/mason/Library/Application Support/Bitcoin/blocks/'):
		self.data_file	=	DataFile(data_directory)