Esempio n. 1
0
    def __init__(self):
        Segment.__init__(self)
        self.fieldCount = 2

        self.id = Element(name="IEA",
                          description="Interchange Control Trailer Code",
                          required=True,
                          minLength=3,
                          maxLength=3,
                          content="")
        self.fields.append(self.id)

        self.iea01 = Element(name="IEA01",
                             description="Number of Included Groups",
                             required=True,
                             minLength=1,
                             maxLength=5,
                             content="")
        self.fields.append(self.iea01)

        self.iea02 = Element(name="IEA02",
                             description="Interchange Control Number",
                             required=True,
                             minLength=1,
                             maxLength=9,
                             content="")
        self.fields.append(self.iea02)
Esempio n. 2
0
def genKeywords():
    wb = xlrd.open_workbook("keywords.xlsx")
    sheet = wb.sheet_by_index(0)
    keywords = []
    for i in range(sheet.ncols):
        v = sheet.col_values(i)
        v = [s for s in v if s != '']
        keywords.append(v)
    for k in keywords:
        name = "key" + parseName(k[0])
        values = k[1:]
        for i in range(len(values)):
            values[i] = values[i].replace("&", "&")
        key = Element(name, "", "string", "No", "No", False, None, False, True,
                      ["keywords"], values)
        direct = DIRECTORY + "keywords" + "\\"
        filename = name + ".xsd"
        if not os.path.exists(direct):
            os.makedirs(direct)
        f = open(direct + filename, 'w')
        output = genHeader() + key.gen() + genFooter()
        f.write(output)
        f.close()
    f = open('keywords.txt', 'r')
    keys = [t for t in f.read().split('\n') if t != ""]
    for k in keys:
        direct = DIRECTORY + "keywords" + "\\"
        filename = direct + k + ".xsd"
        f = open(direct + k + ".xsd", 'w')
        key = Element(k, "", "string", "No", "No", False, None, False, True,
                      ["keywords"])
        output = genHeader() + key.gen() + genFooter()
        f.write(output)
        f.close()
Esempio n. 3
0
    def __init__(self):
        Segment.__init__(self)
        self.fieldCount = 2
        self.element_separator = "|"
        self.segment_terminator = "\n"

        self.id = Element(name="MOCK",
                          description="Mock Segment ID",
                          required=True,
                          minLength=2,
                          maxLength=3,
                          content="MCK")
        self.fields.append(self.id)

        self.test01 = Element(name="TEST01",
                              description="TEST 01 Segment",
                              required=False,
                              minLength=1,
                              maxLength=4,
                              content="TST1")
        self.fields.append(self.test01)

        self.test02 = Element(name="TEST02",
                              description="TEST 02 Segment",
                              required=False,
                              minLength=1,
                              maxLength=4,
                              content="")
        self.fields.append(self.test02)
Esempio n. 4
0
    def __init__(self):
        Segment.__init__(self)
        self.fieldCount = 3

        self.id = Element(name="ST",
                          description="Transaction Set Header",
                          required=True,
                          minLength=2,
                          maxLength=2,
                          content="ST")
        self.fields.append(self.id)

        self.st01 = Element(name="ST01",
                            description="Transaction Set ID Code",
                            required=True,
                            minLength=3,
                            maxLength=3,
                            content="")
        self.fields.append(self.st01)

        self.st02 = Element(name="ST02",
                            description="Transaction Set Control Number",
                            required=True,
                            minLength=4,
                            maxLength=9,
                            content="")
        self.fields.append(self.st02)

        self.st03 = Element(name="ST03",
                            description="Implementation Convention Reference",
                            required=False,
                            minLength=1,
                            maxLength=35,
                            content="")
        self.fields.append(self.st03)
