当前位置: 首页>>代码示例>>Python>>正文


Python Stopwatch.get_elapsed_time方法代码示例

本文整理汇总了Python中stopwatch.Stopwatch.get_elapsed_time方法的典型用法代码示例。如果您正苦于以下问题:Python Stopwatch.get_elapsed_time方法的具体用法?Python Stopwatch.get_elapsed_time怎么用?Python Stopwatch.get_elapsed_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stopwatch.Stopwatch的用法示例。


在下文中一共展示了Stopwatch.get_elapsed_time方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]
class FpsMeter:
    print_fps = True
    
    def __init__(self, name=None):
        if name is None:
            self._name_argument_string = ""
        else:
            self._name_argument_string = "(%s)" % name
        self._fps_history = collections.deque(maxlen=10)
        self._previous_time = None
        self._previous_calculated_fps_time = None
        self._stopwatch = Stopwatch()
        self._fps = None

    def update(self):
        self._now = self._stopwatch.get_elapsed_time()
        if self._previous_time is None:
            self._stopwatch.start()
        else:
            self._update_fps_history()
            self._update_fps_if_timely()
        self._previous_time = self._now

    def _update_fps_history(self):
        time_increment = self._now - self._previous_time
        fps = 1.0 / time_increment
        self._fps_history.append(fps)

    def _update_fps_if_timely(self):
        if self._previous_calculated_fps_time:
            if (self._stopwatch.get_elapsed_time() - self._previous_calculated_fps_time) > 1.0:
                self._calculate_fps()
        else:
            self._calculate_fps()

    def _calculate_fps(self):
        self._fps = sum(self._fps_history) / len(self._fps_history)
        if self.print_fps:
            print "FPS%s: %.1f" % (self._name_argument_string, self._fps)
        self._previous_calculated_fps_time = self._stopwatch.get_elapsed_time()

    def get_fps(self):
        return self._fps
开发者ID:gaborpapp,项目名称:AIam,代码行数:45,代码来源:fps_meter.py

示例2: add_parser_arguments

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]

