예제 #1
0
def filter(ls, args, **kwargs):
    Validators.filter(ls, args)
    if len(args) == 1:
        Commands.filter_real(ls, **kwargs)
    if len(args) == 3:
        ops = {"=": float.__eq__, "<": float.__lt__, ">": float.__gt__}
        Commands.filter_modulo(ls, ops[args[1]], float(args[2]), **kwargs)
예제 #2
0
def init(seq_len: int, language, is_sorted: bool) -> MemoryChallenger:
    Validators.validate_seq_len(seq_len)
    const_language = Validators.validate_format_language(language)

    read_engine = pyttsx3.init()
    read_rate = read_engine.getProperty('rate')
    read_engine.setProperty('rate', read_rate - 50)
    mem_challenger = MemoryChallenger(seq_len, const_language, read_engine, is_sorted)
    return mem_challenger
    def __init__(self, seq_len: int, language, read_engine: pyttsx3,
                 is_sorted: bool):
        Validators.validate_seq_len(seq_len)
        if type(language) is not Const.LANGUAGE:
            Validators.validate_format_language(language)

        self.language: Const.LANGUAGE = language
        self.seq_len: int = seq_len
        self.is_sorted: bool = is_sorted
        self.sequence: str = ""
        self.read_engine: pyttsx3.Engine = read_engine
예제 #4
0
def lists(ls, args, **kwargs):
    Validators.lists(ls, args)
    if len(args) == 0:
        show = Commands.lists(ls)
    if len(args) == 4:
        show = Commands.list_real_range(ls, int(args[1]), int(args[3]))
    if len(args) == 3:
        ops = {"=": float.__eq__, "<": float.__lt__, ">": float.__gt__}
        show = Commands.list_modulo(ls, ops[args[1]], float(args[2]))

    show = ", ".join([ComplexNumber.format(i) for i in show])
    print(show if show != "" else "No results")
예제 #5
0
def select_friend():
    item_position = 1
    if len(friends):
        for i in friends:
            print '%d %s %s aged %d with rating %.1f'%(item_position,i.salutation,i.name,i.age,i.rating)
            item_position = item_position+1
        choice = validators.get_int("Enter your choice",1,len(friends)+1)
        return choice-1

    else:
        print 'You dont have any friends'
    return None
예제 #6
0
def add_friend(spy):
    Users.show_user_details()
    index = spy.id
    while index == spy.id:
        index = validators.get_int("\nSelect user to add as friend ",1,len(user_list)+1)
        if index == spy.id:
            print 'You cant add yourself as friend'
        for friend in friends:
            if index == friend.id:
                print 'Friend Already Added'
                index = spy.id
    friend = Friend(user_id = index)
    friend.save(spy)
    friends.append(user_list[index-1])
    print 'Friend Added successfully'
    return len(friends)
예제 #7
0
    def change_status(self):
        updated_status_message = self.current_status_message
        if self.current_status_message is not None:
            print "Your current status message is " + self.current_status_message + "\n"
        else:
            print 'You don\'t have any status message currently \n'

        default = raw_input(
            "Do you want to select from the older status (y/n)?")

        if default.upper() == "N":
            new_status_message = raw_input(
                "What status message do you want to set?")

            if len(new_status_message) > 0:
                updated_status_message = new_status_message
                STATUS_MESSAGES.append(updated_status_message)

        elif default.upper() == 'Y':
            item_position = 1
            for message in STATUS_MESSAGES:
                print str(item_position) + ". " + message
                item_position = item_position + 1
            message_selection = validator.get_int(
                "\nChoose from the above messages ", 1,
                len(STATUS_MESSAGES) + 1)
            updated_status_message = STATUS_MESSAGES[message_selection - 1]

        if updated_status_message != self.current_status_message:
            self.current_status_message = updated_status_message
            try:
                conn.execute(
                    "UPDATE USERS set CURRENT_STATUS_MESSAGE = ? where USERS.username is ?",
                    (self.current_status_message, self.username))
                conn.commit
            except:
                print 'Couldn\'t save changes in the database'

        print 'Status Update successful'
        print 'Updated to ' + updated_status_message

        return updated_status_message
