Example #1
0
    def train(self, corpus, learningRate, thread=None):
        """ Trains this network using gradient descent.

        :param corpus:
        :param learningRate: Learning rate (alpha parameter) used for training.
        :param thread: (Optional) Number of thread to use for training neurons.
        """
        if not exists(self.directory):
            raise IOError('Directory %s not found, abort' % self.directory)
        trainer = NeuronTrainer(corpus, self.size, self.window, learningRate)
        Controller.run(trainer, self.neurons, thread)
Example #2
0
 def _test_controller_addStudent(self):
     '''
     Tests if adding a student to the repository works
     '''
     repository = Repository()
     controller = Controller(repository)
     
     try:
         Controller.addStudent(controller, ["John"])
         assert True
     except:
         assert False
                 
     try:
         Controller.addStudent(controller, ["John John"])
         assert True
     except:
         assert False
     
     try:
         Controller.addStudent(controller, [5])
         assert False
     except ValueError:
         assert True
     
     try:
         Controller.addStudent(controller, [])
         assert False
     except ValueError:
         assert True        
Example #3
0
 def mainMenu(self):
     '''
     This is where the user interacts with the rest of the program
     '''
     while 1:            
         try:
             Controller.setCommand(self._controller, input("Write a command (type help for a list): "))
         except ValueError:
             print("Invalid command parameter!")
             
         try:
             Controller.checkCommand(self._controller)
         except CommandNotFound:
             print ("Command not found!")
         except SystemExit:
             print ("Exiting program...")
             return True
Example #4
0
    def generate_output_file(self, input_image_file, input_video_file, output_file):
        try:
            controller = Controller()
            controller.add_observer(self)
            controller.generate_output_file(input_image_file, input_video_file, output_file)
            print "\nFile successfully created"

        except EmptyImageFileInputError:
            print "You didn't specified an input image file"

        except EmptyVideoFileInputError:
            print "You didn't specified an input video file."

        except EmptyFileOutputError:
            print "You didn't specified an output file."

        except:
            print "An unexpected error occurred. File could not be created."
Example #5
0
File: main.py Project: bjwt/leopard
def main():
    """
    KoP entry point
    """
    # create the viewer
    # TODO: create a factory for viewer
    viewer = NewtViewer()

    # create the model
    model = Model()

    # create the controller
    cont = Controller(model, viewer)

    cont.loop()

    # close the viewer
    viewer.destructor()
Example #6
0
 def _test_controller_addDiscipline(self):
     '''
     Tests if adding a discipline works
     '''
     repository = Repository()
     controller = Controller(repository)
     
     try:
         Controller.addDiscipline(controller, ["FP"])
         assert True
     except Debug:
         assert True
     except:
         assert False
     
     try:
         Controller.addDiscipline(controller, ["FP"])
         assert False
     except DuplicateDisciplineError:
         assert True
         
     try:
         Controller.addDiscipline(controller, [])
         assert False
     except ValueError:
         assert True
         
     try:
         Controller.addDiscipline(controller, [2])
         assert False
     except ValueError:
         assert True
         
     try:
         Controller.addDiscipline(controller, ["ASC"])
         assert True
     except:
         assert False
Example #7
0
 def _test_controller_isDuplicate(self):
     '''
     Tests if finding a duplicate in the repository works
     '''
     repository = Repository()
     controller = Controller(repository)
     Repository.push(repository, Student("john", 1))
     Repository.push(repository, "Test QA")
     
     assert Controller.isDuplicate(controller, 1, "studentID") == 0
     assert Controller.isDuplicate(controller, 2, "studentID") == -1
     assert Controller.isDuplicate(controller, "Test QA", "discipline") == 1
     assert Controller.isDuplicate(controller, "Tester QA", "discipline") == -1
     assert Controller.isDuplicate(controller, 1, "???") == -1
     assert Controller.isDuplicate(controller, "78", "studentID") == -1
Example #8
0
from time import sleep


