11from datetime import timedelta
22from enum import Enum
3+ from investing_algorithm_framework .domain .exceptions import \
4+ OperationalException
35
46
57class TimeUnit (Enum ):
8+ """
9+ Enum class the represents a time unit such as
10+ second, minute, hour or day. This can class
11+ can be used to specify time specification within
12+ the framework.
13+ """
614 SECOND = "SECOND"
715 MINUTE = "MINUTE"
816 HOUR = "HOUR"
@@ -18,7 +26,11 @@ def from_string(value: str):
1826 if value .upper () == entry .value :
1927 return entry
2028
21- raise ValueError (
29+ raise OperationalException (
30+ f"Could not convert string { value } to time unit"
31+ )
32+
33+ raise OperationalException (
2234 f"Could not convert value { value } to time unit," +
2335 " please make sure that the value is either of type string or" +
2436 f"TimeUnit. Its current type is { type (value )} "
@@ -38,17 +50,21 @@ def from_ohlcv_data_file(file_path: str):
3850 TimeUnit: The extracted time unit.
3951 """
4052 if not isinstance (file_path , str ):
41- raise ValueError ("File path must be a string." )
53+ raise OperationalException (
54+ "File path must be a string."
55+ )
4256
4357 parts = file_path .split ('_' )
4458 if len (parts ) < 2 :
45- raise ValueError ("File name does not contain a valid time unit." )
59+ raise OperationalException (
60+ "File name does not contain a valid time unit."
61+ )
4662
4763 time_unit_str = parts [- 1 ].split ('.' )[0 ].upper ()
4864 try :
4965 return TimeUnit .from_string (time_unit_str )
5066 except ValueError :
51- raise ValueError (
67+ raise OperationalException (
5268 f"Could not extract time unit from file name: { file_path } . "
5369 "Expected format 'symbol_timeunit.csv', "
5470 f"got '{ time_unit_str } '."
0 commit comments