예제 #8
0
def send_message(spy):
      friend_choice = select_friend()
      valid_set = ['T','I']
      text = raw_input("Please Enter your Message")
      choice = validators.get_alpha('Want to send message as text or hide it in image?(T for text/I for Image) ',1,2,valid_set)
      if choice == 'I':
          try:
              original_image = raw_input("What is the name of the image?")
              output_path = 'output.jpg'
              try:
                Steganography.encode(original_image, output_path, text)
              except IOError:
                  print 'File doesnt exist'
          except:
              print 'Operation Unsuccessful'
              return 0

      new_chat = ChatMessage(spy_id=spy.id, friend_id=friends[friend_choice].id,message=text,time= datetime.now().strftime("%b %d %Y %H:%M"))
      new_chat.save()
      friends[friend_choice].chats.append(new_chat)
      print "Your secret message is ready!"
예제 #9
0
def parse_command(user_command: str, mem_challenger: MemoryChallenger) -> Const.STATUS:
    new_length = Validators.validate_format_regex_length(Const.COMMAND.CHANGE_LENGTH.value, user_command)
    if new_length is not None:
        mem_challenger.set_seq_length(new_length)
    else:
        try:
            user_command_enum = Const.COMMAND(user_command)
        except ValueError:
            print(admin_message(f"The command {user_command} is unknown. Please try to use one of the following"
                                f" commands: {Const.LIST_COMMANDS}"))
            return Const.STATUS.UNDEFINED_ACTION

        if user_command_enum in Const.QUIT_COMMANDS_LIST:
            return Const.STATUS.QUIT
        elif user_command_enum in Const.NEXT_COMMANDS_LIST:
            return Const.STATUS.NEXT
        elif user_command_enum == Const.COMMAND.CHANGE_LANGUAGE:
            mem_challenger.change_language()
        elif user_command_enum == Const.COMMAND.CHANGE_SORTED:
            mem_challenger.change_sorted()

    print(admin_message(f"The command '{user_command}' was executed."))
    return Const.STATUS.DONE_ACTION
예제 #10
0
def product(ls, args, **kwargs):
    Validators.product(ls, args)
    p = Commands.product(ls, int(args[0]), int(args[2]))
    print(ComplexNumber.format(p))
예제 #11
0
 def set_seq_length(self, new_seq_len: int) -> None:
     Validators.validate_seq_len(new_seq_len)
     self.seq_len = new_seq_len
예제 #12
0
def remove(ls, args, **kwargs):
    Validators.remove(ls, args)
    if len(args) == 1:
        Commands.remove(ls, int(args[0]), int(args[0]), **kwargs)
    else:
        Commands.remove(ls, int(args[0]), int(args[2]), **kwargs)
예제 #13
0
def add(ls, args, **kwargs):
    Validators.add(args)
    Commands.add(ls, ComplexNumber.create(args[0]), **kwargs)