def put_timer_event():
    while continue_timer:
        sleep(.7)
        timer_event = TimerEvent()
        event_queue.put(timer_event)


global continue_timer
continue_timer = True

event_queue = Queue()
model = Model()

view = View(event_queue)
view.start()

controller = Controller(event_queue, view, model)
controller.start()

cycle_timer = Thread(target=put_timer_event)
cycle_timer.start()

view.join()
controller.join()
continue_timer = False
cycle_timer.join()

Example #9
0
 def _test_controller_setCommand(self):
     '''
     Tests if setCommand works accordingly
     '''
     
     controller = Controller("debug")
     
     controller.setCommand("add, 123")
     assert Controller.getCommand(controller) == ["add", ",", "123"]
     
     controller.setCommand(",,,")
     assert Controller.getCommand(controller) == [",", ",", ","]
     
     controller.setCommand("add 123")
     assert Controller.getCommand(controller) == ["add", "123"]
     
     controller.setCommand("yes")
     assert Controller.getCommand(controller) == ["yes"]
     
     controller.setCommand("")
     assert Controller.getCommand(controller) == []
Example #10
0
 def _test_controller_addGrade(self):
     '''
     Tests if adding a grade to the repository works
     '''
     repository = Repository()
     controller = Controller(repository)
     
     try:
         Controller.addGrade(controller, ["FP", ",", "1", ",", "5.5", ",", "Arthur"])
         assert False
     except DuplicateDisciplineError:
         assert True
     Controller.addDiscipline(controller, ["FP"])
     
     try:
         Controller.addGrade(controller, ["FP", ",", "1", ",", "5.5", ",", "Arthur"])
         assert False
     except DuplicateIDError:
         assert True
     Controller.addStudent(controller, ["John"])
     
     try:
         Controller.addGrade(controller, ["FP", ",", "1", ",", "5.5", ",", "Arthur"])
         assert True
     except:
         assert False
    
     try:
         Controller.addGrade(controller, [])
         assert False
     except ValueError:
         assert True
     
     try:
         Controller.addGrade(controller, [2])
         assert False
     except ValueError:
         assert True
     
     try:
         Controller.addGrade(controller, ["FP", ",", "1", ",", "9.5", ",", "Arthur Molnar"])
         assert True
     except:
         assert False
Example #11
0
def main():
    controller = Controller()
    controller.run()
Example #12
0
import logging
log = logging.getLogger(__name__)


from model.root import Root
from view.view import View
from controller.controller import Controller

from lib.portrait import FremantleRotation

root = Root()
root.build_data()

controller = Controller(root)
view = View(root, controller)

controller.view = view


rotation_object = FremantleRotation('SmsNostalgia', 
                                    main_window=view.window_main.window, 
                                    version='1.0', 
                                    mode=FremantleRotation.AUTOMATIC)


view.start()
Example #13
0
def main():
    logging.info('Running MLO')

    parser = argparse.ArgumentParser()
    parser.add_argument('-f', help='fitness script, use fitnessTemplate.py')
    parser.add_argument('-c', help='config script, use test_configuration.py')
    parser.add_argument('--gui', help='enable the GUI',
                        action='store_true')
    parser.add_argument('--restart', help='restart after crash (in the terminal mode)',
                        action='store_true')
    args = parser.parse_args()

    if not (args.gui or args.f or args.c or args.restart):
        print 'Either run the program with --gui or provide a fitness and ' \
              'configuration scripts (with -f and -c)'
        sys.exit(1)
    gui = args.gui
    restart = args.restart
    fitness = None
    configuration = None

    if not gui and not restart and (not args.f or not args.c):
        print 'Make sure to provide both the fitness and configuration scripts or restart flag'
        sys.exit(1)    
    
    ## start in gui mode
    if gui:
        ## initialize controller
        restart = True
        controller = Controller(restart)
        logging.info('Will run with GUI')
        controller.view = GUIView()
    ## start in terminal mode
    else:
        ## initialize controller, restart runs only if requested
        controller = Controller(restart)
        controller.view = TerminalView()
        
        if restart:
            logging.info('Will restart most recent run, for other runs run in GUI mode..')
            fit = self.controller.get_most_recent_fitness_script_folder() + "/" + self.controller.get_most_recent_fitness_script_file() 
            config = self.controller.get_most_recent_configuration_script_folder() + "/" + self.controller.get_most_recent_configuration_script_file() 
        else:
            fit = args.f
            config = args.c
            
        # Load the fitness script
        controller.fitness = load_script(fit, 'fitness')
        if controller.fitness is None:
            logging.info('Could not load fitness file')
            sys.exit(1)

        # Load the configuration script
        controller.configuration = load_script(config, 'configuration')
        if controller.configuration is None:
            logging.info('Could not load configuration file')
            sys.exit(1)
            
    controller.take_over_control()

    logging.info('MLO finished successfully')
    sys.exit(0)
