source: flowtimer/flowtimer/Phase.py@ f959488

guix
Last change on this file since f959488 was f959488, checked in by Enrico Schwass <ennoausberlin@…>, 9 months ago

Schedule can be initialized with a list of Phases and RecurringPhaseSequences

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import json
2
3
4class Phase:
5
6 """
7 This class is a representation of a single phase inside a timer
8 """
9
10 def __init__(self, title, ticks):
11 """
12 creates the variables associated with that class
13
14 :type title: string
15 :param title: Name of phase
16
17 :type ticks: int
18 :param ticks: ticks in seconds
19 """
20
21 self.title = title
22 self.initial_ticks = ticks
23 self.state = "initial"
24 self.ticks_left = ticks
25
26 def to_json(self):
27 return json.dumps({"title": self.title, "duration": self.initial_ticks})
28
29 def __str__(self):
30 """
31 Human readable representation of all attributes
32
33 :return: human readable representation of all attributes
34 :rtype: String
35 """
36
37 return ("-->" + self.title + "\nTicks left=" +
38 str(self.ticks_left) + "\n" + str(self.state) + "\n")
39
40 def abort(self):
41 self.state = "finished"
42
43 def start(self):
44 self.state = "running"
45
46 def reset(self):
47 self.ticks_left = self.initial_ticks
48 self.state = "initial"
49
50 def pause(self):
51 self.state = "paused"
52
53 def running(self):
54 return self.state == "running"
55 # return self.time_left > 0
56
57 def finished(self):
58 return self.state == "finished"
59
60 def paused(self):
61 return self.state == "paused"
62
63 def tick(self, ticks):
64 result = self.ticks_left - ticks
65
66 if result <= 0:
67 print("Single phase finished")
68 self.ticks_left = 0
69 self.state = "finished"
70 else:
71 self.ticks_left = result
72 return result
Note: See TracBrowser for help on using the repository browser.