#.........这里部分代码省略.........
                    logger.debug("duration for %r: %r\n" %
                                      (file_info["name"], file_info["duration"]))
                    playable_file_index += 1

            if self.include_non_playable:
                file_info["index"] = filenum
            else:
                file_info["index"] = file_info["playable_file_index"]
        self._num_playable_files = playable_file_index

    def _get_file_duration(self, file_info):
        if "decoded_name" in file_info:
            cmd = 'soxi -D "%s"' % file_info["decoded_name"]
            try:
                stdoutdata, stderrdata = subprocess.Popen(
                    cmd, shell=True,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
                return float(stdoutdata)
            except:
                logger.debug("failed to get duration for %s" % file_info["decoded_name"])
                return 0

    def _get_num_channels(self, file_info):
        if "decoded_name" in file_info:
            cmd = 'soxi -c "%s"' % file_info["decoded_name"]
            stdoutdata, stderrdata = subprocess.Popen(
                cmd, shell=True, stdout=subprocess.PIPE).communicate()
            return int(stdoutdata)

    def get_current_log_time(self):
        if self.fast_forwarding:
            return self._log_time_for_last_handled_event
        else:
            return self.log_time_played_from + self.stopwatch.get_elapsed_time() * self.timefactor

    def play_non_realtime(self, quit_on_end=False):
        logger.debug("entering play_non_realtime")
        if self._loop:
            while True:
                self._play_until_end()
                self.set_time_cursor(0)
        else:
            self._play_until_end()
            if quit_on_end:
                self._quitting = True
        logger.debug("leaving play_non_realtime")

    def _play_until_end(self):
        logger.debug("entering _play_until_end")
        self._playing = True
        self.stopwatch.start()
        no_more_events = False
        while self._playing and not no_more_events:
            event = self._get_next_chunk_or_segment()
            if event:
                self._handle_event(event)
            else:
                no_more_events = True
        logger.debug("leaving _play_until_end")

    def _get_next_chunk_or_segment(self):
        logger.debug("chunk index = %d, segment index = %d" % (
                self.current_chunk_index, self.current_segment_index))
        chunk = self._get_next_chunk()
        segment = self._get_next_segment()
        logger.debug("next chunk: %s" % chunk)
开发者ID:gaborpapp,项目名称:torrential-forms,代码行数:70,代码来源:orchestra.py

示例3: MainWindow

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]
class MainWindow(QtGui.QWidget):
    def __init__(self, experiment):
        QtGui.QMainWindow.__init__(self)
        experiment.window = self
        self._experiment = experiment
        self._layout = QtGui.QVBoxLayout()
        self.sliders = {}
        self.setLayout(self._layout)
        self._add_parameter_form()
        self._add_map_view()
        self._create_menu()
        self._generate_map_and_path()

        self.stopwatch = Stopwatch()
        self._frame_count = 0
        timer = QtCore.QTimer(self)
        timer.setInterval(1000. / FRAME_RATE)
        QtCore.QObject.connect(timer, QtCore.SIGNAL('timeout()'), self._update)
        timer.start()

    def _add_map_view(self):
        self._map_view = MapView(self, experiment)
        self._layout.addWidget(self._map_view)

    def _add_parameter_form(self):
        layout = QtGui.QFormLayout()
        self._add_slider(layout, "novelty")
        self._add_slider(layout, "extension")
        self._add_slider(layout, "location_preference")
        self._layout.addLayout(layout)

    def _add_slider(self, layout, name):
        slider = QtGui.QSlider(QtCore.Qt.Horizontal)
        slider.setRange(0, SLIDER_PRECISION)
        slider.setSingleStep(1)
        slider.setValue(0.0)
        layout.addRow(name, slider)
        self.sliders[name] = slider

    def _create_menu(self):
        menu_bar = QtGui.QMenuBar()
        self._layout.setMenuBar(menu_bar)
        self._menu = menu_bar.addMenu("Navigator test")
        self._add_generate_new_path_action()
        self._add_extend_path_action()
        self._add_generate_map_action()

    def _add_generate_new_path_action(self):
        action = QtGui.QAction('Generate new &path', self)
        action.setShortcut('Ctrl+P')
        action.triggered.connect(self._experiment.generate_new_path)
        self._menu.addAction(action)

    def _add_extend_path_action(self):
        action = QtGui.QAction('&Extend path', self)
        action.setShortcut('Ctrl+E')
        action.triggered.connect(self._experiment.extend_path)
        self._menu.addAction(action)

    def _add_generate_map_action(self):
        action = QtGui.QAction('Generate &map', self)
        action.setShortcut('Ctrl+M')
        action.triggered.connect(self._generate_map_and_path)
        self._menu.addAction(action)

    def _generate_map_and_path(self):
        self._experiment.generate_map()
        self._experiment.create_navigator()
        self._experiment.generate_new_path()

    def _update(self):
        self.now = self.stopwatch.get_elapsed_time()
        if self._frame_count == 0:
            self.stopwatch.start()
        else:
            time_increment = self.now - self.previous_frame_time
            self._experiment.proceed(time_increment)
            self._map_view.updateGL()
        self.previous_frame_time = self.now
        self._frame_count += 1
开发者ID:gaborpapp,项目名称:AIam,代码行数:82,代码来源:test_navigator.py

示例4: MainWindow

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]
class MainWindow(QtGui.QWidget):
    def __init__(self, experiment):
        QtGui.QMainWindow.__init__(self)
        experiment.window = self
        self._experiment = experiment
        self._layout = QtGui.QVBoxLayout()
        self.setLayout(self._layout)
        self._add_parameter_form()
        self._add_map_view()
        self._create_menu()

        self.stopwatch = Stopwatch()
        self._frame_count = 0
        timer = QtCore.QTimer(self)
        timer.setInterval(1000. / FRAME_RATE)
        QtCore.QObject.connect(timer, QtCore.SIGNAL('timeout()'), self._update)
        timer.start()

    def _add_map_view(self):
        self._map_view = MapView(self, experiment)
        self._layout.addWidget(self._map_view)

    def _add_parameter_form(self):
        self._parameter_sliders = {}
        layout = QtGui.QFormLayout()
        for parameter_name in PARAMETERS:
            default_value = getattr(args, parameter_name)
            self._add_slider(layout, parameter_name, default_value)
        self._layout.addLayout(layout)

    def _add_slider(self, layout, name, default_value):
        slider = QtGui.QSlider(QtCore.Qt.Horizontal)
        slider.setRange(0, SLIDER_PRECISION)
        slider.setSingleStep(1)
        slider.setValue(int(default_value * SLIDER_PRECISION))
        slider.valueChanged.connect(lambda event: self.update_flaneur_parameter(name))
        layout.addRow(name, slider)
        self._parameter_sliders[name] = slider

    def update_flaneur_parameter(self, parameter_name):
        slider = self._parameter_sliders[parameter_name]
        value = float(slider.value()) / SLIDER_PRECISION
        setattr(self._experiment.flaneur, parameter_name, value)

    def _create_menu(self):
        menu_bar = QtGui.QMenuBar()
        self._layout.setMenuBar(menu_bar)
        self._menu = menu_bar.addMenu("Flaneur test")
        self._add_reset_action()
        self._add_generate_map_action()

    def _add_reset_action(self):
        action = QtGui.QAction('Reset', self)
        action.setShortcut('R')
        action.triggered.connect(self._experiment.reset)
        self._menu.addAction(action)

    def _add_generate_map_action(self):
        action = QtGui.QAction('Generate &map', self)
        action.setShortcut('Ctrl+M')
        action.triggered.connect(self._generate_map)
        self._menu.addAction(action)

    def _generate_map(self):
        self._experiment.generate_map()

    def _update(self):
        self.now = self.stopwatch.get_elapsed_time()
        if self._frame_count == 0:
            self.stopwatch.start()
        else:
            time_increment = self.now - self.previous_frame_time
            self._experiment.proceed(time_increment)
            self._map_view.updateGL()
        self.previous_frame_time = self.now
        self._frame_count += 1
