Changeset d310de3 in flowtimer
- Timestamp:
- 08/25/24 18:27:34 (9 months ago)
- Branches:
- guix
- Children:
- 01c3cce
- Parents:
- d7a66ad
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
flowtimer/RecurringPhaseSequence.py
rd7a66ad rd310de3 11 11 if 'title' in d and 'initial_ticks' in d: 12 12 return Phase(d['title'], d['initial_ticks']) 13 if 'phase _list' in d and 'initial_repetitions' in d:14 return RecurringPhaseSequence(d["title"], d['phase _list'], d['initial_repetitions'])13 if 'phases' in d and 'initial_repetitions' in d: 14 return RecurringPhaseSequence(d["title"], d['phases'], d['initial_repetitions']) 15 15 print("Wrong format") 16 16 return d … … 20 20 def default_json_string(cls): 21 21 return json.dumps({"title": "default", 22 "phase _list": [{"title": "Tasking", "initial_ticks": 5},23 24 22 "phases": [{"title": "Tasking", "initial_ticks": 5}, 23 {"title": "Work", "initial_ticks": 45}, 24 {"title": "Break", "initial_ticks": 15}], 25 25 "initial_repetitions": 3}) 26 26 … … 29 29 return cls.from_json(cls.default_json_string()) 30 30 31 def __init__(self, title, phase _list, repetitions):31 def __init__(self, title, phases, repetitions): 32 32 assert repetitions > 0 33 assert phase _listis not []33 assert phases is not [] 34 34 self._title = title 35 35 self.state = "initial" 36 self.phase _list = phase_list37 self.current_phase = phase _list[0]36 self.phases = phases 37 self.current_phase = phases[0] 38 38 self.initial_repetitions = repetitions 39 39 self.passes_left = repetitions … … 53 53 54 54 def current_phase_number(self): 55 return self.phase _list.index(self.current_phase)55 return self.phases.index(self.current_phase) 56 56 57 57 def phases_left_in_pass(self): … … 59 59 60 60 def upcoming_phases_in_pass(self): 61 if self.current_phase_number() < len(self.phase _list) - 1:62 return self.phase _list[self.current_phase_number()+1:]61 if self.current_phase_number() < len(self.phases) - 1: 62 return self.phases[self.current_phase_number()+1:] 63 63 return [] 64 64 65 65 @property 66 66 def initial_ticks(self): 67 return sum([each.initial_ticks for each in self.phase _list])67 return sum([each.initial_ticks for each in self.phases]) 68 68 69 69 @property 70 70 def ticks_left(self): 71 71 return ( 72 (self.passes_left-1) * sum([each.initial_ticks for each in self.phase _list]) +72 (self.passes_left-1) * sum([each.initial_ticks for each in self.phases]) + 73 73 self.current_phase.ticks_left + 74 74 sum([each.ticks_left for each in self.upcoming_phases_in_pass()])) … … 99 99 self.passes_left -= 1 100 100 self.current_phase.reset() 101 self.current_phase = self.phase _list[0]101 self.current_phase = self.phases[0] 102 102 103 103 def advance_to_next_phase(self): 104 104 current_index = self.current_phase_number() 105 if current_index < len(self.phase _list) - 1:105 if current_index < len(self.phases) - 1: 106 106 # Move to the next phase in the sequence 107 107 self.current_phase.reset() 108 self.current_phase = self.phase _list[current_index + 1]108 self.current_phase = self.phases[current_index + 1] 109 109 else: 110 110 # Completed a full sequence; check if more repetitions are needed … … 114 114 else: 115 115 self.current_phase.reset() 116 self.current_phase = self.phase _list[0] # Reset to the first phase116 self.current_phase = self.phases[0] # Reset to the first phase 117 117 118 118 def tick(self, ticks): … … 134 134 135 135 def unrolled(self): 136 return [deepcopy(seq) for seq in [each for each in self.initial_repetitions * self.phase _list]]136 return [deepcopy(seq) for seq in [each for each in self.initial_repetitions * self.phases]] -
flowtimer/Schedule.py
rd7a66ad rd310de3 79 79 "type": "Sequence", 80 80 "title": block.title, 81 "sequence": [serialize_block(phase) for phase in block.phase _list],81 "sequence": [serialize_block(phase) for phase in block.phases], 82 82 "initial_repetitions": block.initial_repetitions 83 83 } -
tests/test_recurring_phase_sequence.py
rd7a66ad rd310de3 17 17 assert isinstance(sequence, RecurringPhaseSequence) 18 18 assert sequence.initial_repetitions == 3 19 assert len(sequence.phase _list) == 320 assert sequence.phase _list[0].title == "Tasking"19 assert len(sequence.phases) == 3 20 assert sequence.phases[0].title == "Tasking" 21 21 22 22 def test_to_json(self, recurring_phase_sequence): … … 26 26 assert data['initial_repetitions'] == 3 27 27 assert data['passes_left'] == 3 28 assert len(data['phase _list']) == 328 assert len(data['phases']) == 3 29 29 30 30 def test_initial_state(self, recurring_phase_sequence): … … 49 49 50 50 def test_ticks_left(self, recurring_phase_sequence): 51 total_ticks = (sum([phase.initial_ticks for phase in recurring_phase_sequence.phase _list]) *51 total_ticks = (sum([phase.initial_ticks for phase in recurring_phase_sequence.phases]) * 52 52 recurring_phase_sequence.initial_repetitions) 53 53 … … 59 59 assert not recurring_phase_sequence.completed() 60 60 for _ in range(3): 61 for phase in recurring_phase_sequence.phase _list:61 for phase in recurring_phase_sequence.phases: 62 62 recurring_phase_sequence.tick(phase.initial_ticks) 63 63 assert recurring_phase_sequence.completed()
Note:
See TracChangeset
for help on using the changeset viewer.