def setup_spinnman_interfaces(self): """Set up the interfaces for communicating with the SpiNNaker board """ self.dao.set_hostname(self.hostname) self.txrx = Transceiver(self.hostname) # Start local tubotron if requested if conf.config.getboolean("Visualiser", "enable"): self.wait_for_run = conf.config.getboolean("Visualiser", "pause_before_run") if self.wait_for_run: self.visualiser = Visualiser(self.dao, start_simulation_method=getattr( self, "run_now")) else: self.visualiser = Visualiser(self.dao) self.visualiser.set_port(self.visualiser_port) tubotron_port = conf.config.getint("Tubotron", "port") tubotron_tag = conf.config.getint("Tubotron", "tag") tubotron_host = conf.config.get("Tubotron", "hostname") self.set_tag_output(tubotron_tag, tubotron_port, tubotron_host) if conf.config.getboolean("Tubotron", "enable"): if tubotron_host == "localhost": self.tubotron = Tubotron(tubotron_port) if conf.config.has_option("Tubotron", "leaveRunning"): self.leaveTubotronRunning = conf.config.getboolean( "Tubotron", "leaveRunning")
def trigger_page(): """ Renders the trigger page. This page contains an instance of a TriggerForm. The TriggerForm contains input fields for the simulation. If the submit button is pressed, a simulation is triggered and the results are generated using the Visualiser class. If all succeeds, forward to endpoint "visualise" """ form = TriggerForm() # if the form is valid and the submit button was pressed if form.validate_on_submit(): # get the static path from the current application to store the visualisations static_path = os.path.join(current_app.root_path, current_app.static_folder) # clean up the previous simulation results Cleaner().remove_previous_simulation_results(static_path=static_path) # retrieve number of requests from the form number_of_requests = form.number_of_requests_field.data # Create an instance of the bounding box class, using the form data bounding_box = BoundingBox((form.x1_field.data, form.y1_field.data, form.x2_field.data, form.y2_field.data)) # Create an instance of the StaticDataReader class. static_data = StaticDataReader( berlin_bounds_file=current_app.config['BERLIN_BOUNDS_FILE'], berlin_stops_file=current_app.config['BERLIN_STOPS_FILE']) # Create an instance of the Simulator class. simulator = Simulator( bounding_box=bounding_box.bounding_box, path_to_stops=current_app.config['BERLIN_STOPS_FILE']) # Run a simulation simulation_results = simulator.simulate(number_of_requests) # Create an instance of the Visualiser class. visualiser = Visualiser(bounding_box=bounding_box, simulation_results=simulation_results, static_path=static_path, static_data=static_data) # Generate visualisations visualiser.generate_overview_figure() visualiser.generate_closeup_figure() visualiser.generate_gmap() # redirect to the visualise endpoint return redirect( url_for('routes.visualise', visualiser_id=visualiser.id)) # render a template for the trigger page. return render_template('trigger_page.html', title="MI Code Challenge", form=form)
def setUpClass(self): """ Sets up the class. The data only has to be read in once, so this is done in the class setup method. """ # TODO: Remove warn ngs filter when migrating to geopandas > 0.7.0 ! warnings.simplefilter('ignore', category=FutureWarning) warnings.simplefilter('ignore', category=DeprecationWarning) static_data = StaticDataReader('data/berlin_bounds.poly', 'data/berlin_stops.geojson') bounding_box_tuple = (13.34014892578125, 52.52791908000258, 13.506317138671875, 52.562995039558004) simulator = Simulator(bounding_box=bounding_box_tuple) simulation_results = simulator.simulate(number_of_requests=6) self.visualiser = Visualiser( bounding_box=BoundingBox(bounding_box_tuple), simulation_results=simulation_results, static_data=static_data, static_path='webapp/static')