Esempio n. 5
0
    def __init__(self):
        Segment.__init__(self)
        self.fieldCount = 2

        self.id = Element(name="SE",
                          description="Transaction Set Trailer",
                          required=True,
                          minLength=2,
                          maxLength=2,
                          content="SE")
        self.fields.append(self.id)

        self.se01 = Element(name="SE01",
                            description="Number of Included Segments",
                            required=True,
                            minLength=1,
                            maxLength=6,
                            content="")
        self.fields.append(self.se01)

        self.se02 = Element(name="SE02",
                            description="Transaction Set Control Number",
                            required=True,
                            minLength=4,
                            maxLength=9,
                            content="")
        self.fields.append(self.se02)
    def _validate_words(self, line_num, i):

        #print("-- VALIDTE WORDS -- ")

        line = self._program_text.splitlines()[line_num]
        line_length = len(line)

        #print(" _validate_words line " + line)
        #print(" i " + str(i))
        #print(" line_length " + str(line_length))

        word = line[i]
        i += 1

        while (i < line_length
               and (str.isalpha(line[i]) or str.isdigit(line[i])
                    or line[i] == '_')):
            word += line[i]
            i += 1

        #checar se eh reservado ou se eh identificador ou operador (and e or)
        if (word in self._key_words):
            self._elements.append(Element(word, "Reserved Word", line_num))
        #elif(word in self._operators):
        #	self._elements.append(Element(word, "Operator", line_num))
        else:
            self._elements.append(Element(word, "Indentifier", line_num))

        return i
Esempio n. 7
0
	def test_detect_cycle(self):
		Elms = [Element(ID=0, name = '0'), Element(ID=1, name='1'), Element(ID=2, name='2'), Element(ID=3, name='3')]
		edges = {Edge(Elms[0], Elms[1], '<'), Edge(Elms[0], Elms[2], '<'), Edge(Elms[0], Elms[3], '<'),
				 Edge(Elms[2], Elms[1], '<'), Edge(Elms[3], Elms[1], '<')}
		G = Graph(ID=10, typ='test', Elements=set(Elms), Edges=edges)
		OG = OrderingGraph(ID = 5, Elements = G.elements, Edges = G.edges)
		assert(not OG.detectCycle())
		OG.edges.add(Edge(Elms[1], Elms[0], '<'))
		assert (OG.detectCycle())
Esempio n. 8
0
 def readElements(self, elementData):
     elements = []
     faces = []
     iFace = 0
     iElement = 0
     # find the total number of elements generated by gmsh
     nElements = int(elementData[0])
     # determine if this is a 2D or 3D mesh by searching through the elements
     meshDim = 2
     elementTypes = elementTypes2D
     faceTypes = faceTypes2D
     for txt in elementData[1:]:
         # get the info for this element, stripping off the leading element number
         element = [int(x) for x in txt.split()[1:]]
         # what type of element have we got?
         eType = element[0]
         if eType in elementTypes3D:
             meshDim = 3
             elementTypes = elementTypes3D
             faceTypes = faceTypes3D
             break
     self["meshDim"] = meshDim
     for txt in elementData[1:]:
         # get the info for this element, stripping off the leading element number
         element = [int(x) for x in txt.split()[1:]]
         # what type of element have we got?
         eType = element[0]
         nTags = element[1]
         tag = element[2]
         if (eType in faceTypes) and (
                 tag !=
                 0):  # we have a face element that lies on a boundary
             nodes = element[2 + nTags:]
             faces.append(Element(eType, nodes, tag, []))
             iFace += 1
         elif eType in elementTypes:  # we have an element
             nodes = element[2 + nTags:]
             elements.append(Element(eType, nodes, tag, []))
             iElement += 1
     print "\t  ", iElement, "Elements and ", iFace, " Faces"
     self["elements"] = elements
     self["faces"] = faces
     # now make a list of nodes that lie on boundaries
     bNodes = {}
     bNodeTags = {}
     nIndex = 0
     for f in faces:
         fNodes = f.getNodes()
         for n in fNodes:
             if n not in bNodes:
                 bNodes[n] = nIndex
                 bNodeTags[nIndex + 1] = [f.getElementProps()]
                 nIndex += 1
             else:
                 bNodeTags[bNodes[n] + 1].append(f.getElementProps())
     self["boundaryNodes"] = bNodes
     self["boundaryNodeTags"] = bNodeTags
Esempio n. 9
0
 def __init__(self, lig, col, isHorizontal, taille):
     self.elements = []
     self.status = -1
     self.nbTouche = 0
     for i in range(taille):
         if isHorizontal:
             self.elements.append(Element(lig, col + i))
         else:
             self.elements.append(Element(lig + i, col))
Esempio n. 10
0
def writeImage(identifier, source, link):
    if link is None:
        f.write('\t<img id="' + identifier + '" src="' + source + '"/>\n')
        elements.append(Element(identifier, 'image', None))
    else:
        writeHyperlink(None, link,
                       '<img id="' + identifier + '" src="' + source + '"/>')
        elements.append(Element(identifier, 'image', None))
    return
