示例#1
0
 def other_date_century(year):
     """Return {{other_date|century}} for a given year."""
     # TODO add year[-2:] == u'00' and helpers.is_int(year) testing
     if not helpers.is_int(year) or int(year[-2:]) != 0:
         raise helpers.MyError(
             u'other_date_century() expects year in the format YY00 or Y00')
     return '{{other date|century|%d}}' % (int(year[:-2]) + 1)
示例#2
0
 def other_date_century(year):
     """Return {{other_date|century}} for a given year."""
     # TODO add year[-2:] == u'00' and helpers.is_int(year) testing
     if not helpers.is_int(year) or int(year[-2:]) != 0:
         raise helpers.MyError(
             u'other_date_century() expects year in the format YY00 or Y00')
     return '{{other date|century|%d}}' % (int(year[:-2]) + 1)
示例#3
0
def extractKuenstlerYear(name, bYear, dYear):
    """
    Checks for the presence of years at the end of a name,
    if found these are stripped after comparison to birth/death years.
    If birth/death years are not known then the found values are returned
    :param name: the string to test
    :param bYear: the known birth year
    :param dYear: the known death year
    :return: str, str, str, str
    """
    log = ''
    testYears = None
    testName = None
    if name.endswith(')'):
        test = name.split('(')[-1][:-1]
        if ',' in test:  # (title, YYYY-YYYY)
            parts = test.split(',')
            testYears = parts[-1].split('-')
            testName = '('.join(name.split('(')[:-1])
            testName += u'(%s)' % ','.join(parts[:-1])
        else:  # (YYYY-YYYY)
            testYears = test.split('-')
            testName = '('.join(name.split('(')[:-1])
    elif helpers.is_int(name[-len('YYYY'):]):  # YYYY-YYYY
        test = name[-len('YYYY-YYYY'):]
        testYears = test.split('-')
        testName = name[:-len('YYYY-YYYY')]

    # found potential matches
    if testYears:
        for i, e in enumerate(testYears):
            testYears[i] = e.strip('*+ ')  # (*YYYY-YYYY+)
        if len(testYears) == 2 and \
                all(not testY or helpers.is_int(testY)
                    for testY in testYears):
            # YYYY-YYYY
            if bYear and bYear != testYears[0]:
                log += u'bYear: %s,\t%s != %s\n' % (name, testYears[0], bYear)
            if dYear and dYear != testYears[1]:
                log += u'dYear: %s,\t%s != %s\n' % (name, testYears[1], dYear)
            if not log:
                name = testName.strip().rstrip(',')
                bYear = testYears[0]
                dYear = testYears[1]

    return name, bYear, dYear, log
示例#4
0
def extractKuenstlerYear(name, bYear, dYear):
    """
    Checks for the presence of years at the end of a name,
    if found these are stripped after comparison to birth/death years.
    If birth/death years are not known then the found values are returned
    :param name: the string to test
    :param bYear: the known birth year
    :param dYear: the known death year
    :return: str, str, str, str
    """
    log = ''
    testYears = None
    testName = None
    if name.endswith(')'):
        test = name.split('(')[-1][:-1]
        if ',' in test:  # (title, YYYY-YYYY)
            parts = test.split(',')
            testYears = parts[-1].split('-')
            testName = '('.join(name.split('(')[:-1])
            testName += u'(%s)' % ','.join(parts[:-1])
        else:  # (YYYY-YYYY)
            testYears = test.split('-')
            testName = '('.join(name.split('(')[:-1])
    elif helpers.is_int(name[-len('YYYY'):]):  # YYYY-YYYY
        test = name[-len('YYYY-YYYY'):]
        testYears = test.split('-')
        testName = name[:-len('YYYY-YYYY')]

    # found potential matches
    if testYears:
        for i, e in enumerate(testYears):
            testYears[i] = e.strip('*+ ')  # (*YYYY-YYYY+)
        if len(testYears) == 2 and \
                all(not testY or helpers.is_int(testY)
                    for testY in testYears):
            # YYYY-YYYY
            if bYear and bYear != testYears[0]:
                log += u'bYear: %s,\t%s != %s\n' % (name, testYears[0], bYear)
            if dYear and dYear != testYears[1]:
                log += u'dYear: %s,\t%s != %s\n' % (name, testYears[1], dYear)
            if not log:
                name = testName.strip().rstrip(',')
                bYear = testYears[0]
                dYear = testYears[1]

    return name, bYear, dYear, log
 def set_line_number(self):
     if is_int(self.current_token.value):
         self.text_line += 1
         self.current_line_number = int(self.current_token.value)
         self.get_next_token()
     else:
         raise Exception(
             f'Invalid line number "{self.current_token.value}" on line {self.text_line}.\n'
         )
    def DIM(self):
        self.get_next_token()

        if self.current_token.type != "identifier":
            raise Exception("Dimention must get an identifier.")
        id_name = self.current_token.value

        self.get_next_token()
        dims = []
        while self.current_token.type == "separator" and self.current_token.value == "[":
            self.get_next_token()
            if self.current_token.type == "literal" and is_int(
                    self.current_token.value):
                dims.append(int(self.current_token.value))
            else:
                raise Exception("Index must be integer.")
            self.get_next_token()
            if self.current_token.type != "separator" or self.current_token.value != "]":
                raise Exception("Must close brackets")
            self.get_next_token()

        variable_node = VariableNode(id_name,
                                     dims=dims,
                                     scope=self.scope_stack[-1])
        self.current_node.variable_list.append(variable_node)
        if self.current_token.type == "operator" and self.current_token.value == "=":
            self.get_next_token()
            current_dim = -1
            current_pos = [0 for dim in dims]
            while self.current_token.type != "separator" or self.current_token.value != "\n":
                if self.current_token.type == "separator" and self.current_token.value == "{":
                    current_dim += 1
                elif self.current_token.type == "separator" and self.current_token.value == "}":
                    current_pos[current_dim] = 0
                    current_dim -= 1
                elif self.current_token.type == "separator" and self.current_token.value == ",":
                    current_pos[current_dim] += 1
                elif self.current_token.type == "literal":
                    literal_node = LiteralNode(self.current_token.value)
                    assign_node = AssignNode()
                    assign_node.type = literal_node.type
                    variable_node.type = literal_node.type

                    temp_variable_node = variable_node.deepcopy()
                    assign_node.add_child(temp_variable_node)

                    for pos in current_pos:
                        temp_variable_node.add_child(LiteralNode(str(pos)))

                    assign_node.add_child(literal_node)
                    self.current_node.add_child(assign_node)

                self.get_next_token()
