aboutsummaryrefslogtreecommitdiffstats
path: root/python/monitor.py
blob: 0bcdf37ecf7e27a8a9cf2130c5b26865f0668c6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import time
import subprocess
import datetime
import common
from intex_scenarios import generate_scenarios

Rpath = os.path.join(common.root, "code", "R")
logpath = os.path.join(common.root, "logs")
dealsfile = os.path.join(common.root, "scripts", "deals_to_price.txt")

args1 = ["Rscript", "--vanilla", os.path.join(Rpath, "build_portfolios.R")]
args2 = ["Rscript", "--vanilla", os.path.join(Rpath, "build_scenarios.R")]

while True:
    workdate = str(datetime.date.today())
    if os.path.exists(dealsfile):
        with open(os.path.join(dealsfile)) as fh:
            dealnames = [line.split("\t")[0] for line in fh]
        with open(os.path.join(logpath, "build_portfolios.Rout"), "w") as fh:
            subprocess.call(args1, stderr = subprocess.STDOUT, stdout = fh)
        with open(os.path.join(logpath, "build_scenarios.Rout"), "w") as fh:
            subprocess.call(args2, stderr = subprocess.STDOUT, stdout = fh)
        for dealname in dealnames:
            generate_scenarios(common.conn, workdate, dealname)
    time.sleep(3)
common.conn.close()