11import sys
22from threading import Thread
33from wrapt import synchronized
4+ from enum import Enum
5+
6+ from investing_bot_framework .core .exceptions import OperationalException
47
58
69class Singleton (type ):
@@ -52,4 +55,52 @@ def localtrace(self, frame, event, arg):
5255 return self .localtrace
5356
5457 def kill (self ):
55- self .killed = True
58+ self .killed = True
59+
60+
61+ class TimeUnit (Enum ):
62+ """
63+ Class TimeUnit: Enum for TimeUnit
64+ """
65+
66+ SECOND = 'SEC' ,
67+ MINUTE = 'MIN' ,
68+ HOUR = 'HR' ,
69+ ALWAYS = 'ALWAYS'
70+
71+ # Static factory method to convert a string to time_unit
72+ @staticmethod
73+ def from_string (value : str ):
74+
75+ if isinstance (value , str ):
76+
77+ if value .lower () in ('sec' , 'second' , 'seconds' ):
78+ return TimeUnit .SECOND
79+
80+ elif value .lower () in ('min' , 'minute' , 'minutes' ):
81+ return TimeUnit .MINUTE
82+
83+ elif value .lower () in ('hr' , 'hour' , 'hours' ):
84+ return TimeUnit .HOUR
85+
86+ elif value .lower () in ('always' , 'every' , 'continuous' , 'every_time' ):
87+ return TimeUnit .ALWAYS
88+ else :
89+ raise OperationalException ('Could not convert value {} to a time_unit' .format (value ))
90+
91+ else :
92+ raise OperationalException ("Could not convert non string value to a time_unit" )
93+
94+ def equals (self , other ):
95+
96+ if isinstance (other , Enum ):
97+ return self .value == other .value
98+ else :
99+
100+ try :
101+ time_unit = TimeUnit .from_string (other )
102+ return time_unit == self
103+ except OperationalException :
104+ pass
105+
106+ return other == self .value
0 commit comments