Esempio n. 1
0
def runTest():
    print('Running testcases...')
    
    # Import HelloLexer
    if not DIST in sys.path:
        sys.path.append(DIST)

    from Fragment import Fragment

    # Read all test files
    testfiles = sorted(os.listdir(TESTS))

    for filename in testfiles:
        printBreak()
        print('Running test : ' + filename)
        printBreak()
        filepath = os.path.join(DIR, './tests', filename)
        # file = open(filepath, 'r')
        # code = file.read()
        # print(code)
        # file.close()
        lexer = Fragment(FileStream(filepath))
        tokens = []
        token = lexer.nextToken()
        while token.type != Token.EOF:
            tokens.append(token.text)
            token = lexer.nextToken()
        tokens.append('<EOF>')
        print(','.join(tokens))

    printBreak()
    print('Run tests completely')
Esempio n. 2
0
    def partition(frame):
        """ Partition Frame into processed fragments 
        
        Args:
            frame (np.ndarry): Frame to partition.
        
        Returns: 
            A list of Fragments derived from Frame.
        """
        height, width = frame.shape[:2]
        partitionSize = height // 4
        fragments = []

        for i in range(4):
            startPartition = i * partitionSize
            # Extract and color-process fragment
            fragment = Fragment(frame[startPartition:(startPartition +
                                                      partitionSize), 0:width])

            # Set center points to be relative to full Frame
            fragment.setRelativeContourCtrX(0)
            fragment.setRelativeImageCtrX(0)
            fragment.setRelativeContourCtrY(startPartition)
            fragment.setRelativeImageCtrY(startPartition)

            fragments.append(fragment)

        return fragments
Esempio n. 3
0
class Matchset:
    fragment_1 = Fragment()  # Contour Fragment 1
    fragment_2 = Fragment()  # Contour Fragment 2
    match_1_start = 0
    match_1_end = 0
    match_2_end = 0
    match_2_start = 0
    match_1 = Fragment()
    match_2 = Fragment()
    i = 0
    j = 0
    score = 0  # Matching Score
Esempio n. 4
0
    def retrieve(self,filepath,order):
        #initial configs
        logger = Logger.getInstance()
        
        order = int(order)        
        tokens = filepath.split('/');
        filetitle = tokens[len(tokens)-1]
        logger.logInfo('retrieving from file: ' + filetitle)
        reader = ParserProvider.getParser(filetitle)
        filepointer = reader.openFile(filepath)
        fr = reader.readFile(filepointer)

        #recover fragment
        fragment = Fragment('',filepath,order,'')
        text = reader.readCertSegment(filepointer,order)
        if(text!=''):
            fragment.set_text(text)
        
        return fragment
Esempio n. 5
0
    def consume_packet(self, header_bstr, packet_time):
        """
        Accept new packet and associate it with appropriate trace

        Keyword arguments:
        header_bstr -- binary string of the packet header
        packet_time -- time tuple (sec, ms) since epoch of header
        """
        # Check if packet isn't complete
        new_fragment = Fragment(header_bstr, packet_time)
        if new_fragment.id in self.incomplete_packets:
            packet = self.incomplete_packets[new_fragment.id]
            packet.add_frag(new_fragment)
        else:
            packet = Packet(new_fragment)
            self.incomplete_packets[packet.id] = packet

        # Set start time if very first packet
        if self.ref_time is None:
            self.ref_time = packet.time

        if packet.is_complete():
            del self.incomplete_packets[packet.id]
            if (packet.protocol == Protocol.UDP
                    or (packet.protocol == Protocol.ICMP
                        and packet.type == Type.ECHO)):
                self.traces[packet.get_trace_sig()] = Trace(
                    packet, self.ref_time)
                self.trace_order.append(packet.get_trace_sig())

            elif packet.protocol == Protocol.ICMP and packet.type == Type.TIME_EXCEEDED:
                if packet.get_trace_sig() in [
                        trace.get_sig() for trace in self.traces.values()
                ]:
                    self.traces[packet.get_trace_sig()].add_resp(packet)
                else:
                    if DEV_ENV:
                        print("Error: ICMP receieved for nonexistant probe")
                        print(packet.get_trace_sig())
            else:
                if DEV_ENV:
                    print("Protocol not savable in traces")
