Exemplo n.º 1
0
 def test_0_spins(self):
     s = Sample()
     session_start_time = datetime.datetime.now()
     session_end_time = session_start_time + datetime.timedelta(seconds=3)
     sample_end_time = session_start_time + datetime.timedelta(seconds=2)
     s.collect_sample(flywheel_q, session_start_time, session_end_time,
                      sample_end_time)
     self.assertEquals(s.get_flywheel_change(), 0)
     self.assertEquals(len(s.get_sample_flywheel_updates()), 0)
Exemplo n.º 2
0
 def test_add_10_spins_with_0pt1_seconds_between_spins(self):
     s = Sample()
     session_start_time = datetime.datetime.now()
     session_end_time = session_start_time + datetime.timedelta(seconds=3)
     sample_end_time = session_start_time + datetime.timedelta(seconds=2)
     self.add_n_spins_with_n_seconds_between_spins(10, 0.1)
     s.collect_sample(flywheel_q, session_start_time, session_end_time,
                      sample_end_time)
     self.assertEquals(s.get_flywheel_change(), 10)
     self.assertEquals(len(s.get_sample_flywheel_updates()), 10)
Exemplo n.º 3
0
 def test_complete_11_anticlockwise_irspins_with_0pt01_seconds_between_each_ir(
         self):
     s = Sample()
     session_start_time = datetime.datetime.now()
     session_end_time = session_start_time + datetime.timedelta(seconds=3)
     sample_end_time = session_start_time + datetime.timedelta(seconds=2)
     self.add_n_irspins_with_n_seconds_between_ir(11, 0.01, ANTICLOCKWISE)
     s.collect_sample(flywheel_q, session_start_time, session_end_time,
                      sample_end_time)
     self.assertEquals(s.get_stroke_pos_change(), -11)
     self.assertEquals(len(s.get_sample_ir_updates()), 33)
Exemplo n.º 4
0
 def test_complete_2_clockwise_irspins_with_0pt01_seconds_between_each_ir(
         self):
     s = Sample()
     #since this test starts at IR_ONE, we'll say the 'old' IR was IR_THREE
     s.ssr.old_ir = IR_THREE
     session_start_time = datetime.datetime.now()
     session_end_time = session_start_time + datetime.timedelta(seconds=3)
     sample_end_time = session_start_time + datetime.timedelta(seconds=2)
     self.add_n_irspins_with_n_seconds_between_ir(2, 0.01, CLOCKWISE)
     s.collect_sample(flywheel_q, session_start_time, session_end_time,
                      sample_end_time)
     self.assertEquals(s.get_stroke_pos_change(), 2)
     self.assertEquals(len(s.get_sample_ir_updates()), 6)
Exemplo n.º 5
0
    def run(self, q, gui_q, session_start_time, session_end_time, display_sample):
        self.sess_complete = False
        remaining_ms = 0
        self.session_start_time = session_start_time        
        self.session_end_time = session_end_time
        self.sample_cnt = 1
        self.speed_sample_cnt = 0
        self.timeout_time = ""
        self.display_sample = display_sample
        sample = Sample()
        self.sample = 0
        while not self.sess_complete:
            sample_end_time = self.get_next_sample_end_time()
            sample.collect_sample(q, self.session_start_time, self.session_end_time, sample_end_time)
            self.update_lst = []

            if datetime.datetime.now() < self.session_end_time:
                remaining_ms = timedelta_milliseconds(self.session_end_time - datetime.datetime.now())

                #apply time remaining GUI update
                self.update_lst.append(self.update_time_remaining(remaining_ms))
                sp_change = sample.get_stroke_pos_change()
                r_change = sample.get_flywheel_change()

                #apply stroke pos change GUI update and data update
                self.update_lst.append([STROKE_UPT, sp_change])
                stroke_updates = sample.get_sample_ir_updates()
                if len(stroke_updates) > 0:
                    self.ir_ary.extend(stroke_updates)

                #apply flywheel GUI update and data update
                self.update_lst.append([PLAYER_UPT, r_change])
                flywheel_updates = sample.get_sample_flywheel_updates()
                if len(flywheel_updates) > 0:
                    self.timestamp_ary.extend(flywheel_updates)

                sample.reset()

                if r_change == 0:
                    if self.timeout_time == "":
                        self.timeout_time = datetime.datetime.now() + datetime.timedelta(seconds=NUM_SECONDS_TIMEOUT)
                    else:
                        timedelta = self.timeout_time - datetime.datetime.now()
                        to_seconds_remaining = int(timedelta.total_seconds())
                        if to_seconds_remaining <= 0:
                            self.update_lst.append([STOPWATCH_UPT, "TIMEOUT", RED])
                            self.update_lst.append([SCREEN_MSG, "TIMEOUT", RED])
                            self.sess_complete = True
                        elif to_seconds_remaining < NUM_SECONDS_BEFORE_TIMEOUT_CRITICAL_WARNING:
                            msg = "TIMEOUT IN " + str(to_seconds_remaining)
                            self.update_lst.append([SCREEN_MSG, msg, RED])
                        elif to_seconds_remaining < NUM_SECONDS_BEFORE_TIMEOUT_WARNING:
                            msg = "TIMEOUT IN " + str(to_seconds_remaining)
                            self.update_lst.append([SCREEN_MSG, msg, WHITE])
                else:
                    self.timeout_time = ""
                    #clear warning
                    self.update_lst.append([SCREEN_MSG, "", WHITE])

                self.update_lst.append([GHOST_UPT, True])
                self.update_lst.append([FISH_UPT, True])
            else:
                self.update_lst.append([STOPWATCH_UPT, "FINISH", GREEN])
                self.sess_complete = True

            gui_q.put(self.update_lst)

            if not user_event_q.empty():
                item_list = user_event_q.get_nowait()
                for item in item_list:
                    if item[0] == RESET_SESSION:
                        return RESET_SESSION
                    elif item[0] == STOP_SESSION:
                        return STOP_SESSION
        return SESSION_COMPLETED