示例#7
0
def function_options(fun, op):
    if op == '1':
        '''1.  𝑓(𝑥) = 𝑥 + 1'''
        x = ''
        while not is_int(x):
            print("\n1.  𝑓(𝑥) = 𝑥 + 1")
            x = input("\nx = ")

        print("\nResutaldo: " + str(fun(f, int(x))))
        return False
    elif op == '2':
        '''2.  𝑔(𝑥)=2𝑥'''
        x = ''
        while not is_int(x):
            print("\n2.  𝑔(𝑥)=2𝑥")
            x = input("\nx = ")
        print('\nResultado ' + str(fun(g, int(x))))
        return False
    else:
        print("\nERROR: Ingrese una opcion valida.\n")
        return True
    def GOTO(self):
        goto_node = GoToNode()
        goto_node.line_number = self.current_line_number
        self.current_node.add_child(goto_node)

        self.get_next_token()
        if self.current_token.type == "literal" and is_int(
                self.current_token.value):
            goto_node.add_child(LiteralNode(self.current_token.value))
            self.get_next_token()
        else:
            raise Exception(
                f"GOTO command must have an integer as argument. Received {self.current_token.value}"
            )
示例#9
0
 def select_few(self, ticket_type, count):
     try:
         if helpers.is_int(count) and int(count) >= 0:
             self.deselect_all(ticket_type)
             tics = self.machineTicket.get_ticket_type(ticket_type)
             if (len(tics) == 0
                     and len(tics) != int(count)) or int(count) > len(tics):
                 raise Exception(
                     "Cannot select more of this type of tickets")
             else:
                 for i in range(int(count)):
                     selected = tics.pop()
                     self.selected_tickets.add(selected)
                     self.machineTicket.remove(selected)
         else:
             raise Exception("Value must be positive integer")
     except Exception:
         raise
示例#10
0
def handle_arguments():
    '''Handles arguments passed on by the user to the program,
  if no arguments are passed, it opens the default video capture source from the machine,
  if an int argument is passed, it opens that specific video capture source,
  if a string argument is passed, and it ends with ".mp4", ".jpg" or ".png", it opens the file passed
  '''

    if len(sys.argv) == 1:
        label_video(0)
    elif len(sys.argv) == 2:
        if is_int(sys.argv[1]):
            label_video(int(sys.argv[1]))
        else:
            if not os.path.exists(sys.argv[1]):
                print('File not found.')
                return
            if sys.argv[1].endswith('.mp4'):
                label_video(sys.argv[1])
            elif sys.argv[1].endswith('.jpg') or sys.argv[1].endswith('.png'):
                label_image(sys.argv[1])
示例#11
0
def compute_cell_value(value, col, row):
    if (value is None or value == ""):
        return None
    if not value.startswith("="):
        return int(value)

    cells = value[1:].split("+")
    sum = 0
    raise_when_finished = False
    for cell_id in cells:
        if is_int(cell_id):
            sum += int(cell_id)
        else:
            cell_id = to_tuple(cell_id)

            # check if cell is referring itself
            if cell_id == (col, row):
                raise RefError()
            cell = CellModel.query.get(cell_id)

            # add dependency if it doesn't exist already
            dependency = CellDependenciesModel.query.get(
                (cell.col, cell.row, col, row))
            if dependency is None:
                dependency = CellDependenciesModel(dependee_col=cell.col,
                                                   dependee_row=cell.row,
                                                   dependent_col=col,
                                                   dependent_row=row)
                db.session.add(dependency)
                db.session.commit()  #check if it can go out of the loop

            # mask the ref error and throw it when all deps have been added
            if cell.has_ref_error:
                raise_when_finished = True
            else:
                sum += default_to_zero(cell.computed)

    if raise_when_finished:
        raise RefError()
    return sum
 def is_int(s):
     """
     Deprecated in favour of helpers.listify
     """
     print 'call to deprecated KulturnavBot.is_int()'
     return helpers.is_int(s)