Example #14
0
from controller.controller import Controller

c = Controller(100, 4)
res = c.hillClimb(4, 100)
print(res)
Example #15
0
from controller.controller import Controller

c = Controller()
c.start() 
    
Example #16
0
#        print('este contacto existe')
#        ne=False
#        break
#if ne:
#    print('este contacto no existe')
"""
m=Model()
m.agregar_contactos(1,'Fernando Salinas', '419-100-1138','*****@*****.**','Dr. Mora, Gto')
m.agregar_contactos(2,'Juan Perez', '423-990-9876','*****@*****.**','Salamanca, Gto')
m.agregar_contactos(3,'Pedro Hernandez', '8787-132-9777','*****@*****.**','Guanajuato, Gto')

s=m.leer_todos_contactos()

for c in s:
    print(c.nombre)

n=Model()
n.agregar_cita(1,1, 'Jardin Princial', '18-02-2020', '15:30', 'Sin Asunto')

r=n.leer_cita(1)
print(r.lugar)



s=m.leer_todos_contactos()
for c in s:
    print(c.nombre)
"""
cont = Controller()
cont.start()
Example #17
0
from controller.controller import Controller

print(
    "Skriv inn hvilke maskiner du vil få varsel om når de er ferdig, skill med komma"
)
print("Eksempel: 1,7,4,3")
machines = input("Maskiner: ")
machines = machines.split(",")
for machine in machines:
    machine = int(machine)
print("Hvor mange minutter mellom hver sjekk? (min: 1)")
interval = int(input("Minutter: "))
controller = Controller(machines, int(interval))
controller.start()
"""
@Name: main.py
@Author: lxy
@Date: 2019/5/10 10:38
@Description: 主函数, 请从此启动客户端
@Contact: [email protected]
"""
import sys

from controller.controller import Controller

if __name__ == '__main__':
    controller = Controller()
    sys.exit(controller.app.exec_())
Example #19
0
 def build(self):
     return Controller()
Example #20
0
 def _test_controller_checkCommand(self):
     '''
     Tests if all command are found
     '''
     
     controller = Controller("debug")
     
     try:
         controller.setCommand("yus")
         Controller.checkCommand(controller, 1)
         assert False
     except CommandNotFound:
         assert True
         
     try:
         controller.setCommand("exit")
         Controller.checkCommand(controller, 1)
         assert False
     except Debug:
         assert True
     except:
         assert False
     
     try:   
         controller.setCommand("help")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
     
     try:
         controller.setCommand("print students")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
     
     try:
         controller.setCommand("print grades")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
     
     try:
         controller.setCommand("print disciplines")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
     
     try:
         controller.setCommand("print all")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
         
     try:
         controller.setCommand("add discipline fp")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
         
     try:
         controller.setCommand("add student John")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         assert False
         
     try:
         controller.setCommand("add grade fp, 1, 7.5, Arthur")
         Controller.checkCommand(controller, 1)
     except Debug:
         assert True
     except:
         False
Example #21
0
 def __init__(self, **kwargs):
     Controller.__init__(self ,**kwargs)
     self.bot = Controller().bot_controller()
     self.updaters()