Esempio n. 6
0
	def __init__(self, filename, admin):

		# initialize class variables to default state
		self.id = 0
		self.name = filename
		self.fileSize = os.path.getsize('upload/' + filename)
		self.admin = admin
		self.startDate = datetime.datetime.now()
		self.endDate = datetime.datetime.now()
		self.volunteers = []
		self.fragments = []
		self.state = 'started'
		self.files = 'upload/' + filename

		#initialize project id
		number = 0
		for project in db.projects.find():
			number = number + 1

		self.id = number + 1

		# Create project fragments using Fragments class
		Fragment.fragments(filename)
		
		# Create Fragment class instances and save in Project class fragments list variable
		#for index, file in enumerate(os.listdir('fragments/')):
		#	if file[-3:] == 'zip':
		#		fragment = Fragment()
		#		fragment.id = index
		#		fragment.size = os.path.getsize('fragments/' + file)
		#		self.fragments.append(fragment)

		#create fragments list to store in project class
		for index, file in enumerate(os.listdir('fragments/')):
			if file[-3:] == 'zip':
				fragment = dict()
				fragment['id'] = index
				fragment['size'] = os.path.getsize('fragments/' + file)
				fragment['time'] =datetime.datetime.now()
				self.fragments.append(fragment)
				#fragment.append(index)
				#fragment.append(os.path.getsize('fragments/' + file))
				#fragment.append(datetime.datetime.now())
				#fragment.append()

		#Save the project and files in the mongodb
		project = db.projects()
		project['id'] = self.id
		project['name'] = self.name
		project['fileSize'] = self.fileSize
		project['admin'] = self.admin
		project['startDate'] = self.startDate
		project['endDate'] = self.endDate 
		project['volunteers'] = self.volunteers
		project['fragments'] = self.fragments
		#for fragment in 
		project['state'] = self.state
		project.save()
		#self.project = project

		# get _id of the saved project
		for project in db.projects.find({ 'id' : self.id }):
			docid = str(project['_id'])

		#Save project files in mongodb in Project Document
		file = open('upload/' + filename)
		project.fs.put(file)
		#project.files = self.files = 'upload/' + filename

		#Save fragments in mongodb
		for file in os.listdir('fragments/'):
			fragment = db.files()
			fragment['projectid'] = self.id
			fragment['name'] = file
			fragment['docid'] = docid
			fragment['type'] = 'fragment'
			fragment.save()
			open_file = open('fragments/' + file, 'rb')
			fragment.fs.file.put(open_file)
        alignment_bucket = [None, None]
        current_read = alignment.read_name

    # Skip non-primary and supplemental alignments
    if alignment.flag & (256 + 2048):
        continue

    if alignment.strand == '+':
        alignment_bucket[0] = alignment
    elif alignment.strand == '-':
        alignment_bucket[1] = alignment

    # process if the bucket is full
    if alignment_bucket[0] and alignment_bucket[1]:

        fragment = Fragment(alignment_bucket[0], alignment_bucket[1])

        # Check if fragment ends are conteined in a primer region
        # Return range if True, None otherwise.
        range_left = primer_range.is_contained(fragment.ref_start, 'left')
        range_right = primer_range.is_contained(fragment.ref_end, 'right')

        # Chop ends of the fragment overlapping to primer
        fragment.slice(range_left)
        fragment.slice(range_right)

        if args.verbose:
            sys.stderr.write(current_read + ':')
            sys.stderr.write('  Fragment interval: {}-{}\n'.format(
                fragment.ref_start, fragment.ref_end))
            sys.stderr.write(
Esempio n. 8
0
 def test(self):
     f = Fragment("test", "/home/mgazzola/test.txt", 1, "test")
     self.assertEqual("test", f.get_text(), "OK")