예제 #14
0
파일: ICG.py 프로젝트: edgary777/frontDesk
    def credentialsPrompt(self, password):
        """Prompt for root credentials to create new admin user."""
        if self.password.text() == "" or self.passwordV.text() == "":
            # Verify no field is empty.
            self.message.setText("Por favor rellena todos los campos.")
            print("Empty Field")
            return

        if self.username.text() == "" or self.email.text() == "":
            # Verify no field is empty.
            self.message.setText("Por favor rellena todos los campos.")
            print("Empty Field")
            return

        if self.lastName.text() == "" or self.name.text() == "":
            # Verify no field is empty.
            self.message.setText("Por favor rellena todos los campos.")
            print("Empty Field")
            return

        if len(self.username.text()) < 4:
            # username must be at least 4 characters long.
            self.message.setText(
                "El nombre de usuario debe tener 4 caracteres como minimo.")
            print("Username is too short")
            return

        if not isinstance(self.username.text(), str):
            # Username can't be only numbers.
            self.message.setText("El nombre de usuario no puede ser un número.")

        if len(self.name.text()) < 2:
            # name must be at least 2 characters long.
            self.message.setText(
                "Tu nombre no puede tener menos de 2 caracteres.")
            print("Name is too short")
            return

        if len(self.lastName.text()) < 2:
            # last name must be at least 2 characters long.
            self.message.setText(
                "Tu apellido no puede tener menos de 2 caracteres.")
            print("lastName is too short")
            return

        for character in self.username.text():
            if character == " ":
                print("No spaces allowed in username")
                self.message.setText(
                    "No se pueden usar espacios en el nombre de usuario.")
                return

        if len(self.password.text()) < 6:
            # Password must be at least 6 characters long.
            self.message.setText(
                "La contraseña debe tener 6 caracteres como minimo.")
            print("password is too short")
            return

        if self.password.text() != self.passwordV.text():
            # Verify password and passwordV are exactly the same.
            self.message.setText("Las contraseñas no coinciden.")
            print("passwords are not the same.")
            return

        if Validators.validateEmail(self.email.text()) is False:
            # Verify email is valid.
            self.message.setText("El E-mail introducido no es valido.")
            print("Non Valid Email.")
            return

        if self.db.verifyUser(self.username.text(), self.mainW.cursor) is True:
            # Username was already registered.
            self.message.setText("Nombre de usuario no disponible.")
            print("Username already exists.")
            return

        # If all those tests were passed, now we prompt for a root user permission.

        dialog = Dialogs.CredentialsPromptD(self, self.userData, 0, self.mainW.cursor)

        if dialog.exec_() == QDialog.Accepted:
            self.registerUser()
예제 #15
0
import BayesianNetwork as bn
import ErrorMeasurements as em
import Validators as val

#List with most common words that appears aproximately equals in positive and negative tweets (noise)
mostCommonWords = ['i', 'to', 'the', 'you', 'and', 'a', 'on', 'is', 'it', 'in', 'for', 'me', 'that', 'with', 'of', 'my']
if __name__ == "__main__":
	print "Starting..."
	dataFrame = bn.readDatabase(shuffle=True)
	#data,_ = dt.splitDataInProportion(dataBase=dataFrame, trainPercent=0.33)
	#val.CrossValidationMedian(executions=10,trainPercent=0.66, parseDates=False, smooth=0)
	print em.printAllParams(val.haveKFoldValidation(data=dataFrame, k=5, smooth=0))
	print em.getF1Score(val.leaveOneOutValidation(data = dataFrame, smooth=0, filter=[]),positiveClass=0)
	print em.getF1Score(val.leaveOneOutValidation(data=dataFrame, smooth=1, filter=[]), positiveClass=0)
예제 #16
0
def undo(ls, args, **kwargs):
    Validators.undo(ls, args, kwargs["undo"])
    if len(args) != 0:
        raise Exception("Invalid syntax!")

    Commands.undo(ls, kwargs["undo"])
예제 #17
0
def get_name():
    try:
        return validators.get_alpha("Please enter your name to continue ",3)
    except:
        print 'There was some error while processing your request. Please Try Again'
    return get_name()
예제 #18
0
def insert(ls, args, **kwargs):
    Validators.insert(ls, args)
    Commands.insert(ls, ComplexNumber.create(args[0]), int(args[2]), **kwargs)
예제 #19
0
def get_age():
    try:
       return validators.get_int("Please Enter your age ",12,50)
    except:
        print 'There was some error whiile processing your request. Please Try Again'
    return get_age()
예제 #20
0
def replace(ls, args, **kwargs):
    Validators.replace(ls, args)
    old = ComplexNumber.create(args[0])
    new = ComplexNumber.create(args[2])
    Commands.replace(ls, old, new, **kwargs)
예제 #21
0
def get_salutation():
    try:
        return validators.get_alpha("Please Enter your Salutation",2,5).title()
    except:
        print 'There was some error whiile processing your request. Please Try Again'
    return get_salutation()
예제 #22
0
def sums(ls, args, **kwargs):
    Validators.sums(ls, args)
    s = Commands.sums(ls, int(args[0]), int(args[2]))
    print(ComplexNumber.format(s))
예제 #23
0
def get_rating():
    try:
        return validators.get_float("Please Enter a valid rating ",1.0,10.0)
    except:
        print 'There was some error whiile processing your request. Please Try Again'
    return get_rating()