开发者ID:gaborpapp,项目名称:AIam,代码行数:78,代码来源:test_flaneur.py

示例5: __init__

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]

#.........这里部分代码省略.........
        if self.exiting:
            glutDestroyWindow(glutGetWindow())
            return

        try:
            self._draw_gl_scene_error_handled()
        except Exception as error:
            traceback_printer.print_traceback()
            self.exiting = True
            raise error

    def _draw_gl_scene_error_handled(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        self.now = self.current_time()
        if self._frame_count == 0:
            self.stopwatch.start()
        else:
            self.time_increment = self.now - self.previous_frame_time
            self.configure_2d_projection()
            glTranslatef(self.margin, self.margin, 0)
            self._render_frames()
            self.render()
            if self.show_fps:
                self.update_fps_history()
                self.show_fps_if_timely()

        glutSwapBuffers()
        self.previous_frame_time = self.now
        self._frame_count += 1

    def current_time(self):
        return self.stopwatch.get_elapsed_time()

    def update_fps_history(self):
        if self.time_increment > 0:
            fps = 1.0 / self.time_increment
            self.fps_history.append(fps)

    def show_fps_if_timely(self):
        if self.previous_shown_fps_time:
            if (self.now - self.previous_shown_fps_time) > 1.0:
                self.calculate_and_show_fps()
        else:
            self.calculate_and_show_fps()

    def calculate_and_show_fps(self):
        print sum(self.fps_history) / len(self.fps_history)
        self.previous_shown_fps_time = self.now

    def keyPressed(self, key, x, y):
        if key == ESCAPE:
            self.exiting = True
        elif key == 's':
            self._dump_screen()
        elif key == 'f':
            if self._fullscreen:
                glutSetCursor(GLUT_CURSOR_INHERIT)
                glutLeaveGameMode()
                glutSetWindow(self._non_fullscreen_window)
                self._fullscreen = False
            else:
                self._open_fullscreen_window()
                self._fullscreen = True
开发者ID:gaborpapp,项目名称:AIam,代码行数:69,代码来源:window.py

示例6: Experiment

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]

#.........这里部分代码省略.........
            if self._exporting_output:
                self._export_bvh()
            if self._output_sender:
                self._send_output()

    def _proceed_and_update(self):
        self.proceed()
        self.entity.update(self.input)
        self.update()
        self._frame_count += 1
        self.send_event_to_ui(Event(Event.FRAME_COUNT, self._frame_count))
            
    def process_and_broadcast_output(self):
        if self._server.client_subscribes_to(Event.OUTPUT):
            self.processed_output = self.entity.process_output(self.output)
            self.send_event_to_ui(Event(Event.OUTPUT, self.processed_output))

    def _proceed_to_next_frame(self, event):
        self.time_increment = 1. / self.args.frame_rate
        self._proceed_and_update()

        if self.output is not None:
            self.process_and_broadcast_output()
        if self.entity.processed_input is not None:
            self.send_event_to_ui(Event(Event.INPUT, self.entity.processed_input))

    def send_event_to_ui(self, event):
        with self._ui_handlers_lock:
            for ui_handler in self._ui_handlers:
                if not (event.source == "PythonUI" and ui_handler.__class__ == SingleProcessUiHandler):
                    ui_handler.send_event(event)

    def current_time(self):
        return self.stopwatch.get_elapsed_time()

    def _training_duration(self):
        if self.args.training_duration:
            return self.args.training_duration
        elif hasattr(self.training_entity, "get_duration"):
            return self.training_entity.get_duration()
        else:
            raise Exception(
                "training duration specified in neither arguments nor the %s class" % \
                    self.training_entity.__class__.__name__)

    def _create_single_process_server(self):
        return SingleProcessServer(SingleProcessUiHandler, experiment=self)

    def _create_websocket_server(self):
        server = WebsocketServer(WebsocketUiHandler, {"experiment": self})
        print "websocket server ready"
        self._invoke_potential_launcher_in_args()
        return server

    def _invoke_potential_launcher_in_args(self):
        if self.args.launch_when_ready:
            print "launching %r" % self.args.launch_when_ready
            self._launched_process = subprocess.Popen(self.args.launch_when_ready, shell=True)

    def _set_up_timed_refresh(self):
        self._server.add_periodic_callback(
            self._update_and_refresh_uis, 1000. / self.args.frame_rate)

    def _start_in_new_thread(self, server):
        server_thread = threading.Thread(target=server.start)
        server_thread.daemon = True
