def simulation_status(request): output_settings = OutputSettings.objects.get() status = { 'is_simulation_stopped': is_simulation_stopped(), 'simulation_has_started': SmSession.objects.get().simulation_has_started, 'iterations_total': output_settings.iterations, 'iterations_started': len(list_of_iterations()), 'iterations_completed': iterations_complete(), 'iteration_text': mark_safe(SmSession.objects.get().iteration_text), } return JsonResponse(status)
def population_zoom_png(request=None): path = workspace_path(scenario_filename() + '/population_map.png') thumb_path = workspace_path(scenario_filename() + '/population_thumbnail.png') try: with open(path, "rb") as img_file: return HttpResponse(img_file.read(), content_type='image/png') except IOError: save_image = is_simulation_stopped() # we want to check this before reading the stats, this is in motion if not save_image: # in order to avoid database locked Issue #150 return population_png(request, 58.5, 52) else: if any(thread.name == 'population_map_thread' for thread in threading.enumerate()): print("Waiting on a Population Map") sleep(5) else: PopulationWorker(path, thumb_path).start() sleep(.5) return population_zoom_png(request)
def results_context(request): context = {} if not request.is_ajax() and ('results/' in request.path or 'setup/' in request.path): # results specific context session = SmSession.objects.get() context.update({'simulation_has_started': session.simulation_has_started, 'outputs_exist': outputs_exist(), 'results_progress': iteration_progress() * 100,}) try: version = ResultsVersion.objects.all().first().__str__() # singleton doesn't always work on this model (legacy) except: version = "No version available" context.update({ 'is_simulation_running': is_simulation_running(), 'is_simulation_stopped': is_simulation_stopped(), 'iterations_completed': iterations_complete(), 'version_number': version }) context.update(excluded_headers()) return context