Esempio n. 11
0
 def readFromCSV(self, fpath, scale=1.0):
     with open(fpath) as f:
         tablereader = csv.reader(filter(lambda row: row[0] != '#', f))
         for row in tablereader:
             tr = TableRow()
             for elt in row:
                 try:
                     tr.addElement(Element(str(float(elt) * scale)))
                 except:
                     tr.addElement(Element(elt))
             self.addRow(tr)
Esempio n. 12
0
 def td(self, keyword):
     if type(keyword) == str:
         index = 0
         for th in self.ths:
             index = index + 1
             if th.text == keyword:
                 break
         return Element(self.locator + "//*[" + str(index) + "]",
                        self.name + "." + "td[" + keyword + "]")
     if type(keyword) == int:
         return Element(self.locator + "//*[" + str(keyword) + "]",
                        self.name + "." + "td[" + str(keyword) + "]")
Esempio n. 13
0
def load_truss(inputfile):
    truss = FileIn(inputfile)

    list_of_elements = []

    for i in range(len(truss.element_groups)):
        element_id = i
        incidence = [truss.incidences[i][1], truss.incidences[i][2]]
        ax = truss.coordinates[incidence[0] - 1][1]
        ay = truss.coordinates[incidence[0] - 1][2]
        bx = truss.coordinates[incidence[1] - 1][1]
        by = truss.coordinates[incidence[1] - 1][2]
        length = distance(ax, ay, bx, by)
        e = truss.materials[i][0]
        area = truss.geometric_properties[i][0]
        cos = math.fabs(bx - ax) / length
        sin = math.fabs(by - ay) / length
        restrictions_dof = []
        for j in range(len(truss.bc_nodes)):
            if(truss.bc_nodes[j][0] in incidence):
                restrictions_dof.append(j+1) 
       
        element = Element(element_id, incidence, length, area, cos, sin, e, restrictions_dof)
        list_of_elements.append(element)

    return truss, list_of_elements
Esempio n. 14
0
    def create_elements(self):

        element_number = int(1)
        high = 1

        a = -1
        b = self.nodes_in_high

        for element in range(self.elements_number):

            self.elements.append(Element(element_number))

            if high == self.nodes_in_high:
                a += 1
                b += 1
                high = 1

            for j in range(4):

                if ((j == 0) or (j == 1)):
                    self.elements[element].nodes_array.append(
                        self.nodes[j + element_number + a])
                else:
                    self.elements[element].nodes_array.append(
                        self.nodes[j + element_number + b - 3])

            element_number += 1
            high += 1
Esempio n. 15
0
 def __init__(self):
     self.fieldCount = 0
     self.fields = []
     self.id = Element()
     self.element_separator = CurrentSettings.element_separator
     self.segment_terminator = CurrentSettings.segment_terminator
     self.sub_element_separator = CurrentSettings.sub_element_separator
Esempio n. 16
0
    def get(self):
        """Return the contents of the editor.

        Parameters:

        self: This object.

        Return value:

        Copy of Element being edited.

        Description:
        
        Return a new Element containing the current state of the
        editor.
        """

        # Get the tag name.
        tagName = self._tagNameLabel.cget('text')

        # Make a new Element.
        element = Element(tagName)

        # Return the new Element.
        return element
Esempio n. 17
0
def create_priority_queue():
    n = len(occurrences)
    q = []
    for i in range(n):
        element = Element(occurrences[i], i)
        PQHeap.insert(q, element)
    return q
    def __init__(self,
                 ID=None,
                 type_graph=None,
                 name=None,
                 Elements=None,
                 plan_elm=None,
                 Edges=None,
                 Restrictions=None):

        if ID is None:
            ID = uuid4()
        if type_graph is None:
            type_graph = 'PlanElementGraph'
        if Elements is None:
            Elements = set()
        if Edges is None:
            Edges = set()
        if Restrictions is None:
            Restrictions = set()

        self.OrderingGraph = OrderingGraph()
        self.CausalLinkGraph = CausalLinkGraph()

        self.flaws = FlawLib()
        self.solved = False
        self.initial_dummy_step = None
        self.final_dummy_step = None

        if plan_elm is None:
            plan_elm = Element(ID=ID, typ=type_graph, name=name)

        super(PlanElementGraph, self).__init__(ID, type_graph, name, Elements,
                                               plan_elm, Edges, Restrictions)
Esempio n. 19
0
def PQHeaper(C):
    pq = PQHeap.createEmptyPQ()
    for i in range(len(C)):
        if C[i] != 0:
            e = Element(C[i], i)
            PQHeap.insert(pq, e)
    return pq
