You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.3 KiB
Python

"""
This file is designed to specify the appliction of pre/post-processing code.
The pre-processing code gets applied after the data has been loaded
The post-processing code get applied after the data has been generated for instance:
-approximation code/logic; date shifting; suppression; adding noise
-
"""
import numpy as np
from datetime import datetime, timedelta
import time
class Phase:
def __init__(self,**_args):
self._df = _args['data']
self.callback = _args['callback']
def apply(self,**_args):
"""
:param data data-frame
:param _info arguments needed to be applied
:param callback callback function once done
"""
raise Exception ("Function needs to be Implemented")
class Pre(Phase):
pass
class Post(Phase):
def __init__(self,**_args):
super().__init__(**_args)
pass
class Date(Post):
def __init__(self,**_args):
super().__init__(**_args)
def make(self,**_args):
"""
This function generates a random date given a year and optionally a set of days from the randomly generated date
:param year initial value of a year
:param offset list of days between initial date
"""
if _args['year'] in ['',None,np.nan] :
return None
year = int(_args['year'])
offset = _args['offset'] if 'offset' in _args else 0
month = np.random.randint(1,13)
if month == 2:
_end = 28 if year % 4 != 0 else 29
else:
_end = 31 if month in [1,3,5,7,8,10,12] else 30
day = np.random.randint(1,_end)
#-- synthetic date
_date = datetime(year=year,month=month,day=day,minute=0,hour=0,second=0)
FORMAT = '%Y-%m-%d' if 'format' not in _args else _args['format']
# print ([_name,FORMAT, _date.strftime(FORMAT)])
r = []
if offset :
r = [_date.strftime(FORMAT)]
for _delta in offset :
_date = _date + timedelta(_delta)
r.append(_date.strptime(FORMAT))
return r
else:
return _date.strftime(FORMAT)
def apply(self,**_args):
"""
"""