开发者ID:gaborpapp,项目名称:AIam,代码行数:70,代码来源:experiment.py

示例7: MasterBehavior

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]

#.........这里部分代码省略.........
        
    def reset_translation(self):
        master_entity.reset_constrainers()
        self._chainer = Chainer()
        self._chainer.put(numpy.zeros(3))
        self._chainer.get()
        self._chainer.switch_source()
        self._selector = Selector(self._chainer.switch_source)

    def on_recall_amount_changed(self):
        pass
    
    def set_recall_amount(self, recall_amount):
        self._recall_amount = recall_amount

    def get_recall_amount(self):
        return self._recall_amount
    
    def set_model(self, model_name):
        self._improvise = improvise_behaviors[model_name]
        self._chainer.switch_source()

    def proceed(self, time_increment):
        if self._noise_amount > 0:
            students["autoencoder"].add_noise(self._noise_amount)
        self._improvise.proceed(time_increment)
        recall_behavior.proceed(time_increment)
        if self.auto_friction:
            if self._recall_amount < 0.5:
                self._set_master_entity_friction_and_update_ui(True)
            else:
                self._set_master_entity_friction_and_update_ui(False)

    def _set_master_entity_friction_and_update_ui(self, value):
        master_entity.set_friction(value)
        application.on_friction_changed(value)
                
    def sends_output(self):
        return True

    def on_input(self, input_):
        self._input = input_
        if self.memorize:
            memory.on_input(input_)

    def set_auto_switch_enabled(self, value):
        self._auto_switch_enabled = value
        
    def get_output(self):
        if self.input_only:
            return self._input

        if self._auto_switch_enabled:
            self._recall_amount = self._get_auto_switch_recall_amount()
            self.on_recall_amount_changed()
            
        improvise_output = self._get_improvise_output()
        recall_output = recall_behavior.get_output()
        
        if args.verbose:
            self._print_output_info("improvise_output", improvise_output)
            self._print_output_info("recall_output", recall_output)
            
        if recall_output is None:
            if self._recall_amount > 0:
                application.print_and_log("WARNING: recall amount > 0 but no recall output")
            translation = self._pass_through_selector_to_update_its_state(
                get_translation(improvise_output))
            orientations = get_orientations(improvise_output)
        else:
            translation = self._selector.select(
                get_translation(improvise_output),
                get_translation(recall_output),
                self._recall_amount)
            orientations = get_orientations(
                master_entity.interpolate(improvise_output, recall_output, self._recall_amount))
                
        self._chainer.put(translation)
        translation = self._chainer.get()
        output = combine_translation_and_orientations(translation, orientations)
        
        return output

    def _pass_through_selector_to_update_its_state(self, value):
        return self._selector.select(value, None, 0)
    
    def _get_auto_switch_recall_amount(self):
        return (math.sin(self._stopwatch.get_elapsed_time() * .5) + 1) / 2
    
    def _print_output_info(self, name, output):
        if output is None:
            return
        root_quaternion = output[0:4]
        print "%s root: %s" % (name, root_quaternion)
    
    def _get_improvise_output(self):
        reduction = self._improvise.get_reduction()
        if reduction is None:
            return None
        return student.inverse_transform(numpy.array([reduction]))[0]
开发者ID:gaborpapp,项目名称:AIam,代码行数:104,代码来源:learn_recall_improvise.py

示例8: __init__

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]

