diff options
Diffstat (limited to 'python/tasks.py')
| -rw-r--r-- | python/tasks.py | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/python/tasks.py b/python/tasks.py index 05c5f51c..d20191e5 100644 --- a/python/tasks.py +++ b/python/tasks.py @@ -4,29 +4,41 @@ import sys from intex.intex_scenarios import generate_scenarios from json import loads, dumps +from pathlib import Path + def build_portfolios(workdate, dealname, reinvflag): - rpath = os.path.join(os.environ['CODE_DIR'], "R") - logpath = os.path.join(os.environ['LOG_DIR']) - args = ["Rscript", "--vanilla", os.path.join(rpath, "build_portfolios.R"), \ - workdate, dealname + "," + reinvflag] + rpath = Path(__file__).parent.parent / "R" + args = [ + "Rscript", + "--vanilla", + rpath / "build_portfolios.R", + workdate, + dealname + "," + reinvflag, + ] subprocess.check_call(args, env=os.environ, cwd=rpath) + def build_scenarios(workdate, dealname, reinvflag): - rpath = os.path.join(os.environ['CODE_DIR'], "R") - logpath = os.path.join(os.environ['LOG_DIR']) - args = ["Rscript", "--vanilla", os.path.join(rpath, "build_scenarios.R"), \ - workdate, dealname + "," + reinvflag] + rpath = Path(__file__).parent.parent / "R" + args = [ + "Rscript", + "--vanilla", + rpath / "build_scenarios.R", + workdate, + dealname + "," + reinvflag, + ] subprocess.check_call(args, env=os.environ, cwd=rpath) -class Rpc(object): + +class Rpc: def __init__(self, fun, args): self.fun = fun self.args = args def __str__(self): - return dumps({'fun': self.fun, - 'args': self.args}) + return dumps({"fun": self.fun, "args": self.args}) + def __call__(self): globals()[self.fun](*self.args) @@ -34,7 +46,7 @@ class Rpc(object): def from_json(cls, s): rpc = loads(s) if sys.version_info[0] < 3: - instance = cls(rpc['fun'].encode(), [arg.encode() for arg in rpc['args']]) + instance = cls(rpc["fun"].encode(), [arg.encode() for arg in rpc["args"]]) else: - instance = cls(rpc['fun'], rpc['args']) + instance = cls(rpc["fun"], rpc["args"]) return instance |