Esempio n. 20
0
def introScreen(elementName):
    global SCREEN_WIDTH, SCREEN_HEIGHT, PLAYER, FPS, MODE, CONTROL, LAVA, WATER, POISON, ACID, GRID, PLAYER_CONTROLLED
    waitTime = 0

    player = Element(0, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0,
                     getImage(elementName), elementName, getColor(elementName))
    bigTrail = ParticleManager(
        (4.5 * SCREEN_WIDTH / 10, SCREEN_HEIGHT / 2 + 40), (20, 0), 30,
        player.color, player.name, 0.999, 100)
    longTrail = ParticleManager((4.5 * SCREEN_WIDTH / 10, SCREEN_HEIGHT / 2),
                                (15, 0), 30, player.color, player.name, 0.9999,
                                100)
    newImage = pg.transform.scale(player.image, (160, 160))

    while waitTime < 120:
        backgroundInputCheck(pg.event.get())

        bigTrail.update(player.color, player.name,
                        (4.5 * SCREEN_WIDTH / 10, SCREEN_HEIGHT / 2 + 40),
                        (15, 0), 100)
        longTrail.update(player.color, player.name,
                         (4.5 * SCREEN_WIDTH / 10, SCREEN_HEIGHT / 2), (20, 0),
                         100)

        screen.fill(BLACK)  #Paint the whole screen black
        bigTrail.drawParticles(screen)
        longTrail.drawParticles(screen)
        screen.blit(newImage, [SCREEN_WIDTH / 2 - 80, SCREEN_HEIGHT / 2 - 80])
        drawEyes(screen, waitTime, 60, 90, 0)

        waitTime += 1
        clock.tick(60)
        pg.display.flip()
Esempio n. 21
0
def creditsScreen():
    global SCREEN_WIDTH, SCREEN_HEIGHT, PLAYER, FPS, MODE, CONTROL, LAVA, WATER, POISON, ACID, GRID, PLAYER_CONTROLLED

    player = Element(0, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 0, LAVA,
                     "LAVA", ORANGE)
    newImage = pg.transform.scale(player.image, (160, 160))

    onCredits = True
    clearGrid(0)
    restTime = 0

    while restTime < 300 and onCredits:
        onCredits = backgroundInputCheck(pg.event.get())

        screen.fill(BLACK)  #Paint the whole screen black
        writeText(screen, "arial", 100, "Created by Jack Blair",
                  (SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2), WHITE)
        writeText(screen, "arial", 50, "Released April 2020",
                  (SCREEN_WIDTH / 2), (SCREEN_HEIGHT / 2) + 70, WHITE)
        screen.blit(newImage, [SCREEN_WIDTH / 2 - 80, SCREEN_HEIGHT / 2 - 230])
        drawEyes(screen, restTime, 60, 140, 150)

        restTime += 1
        clock.tick(60)
        pg.display.flip()
Esempio n. 22
0
def huffman(C):
    n = len(C)

    Q = C

    for i in range(n - 1):

        x = PQHeap.extractMin(Q)
        y = PQHeap.extractMin(Q)

        xExtractedKey = x.key
        xExtractedData = x.data

        yExtractedKey = y.key
        yExtractedData = y.data

        freq = xExtractedKey + yExtractedKey

        z = Element(int(freq), [xExtractedData, yExtractedData])


        PQHeap.insert(Q, z)


    return PQHeap.extractMin(Q)
Esempio n. 23
0
def parse_test_file(json_dir):
    test_list = []
    file = open(json_dir, "rb")
    tests = json.load(file)
    idx = 0
    cursor = 0
    for t in tests:
        cursor += 1
        mtype = t['event_type']
        # if idx == 0 and mtype == 'oracle':
        if mtype == 'oracle' and cursor != len(tests):
            continue
        if mtype == 'SYS_EVENT':
            test_list.append(t)
            idx += 1
            continue
        # if type != 'oracle':
        id = t['resource-id']
        sup = ':id/'
        tmp = id
        if len(id) > 0:
            tmp = id[id.index(sup) + len(sup):len(id)]
        id = tmp
        t['id'] = id
        text = t['text']
        act = t['activity']
        pwd = t['password']
        clickable = t['clickable']
        cls = t['class']
        desc = t['content-desc']
        e = Element(idx, id, cls, text, desc, 'false', 'false', clickable, 'false', 'false', 'false', pwd, mtype)
        test_list.append(t)
        idx += 1

    return test_list