#.........这里部分代码省略.........
        glutSpecialFunc(self._special_key_pressed)

    def ReSizeGLScene(self, window_width, window_height):
        self.window_width = window_width
        self.window_height = window_height
        if window_height == 0:
            window_height = 1
        glViewport(0, 0, window_width, window_height)
        self.width = window_width - 2*self.margin
        self.height = window_height - 2*self.margin
        self._aspect_ratio = float(window_width) / window_height
        self.min_dimension = min(self.width, self.height)
        self._refresh_layers()
        if not self._3d_enabled:
            self.configure_2d_projection()
        self.resized_window()

    def resized_window(self):
        pass

    def configure_2d_projection(self):
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(0.0, self.window_width, self.window_height, 0.0, -1.0, 1.0)
        glMatrixMode(GL_MODELVIEW)

    def _refresh_layers(self):
        for layer in self._layers:
            layer.refresh()

    def DrawGLScene(self):
        if self.exiting:
            self.logger.debug("total number of rendered frames: %s" % self._frame_count)
            if self.stopwatch.get_elapsed_time() > 0:
                self.logger.debug("total FPS: %s" % (float(self._frame_count) / self.stopwatch.get_elapsed_time()))
            if self.args.profile:
                import yappi
                yappi.print_stats(sys.stdout, yappi.SORTTYPE_TTOT)
            glutDestroyWindow(glutGetWindow())
            return

        try:
            self._draw_gl_scene_error_handled()
        except Exception as error:
            traceback_printer.print_traceback()
            self.exiting = True
            raise error

    def _draw_gl_scene_error_handled(self):
        if self._camera_script:
            self._move_camera_by_script()

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        if self.export:
            self.current_export_time = float(self._frame_count) / self.export_fps

        self.now = self.current_time()
        is_waiting_for_synth = (self.sync and not self._synth() and not self._synced)
        is_waiting_for_audio_capture_to_start = (
            self.capture_message_log and self._audio_capture_start_time is None)
        if self._frame_count == 0 and \
                not is_waiting_for_synth and \
                not is_waiting_for_audio_capture_to_start:
            self.stopwatch.start()
开发者ID:alex-berman,项目名称:tforms,代码行数:70,代码来源:visualizer.py

示例9: add_parser_arguments

# 需要导入模块: from stopwatch import Stopwatch [as 别名]
# 或者: from stopwatch.Stopwatch import get_elapsed_time [as 别名]

#.........这里部分代码省略.........

    @classmethod
    def _get_wav_files_info(cls, tr_log, include_non_playable=False):
        playable_file_index = 0
        for filenum in range(len(tr_log.files)):
            file_info = tr_log.files[filenum]
            file_info["playable_file_index"] = -1

            if "decoded_name" in file_info:
                file_info["duration"] = cls._get_file_duration(file_info)
                if file_info["duration"] > 0:
                    file_info["playable_file_index"] = playable_file_index
                    logger.debug("duration for %r: %r\n" %
                                      (file_info["name"], file_info["duration"]))
                    playable_file_index += 1

            if include_non_playable:
                file_info["index"] = filenum
            else:
                file_info["index"] = file_info["playable_file_index"]
        return playable_file_index

    @classmethod
    def _get_file_duration(cls, file_info):
        if "decoded_name" in file_info:
            statinfo = os.stat(file_info["decoded_name"])
            wav_header_size = 44
            return float((statinfo.st_size - wav_header_size) / cls.BYTES_PER_SAMPLE) / cls.SAMPLE_RATE

    def get_current_log_time(self):
        if self.fast_forwarding:
            return self._log_time_for_last_handled_event
        else:
            return self.log_time_played_from + self.stopwatch.get_elapsed_time() * self.timefactor

    def play_non_realtime(self, quit_on_end=False):
        logger.info("entering play_non_realtime")
        self._was_stopped = False
        self._num_finished_visualizers = 0
        if self._loop:
            while True:
                self._play_until_end()
                if not self._was_stopped:
                    self._wait_for_visualizers_to_finish()
                self.set_time_cursor(0)
        else:
            self._play_until_end()
            if not self._was_stopped:
                self._wait_for_visualizers_to_finish()
            if quit_on_end:
                self._quit()
        logger.info("leaving play_non_realtime")

    def _quit(self):
        if self.options.capture_audio:
            self._audio_capture_process.kill()
        self._quitting = True

    def _play_until_end(self):
        logger.info("entering _play_until_end")
        self._playing = True
        self.stopwatch.start()
        time.sleep(self._leading_pause)
        no_more_events = False
        while self._playing and not no_more_events:
            event = self._get_next_chunk_or_segment()
开发者ID:alex-berman,项目名称:tforms,代码行数:70,代码来源:orchestra.py


注:本文中的stopwatch.Stopwatch.get_elapsed_time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。