示例#13
0
def main():
    '''Main'''
    wants_to_continue = True

    while wants_to_continue:

        print(menu())

        op = input('\nIngrese una opcion: ')

        if op == '1':
            '''1.  𝑓(𝑥) = 𝑥 + 1'''
            x = ''
            while not is_int(x):
                screen_clear_2()
                print("\n\t\tProyecto 1")
                print("\n1.  𝑓(𝑥) = 𝑥 + 1")
                x = input("\nx = ")
            print('\n𝑓(𝑥) = ' + str(f(int(x))))
            screen_clear_1()
        elif op == '2':
            '''2.  𝑔(𝑥)=2𝑥'''
            x = ''
            while not is_int(x):
                screen_clear_2()
                print("\n\t\tProyecto 1")
                print("\n2.  𝑔(𝑥)=2𝑥")
                x = input("\nx = ")
            print('\ng(𝑥) = ' + str(g(int(x))))
            screen_clear_1()
        elif op == '3':
            '''3.  ℎ(𝑥,𝑦)=𝑥^2+𝑦^2'''
            x = ''
            y = ''
            while not is_int(x) and not is_int(y) and not x == '' or y == '':
                screen_clear_2()
                print("\n\t\tProyecto 1")
                print("\n3.  ℎ(𝑥,𝑦)=𝑥^2+𝑦^2")
                x = input("\nx = ")
                y = input("\ny = ")
            print('\nh(𝑥, y) = ' + str(h(int(x), int(y))))
            screen_clear_1()
        elif op == '4':
            '''4.  𝑐𝑒𝑟𝑜(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑥'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n4.  𝑐𝑒𝑟𝑜(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑥")
            print("\nResultado: " + str(funcion(cero)))

            screen_clear_1()
        elif op == '5':
            '''5.  𝑢𝑛𝑜(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑓𝑥'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n5.  𝑢𝑛𝑜(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑓𝑥")
            print("\nResultado: " + str(funcion(uno)))

            screen_clear_1()
        elif op == '6':
            '''6.  𝑑𝑜𝑠(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑓𝑓𝑥'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n6.  𝑑𝑜𝑠(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑓𝑓𝑥")
            print("\nResultado: " + str(funcion(dos)))

            screen_clear_1()
        elif op == '7':
            '''7.  𝑡𝑟𝑒𝑠(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑓𝑓𝑓𝑥'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n7.  𝑡𝑟𝑒𝑠(𝑓,𝑥)=𝜆𝑓.𝜆𝑥.𝑓𝑓𝑓𝑥")
            print("\nResultado: " + str(funcion(tres)))

            screen_clear_1()
        elif op == '8':
            '''8.  𝑠𝑢𝑐𝑒𝑠𝑜𝑟(𝑛,𝑓,𝑥)=𝜆𝑛.𝜆𝑓.𝜆𝑥(𝑓(𝑛𝑓(𝑥)))'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n8.  𝑠𝑢𝑐𝑒𝑠𝑜𝑟(𝑛,𝑓,𝑥)=𝜆𝑛.𝜆𝑓.𝜆𝑥(𝑓(𝑛𝑓(𝑥)))")

            fn = f
            n = cero_1

            x = ''
            while not is_int(x):
                x = input("\nx = ")

            print("\nResultado: " + str(sucesor(fn, n, int(x))))

            screen_clear_1()
        elif op == '9':
            '''9.  𝑠𝑢𝑚𝑎(𝑎,𝑏,𝑓,𝑥)'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n9.  𝑠𝑢𝑚𝑎(𝑎,𝑏,𝑓,𝑥)")

            a = 'a'
            b = 'b'

            a = choose_lambda_fun(a)
            b = choose_lambda_fun(b)

            print("\nResultado: ", funcion(suma(a)(b)))

            screen_clear_1()
        elif op == '10':
            '''10. 𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑐𝑎𝑐𝑖ó𝑛(𝑎,𝑏,𝑓,𝑥)'''

            screen_clear_2()
            print("\n\t\tProyecto 1")
            print("\n10. 𝑚𝑢𝑙𝑡𝑖𝑝𝑙𝑖𝑐𝑎𝑐𝑖ó𝑛(𝑎,𝑏,𝑓,𝑥)")

            a = 'a'
            b = 'b'

            a = choose_lambda_fun(a)
            b = choose_lambda_fun(b)

            print("\nResultado: ", funcion(multiplicacion(a)(b)))

            screen_clear_1()
        elif op == '11':
            wants_to_continue = False
            screen_clear_1()
        else:
            print("\nERROR: Ingrese una opcion valida.\n")
            screen_clear_1()