def main(): """ Main function of the application. """ # Initialize the event manager. event_manager = events.EventManager() AppState.get_state().set_event_manager(event_manager) # Initialize and register the application heartbeat. heart_beat = HeartBeat() event_manager.register_listener(heart_beat) # Initialize and register the world. basic_experiment = experiment.basic.BasicExperiment() world = basic_experiment.get_world() event_manager.register_listener(world) AppState.get_state().set_world(world) # Initialize pygame. surface = init() # Initialize and register the view. main_view = view.View(surface) event_manager.register_listener(main_view) # Initialize and register the controller. main_controller = controller.Controller() event_manager.register_listener(main_controller) # Start the heartbeat. heart_beat.run()
def test_update_one_vehicle(self, mock_input, mock_positive_float): mock_input.return_value = 'Blue Car' mock_positive_float.return_value = 100 # re-import view here so when it imports other things, specfically the view_util # library, it will get the view_util library with the mock input_positive_float importlib.reload( view) # Re-import view to ensure it uses the mock imports # Make mock (fake, pretend) ViewModel with a mock insert method # We can make the mock here since it's not replacing any part of the # program code - it's a self-contained mock object. Use this to figure # out if the view calls the expected method with the correct data. mock_view_model = MagicMock() mock_view_model.increase_miles = MagicMock() # Give the new View the mock ViewModel test_view = view.View(mock_view_model) # The patched inputs will return 'Blue Car' and 100 so the expected vehicle is like this, vehicle = Vehicle('Blue Car', 100) # Call the method under test! test_view.update_one_vehicle() # And assert the mock is called with the correct vehicle. mock_view_model.increase_miles.assert_called_with(vehicle, 100)
def game(self): self.player = player.Player() # start view self.view = view.View() # online objects self.mq = zmq_client.ZmqConnector() self.broker = online_broker.OnlineBroker(self.player, self.mq) # start controller self.ctrl = controller.Controller(self.view, self.player, self.mq, self.broker) self.ctrl.load_external_resources(self.ctrl.view, os.path.join(os.getcwd(), '../resources')) self.ctrl.main_loop() pygame.quit() sys.exit()
def main(): """ Main function of the application. """ # Initialize the event manager. event_manager = events.EventManager() AppState.get_state().set_event_manager(event_manager) # Initialize and register the application heartbeat. heart_beat = HeartBeat() event_manager.register_listener(heart_beat) # Initialize and register the world. #experiment_ = experiment.experiment.Experiment.load_experiment("20161126T003019.p") experiment_ = experiment.basic.BasicVisionExperiment() AppState.get_state().set_experiment(experiment_) world = experiment_.get_world() event_manager.register_listener(world) AppState.get_state().set_world(world) # Initialize pygame. surface = init() # Initialize and register the view. main_view = view.View(surface) event_manager.register_listener(main_view) # Initialize the website trace history view. trace_view = agentevents.AgentEvents() event_manager.register_listener(trace_view) # Initialize and register the controller. main_controller = controller.Controller() event_manager.register_listener(main_controller) # Add the experiment controller to the controller main_controller.set_experiment_controller( lambda e, coords: experiment_.controller( e, main_view.window_coords_to_world_coords(coords))) # Start the webserver. webserver.trace_view = trace_view webserver.start() # Start the heartbeat. heart_beat.run()
def test_insert_one_vehicle(self, mock_input, mock_positive_float): """ Need to replace the ViewModel with a fake view model so the data is not sent to a real database. This test cares that the update_one_vehicle is calling the increase_miles method in the view_model with the right data. The two patch decorators: Replace the input_positive_float with a mock function that returns a pre-configured value. Otherwise the test will stop and wait for input. Update one vehicle also uses the builtin input function, so replace that with a mock too, again, returning a pre-configured value. Patching replaces the parts of the program with mocks just for the duration of this test. When this test is done (passes, fails, errors, whatever) the original methods/functions are restored. """ mock_input.return_value = 'Green Car' mock_positive_float.return_value = 3 # re-import view here so when it imports other things, specfically the view_util # library, it will get the view_util library with the mock input_positive_float importlib.reload(view) # Make mock (fake, pretend) ViewModel with a mock insert method # We can make the mock here since it's not replacing any part of the # program code - it's a self-contained mock object. Use this to figure # out if the view calls the expected method with the correct data. mock_view_model = MagicMock() mock_view_model.insert = MagicMock() # Give the new View the mock ViewModel test_view = view.View(mock_view_model) # The patched inputs will return 'Green Car' and 3 so the expected vehicle is like this, vehicle = Vehicle('Green Car', 3) # Call the method under test! test_view.get_one_new_vehicle() # And assert the mock is called with the correct vehicle. mock_view_model.insert.assert_called_with(vehicle)
def __init__(self): self.__view = view.View() self.__model = model.Model() self.__topline_templates = {} self.__topline_templates["Y2"] = os.path.join(template_folder, "topline_template.docx") self.__topline_templates["QUALTRICS"] = "" self.__topline_templates["UT_POLICY"] = os.path.join(template_folder, "utpolicy_top_template.docx") self.__appendix_templates = {} self.__appendix_templates["Y2"] = os.path.join(template_folder, "appendix_template.docx") self.__appendix_templates["QUALTRICS"] = "" self.__appendix_templates["UT_POLICY"] = os.path.join(template_folder, "utpolicy_app_template.docx") self.__template_logos = {} self.__template_logos["Y2"] = os.path.join(image_folder, "y2_xtabs.png") self.__template_logos["QUALTRICS"] = os.path.join(image_folder, "QLogo.png") self.__template_logos["UT_POLICY"] = os.path.join(image_folder, "y2_utpol_logo.png") self.__template_logos["WHATSAPP"] = os.path.join(image_folder, "whatsapp.png")
# -*- coding:utf-8 -*- from flask import Flask, request from model import model from view import view data_model = model.Model() view = view.View() app = Flask(__name__) @app.route('/', methods = ['GET']) def index(): ''' on charge un graphe dans un cas plus general il faudrait prendre en compte les donnees de formulaire (avec la methode POST) et calculer un (sous)graphe parmi toute une palette de possibilites ''' graph = data_model.load_graph() ''' on confie le graphe calcule a la vue qui sait traduire la donnee "brute" en un objet qui se prete au calcul de la vue cote client ''' view.graph2json(graph) ''' on envoie le resultat cote client
def __init__(self, *args, **kwargs): super(TestView, self).__init__(*args, **kwargs) pygame.init() self.test_view = view.View()
def run_experiment(experiment_, render = True, interactive = True, console_output = True, save_logs = True): """ Run an experiment until it halts. Simulates the world defined by the experiment and handles control events. :param experiment_: An object of type Experiment. :param render: A boolean indicating whether the simulation is to be rendered to the screen. :param interactive: A boolean indicating whether interactive is to be enabled. If interactive mode is on, rendering should be on as well. :param console_output: A boolean indicating whether simulation output is to be displayed in the console. :param save_logs: A boolean indicating whether simulation output is to be saved in a log file. """ if interactive: assert render, "render must be true if interactive mode is set" # Reset the app state AppState.get_state().reset() # Initialize the event manager. event_manager = events.EventManager() AppState.get_state().set_event_manager(event_manager) # Initialize and register the application heartbeat. heart_beat = HeartBeat() event_manager.register_listener(heart_beat) # Initialize and register the world. AppState.get_state().set_experiment(experiment_) world = experiment_.get_world() event_manager.register_listener(world) AppState.get_state().set_world(world) # Initialize pygame. surface = init() if render: # Initialize and register the view. main_view = view.View(surface) event_manager.register_listener(main_view) # Initialize the website trace history view. trace_view = agentevents.AgentEvents() event_manager.register_listener(trace_view) # Initialize and register the controller. main_controller = controller.Controller() event_manager.register_listener(main_controller) if interactive: # Add the experiment controller to the controller main_controller.set_experiment_controller(lambda e, coords: experiment_.controller(e, main_view.window_coords_to_world_coords(coords))) if console_output: # Enable console logger AppState.get_state().enable_console_logger() if save_logs: # Store experiment logs if not os.path.isdir(settings.RESULTS_DIR): os.makedirs(settings.RESULTS_DIR) file_path = os.path.join(settings.RESULTS_DIR, "%s - %s.log" % (strftime("%Y%m%dT%H%M%S"), experiment_.__class__.__name__)) AppState.get_state().enable_file_logger(file_path) # Start the webserver. webserver.register({'traces': trace_view}) webserver.start() # Start the heartbeat. heart_beat.run(slow = render, halt_fun = experiment_.halt, metrics_fun = experiment_.calculate_metrics) if len(heart_beat.metrics) > 0: # Store experiment results if not os.path.isdir(settings.RESULTS_DIR): os.makedirs(settings.RESULTS_DIR) file_path = os.path.join(settings.RESULTS_DIR, "%s - %s.json" % (strftime("%Y%m%dT%H%M%S"), experiment_.__class__.__name__)) with open(file_path, 'w') as f: json.dump(heart_beat.metrics, f, indent=4, sort_keys=True)
import pygame from model import dot, heap, wall from view import view from pygame.draw import * pygame.init() screen = pygame.display.set_mode((794, 1123)) surface = pygame.Surface((794, 1123)) view = view.View(screen) FPS = 30 WHITE = (255, 255, 255) dots = [ dot.Dot(400, 600, 10), dot.Dot(450, 450, 20), dot.Dot(550, 450, 30), dot.Dot(500, 550, 25) ] player = heap.Heap([], 500, 500, 30, 0.5, 0.8) wall = wall.Wall([dot.Dot(200, 600, 0), dot.Dot(300, 500, 0)]) clock = pygame.time.Clock() finished = False i = 0 while not finished: i += 1 clock.tick(FPS) player.step(0.00001 * FPS) rect(screen, WHITE, (0, 0, 794, 1123))