def make_cubes(image):
    height = image.shape[0]
    width = image.shape[1]

    if width % 9 != 0:
        width -= (width % 9)

    if height % 6 != 0:
        height -= (height % 6)

    image = cv2.resize(image, (width, height))

    cube_width = width // 9
    cube_height = height // 6

    cubes = []
    colors = ['blue', 'red', 'yellow', 'orange', 'white', 'green']

    for i in range(6):
        for j in range(9):
            content = image[i * cube_width:(i + 1) * cube_width - 1,
                            j * cube_height:(j + 1) * cube_height - 1]
            cube = Element(colors[i], (i * 9) + j, content)
            cubes.append(cube)

    return cubes
Esempio n. 25
0
    def readMeshFile(self, path, filename):
        count = 1
        elementsList = []
        # ----------------------------
        # Read the existing elements file
        # ----------------------------
        f = os.path.join(path, filename)
        print f
        with open(f, "rt") as fin:
            for line in fin:
                values = [int(s) for s in line.split() if s.isdigit()]
                # elementNumber = re.search('/^[^\d]*(\d+)/', line)
                #print values

                l = len(values)

                # number, body, typeNumber, nodesindex
                newElement = Element(
                    values[0], values[1], values[1] / 10.0, values[2],
                    values[3:l]
                )  # number, body, densityDesignVar, typeNumber, nodesindex):
                newElement.numberNodes = l - 3  # record the number of nodes
                #print g.nodes
                elementsList.append(newElement)

                count += 1
        return elementsList
Esempio n. 26
0
def oracle_parser(oracle_json):
    # action format: 0:action_type,
    # 1:time,
    # 2:action_subject (id, text, xpath),
    # 3:action_subject_detail (id_name, text_str)
    oracle = {}
    id = oracle_json['resource-id']
    if len(id)>0:
        sup_idx = id.index(':id/')
        if sup_idx>0:
            id = id[sup_idx+4:len(id)]
    action = oracle_json['action']
    oracle['activity'] = oracle_json['activity']
    oracle['expect'] = action[3]
    oracle['class'] = oracle_json['class']
    oracle['text'] = oracle_json['text']
    oracle['desc'] = oracle_json['content-desc']
    oracle['action'] = action
    oracle['id'] = id
    if len(id) == 0 and action[2] != 'xpath':  # which means the oracle expects to see a non-element
        oracle['is_elem'] = 0
    else:
        oracle['is_elem'] = 1
        e = Element(0, id, oracle_json['class'], oracle_json['text'], oracle_json['content-desc'], 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false')
        oracle['element'] = e
    oracle['target'] = id if len(id) != 0 else action[2]
    return oracle
    def _validate_operators(self, line_num, i):

        #print("-- VALIDTE OPERATORS -- ")

        line = self._program_text.splitlines()[line_num]
        line_length = len(line)

        # take care with erros if undefined in line[i + 1]
        if (line[i] + line[i + 1] in [':=', '>=', '<=', '<>']):
            self._elements.append(
                Element(line[i] + line[i + 1], "Operators", line_num))
            i += 1
        elif (line[i] in self._operators):
            self._elements.append(Element(line[i], "Operators", line_num))
            #i += 1

        return i
Esempio n. 28
0
def writeHeader(identifier, number, text):
    if number < 1 or number > 6:
        raise ValueError('Invalid header number: ' + str(number) + '\n')

    f.write('\t<h' + str(number) + ' id="' + identifier + '">' + text + '</h' +
            str(number) + '>\n')
    elements.append(Element(identifier, 'header' + str(number), text))
    return
    def _validate_delimiters(self, line_num, i):

        #print("-- VALIDTE DELIMITERS -- ")

        line = self._program_text.splitlines()[line_num]
        line_length = len(line)

        if (i + 1 < line_length
                and (line[i] + line[i + 1] in self._delimiters)):
            self._elements.append(
                Element(line[i] + line[i + 1], "Delimiters", line_num))
            #i += 1
        elif (line[i] in self._delimiters):
            self._elements.append(Element(line[i], "Delimiters", line_num))
            #i += 1

        return i
Esempio n. 30
0
def writeHyperlink(identifier, link, text):
    if identifier is None:
        f.write('\t<a href="' + link + '";>' + text + '</a>\n')
    else:
        f.write('\t<a id="' + identifier + '" href="' + link + '";>' + text +
                '</a>\n')
        elements.append(Element(identifier, 'hyperlink', text))
    return