Skip to content

Commit

Permalink
add new classes, timez, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
trisongz committed Dec 1, 2021
1 parent 73666bc commit c477c38
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lazycls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from . import base
from . import funcs
from . import envs

from . import timez


from .prop import classproperty, ClasspropertyMeta
Expand All @@ -17,6 +17,7 @@
BaseLazy,
Field
)
from .timez import TimeCls

from .base import (
LazyCls,
Expand Down
2 changes: 1 addition & 1 deletion lazycls/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def loadEnvFile(path: Union[str, Path], override: bool = False):
'envToFloat',
'envToInt',
'envInVals',
'envToStr'
'envToStr',
'toEnv',
'loadEnvFile',
'load_env_file',
Expand Down
9 changes: 8 additions & 1 deletion lazycls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ class ValidatorArgs(BaseCls):
include: List[str] = []
exclude: List[str] = []


class BaseDataCls(BaseCls):
string: str = None
value: Any = None
dtype: str = None

__all__ = [
'BaseModel',
'Field',
'BaseCls'
'BaseCls',
'BaseDataCls',
'BaseLazy'
]
94 changes: 94 additions & 0 deletions lazycls/timez.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import time
from .types import *
from .models import BaseDataCls, BaseCls, Field


TimeValues = {
'secs': 60,
'mins': 60,
'hrs': 60,
'days': 24,
'wks': 7,
'mnths': 4
}


class TimeCls(BaseCls):
t: Optional[Union[float, int]] = Field(default_factory=time.time)
short: Optional[bool] = False
start: Optional[Union[float, int]] = None

@property
def now(self):
if self.start: return self.start
return time.time()

def stop(self): self.start = time.time()

@property
def diff(self): return self.now - self.t
@property
def s(self): return self.secs
@property
def secs(self): return self.diff
@property
def seconds(self): return self.secs
@property
def m(self): return self.mins
@property
def mins(self): return self.secs / 60
@property
def minutes(self): return self.mins
@property
def h(self): return self.hrs
@property
def hrs(self): return self.mins / 60
@property
def hr(self): return self.hrs
@property
def hour(self): return self.hrs
@property
def hours(self): return self.hrs
@property
def d(self): return self.days
@property
def day(self): return self.days
@property
def days(self): return self.hrs / 24
@property
def w(self): return self.wks
@property
def wk(self): return self.wks
@property
def wks(self): return self.days / 7
@property
def week(self): return self.wks
@property
def weeks(self): return self.wks
@property
def month(self): return self.mnths
@property
def mons(self): return self.mnths
@property
def mnths(self): return self.wks / 4
@property
def months(self): return self.mnths

@property
def ablstime(self) -> BaseDataCls:
curr_val = self.secs
dict_val, str_val = {}, ''
for tkey, tnum in TimeValues.items():
if curr_val >= 1:
tval = tkey[0] if self.short else tkey
curr_val, curr_num = divmod(curr_val, tnum)
if type(curr_num) == float: str_val = f'{curr_num:.1f} {tval} ' + str_val
else: str_val = f'{curr_num} {tval} ' + str_val
dict_val[tkey] = curr_num
str_val = str_val.strip()
return BaseDataCls(string=str_val, value=dict_val, dtype='time')


__all__ = [
'TimeCls'
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if sys.version_info.major != 3:
raise RuntimeError("This package requires Python 3+")

version = '0.0.2'
version = '0.0.3'
pkg_name = 'lazycls'
gitrepo = 'trisongz/lazycls'
root = Path(__file__).parent
Expand Down

0 comments on commit c477c38

Please sign in to comment.