def run_single_test_on_single_vm(vm, testcase):
    errcode = 2
    vm_username = vm.UserName
    vm_ip = vm.IP
    testid = testcase.TestID

    testcase_bash_script = testcase.ExecScript
    testcase_script_local_path = "./{0}/{1}".format("TestCases",
                                                    testcase_bash_script)
    testcase_script_remote_path = "{0}/{1}/{2}".format("/home", vm_username,
                                                       testcase_bash_script)

    testlog = testcase.LogFile
    testlog_local = "./_{0}-{1}-{2}".format(vm.Role,
                                            str(testid).zfill(2), testlog)
    testlog_remote = "{0}/{1}/{2}".format("/home", vm_username, testlog)

    if os.path.isfile(testcase_script_local_path) == False:
        LOG("             ERROR: The test script does not exist")
        return 2

    #copy the script to remote VM
    os.system("scp -q {0} {1}@{2}:".format(testcase_script_local_path,
                                           vm_username, vm_ip))
    os.system("ssh -q {0}@{1} 'chmod 755 {2}'".format(
        vm_username, vm_ip, testcase_script_remote_path))

    ssh = subprocess.Popen([
        "ssh", "{0}@{1}".format(vm_username, vm_ip),
        testcase_script_remote_path
    ],
                           shell=False,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
    result = ssh.stdout.readlines()

    os.system("scp -q {0}@{1}:{2} {3}".format(vm_username, vm_ip,
                                              testlog_remote, testlog_local))

    if result == []:
        error = ssh.stderr.readlines()
        LOG("             ERROR: %s" % error)
        errcode = 1
    else:
        for i, line in enumerate(result):
            if line.strip() == "":
                continue
            if "TEST PASSED" in line:
                errcode = 0
                break
            if "TEST FAILED" in line:
                errcode = 1
                break

    os.system("ssh -q {0}@{1} 'rm -rf {2}'".format(
        vm_username, vm_ip, testcase_script_remote_path))
    os.system("ssh -q {0}@{1} 'rm -rf {2}'".format(vm_username, vm_ip,
                                                   testlog_remote))

    return errcode
Beispiel #2
0
def clean_data(df):
    LOG('PROC: cleaning raw data in dataframe')
    df[['asks', 'bids', 'price']] = df[['asks', 'bids',
                                        'price']].apply(pd.to_numeric)
    df.index = pd.to_datetime(df['Time'])
    del df['Time']
    return df
Beispiel #3
0
def combine_dfs(dfs, depths):
    LOG('PROC: combining all bookratio dataframes into one')
    df = dfs[0]
    for i in range(1, len(depths)):
        depth = depths[i]
        df = df.join(dfs[i]['bookratio_{0}_pct'.format(depth)], on='Time')
    df.index = df.index.strftime('%Y%m%d%H%M%S')
    return df
Beispiel #4
0
def analyze_data(row):
    LOG('PROC: running book ratio ordering analysis')
    bookratios = [col for col in row.index.tolist() if 'bookratio' in col]
    x, y, z = row[bookratios[0]], row[bookratios[1]], row[bookratios[2]]
    if (x < y) and (y < z):  #xyz
        return 0
    elif (y < x) and (x < z):  #yxz
        return 1
    elif (x < z) and (z < y):  #xzy
        return 2
    elif (y < z) and (z < x):  #yzx
        return 3
    elif (z < x) and (x < y):  #zxy
        return 4
    elif (z < y) and (y < x):  #zyx
        return 5
Beispiel #5
0
    def em(self, initialize=None):
        if initialize is not None:
            self.trans, self.align = pkl.load(gzip.open(initialize, "rb"))
            LOG(INFO, "t and q is loaded.")
        else:
            self.trans = defaultdict(float)
            self.align = defaultdict(float)

            M = len(self.dict_e)
            t = self.trans
            for ej in self.dict_e:
                for fk in self.dict_f:
                    t[ej, fk] = 1. / M
            q = self.align
            for e, f in zip(self.corpus_e, self.corpus_f):
                l, m = len(e), len(f)
                for i, j in zip(xrange(l), xrange(m)):
                    q[j, i, l, m] = 1. / l

        for i in xrange(5):
            self._em()
Beispiel #6
0
 def loadcfgwithpath(self, pathcfg):
     self.cfg = configparser.ConfigParser()
     self.cfg.read(pathcfg)
     LOG('BotCfg: {}'.format(pathcfg))
     self.logconfig()
     return self.cfg
Beispiel #7
0
 def loadcfg(self):
     self.cfg = configparser.ConfigParser()
     self.cfg.read(self.path + '/' + self.filenm)
     LOG('BotCfg: from path:{} name:{}'.format(self.path, self.filenm))
     self.logconfig()
     return self.cfg
Beispiel #8
0
 def logconfig(self):
     for s in self.cfg.sections():
         LOG('CFG: section: ', s)
         for k, v in self.cfg[s].items():
             LOG('CFG: key:{} val:{}'.format(k, v))
Beispiel #9
0
    def initUI(self):
        # 设置窗口图标
        self.SetIcon(wx.Icon(self.icon, wx.BITMAP_TYPE_ICO))

        self.initMenu()

        panel = wx.Panel(self)

        # 邀请链接/邀请用户数标签
        st_link = wx.StaticText(panel, label=u'邀请链接: ', style=wx.TE_LEFT)
        st_desc_link = wx.StaticText(
            panel,
            label=u'注:在账户中心最下方可以找到邀请链接,'
            u'如:https://www.processon.com/i/5cc564f5e4b09eb4ac2b498e',
            style=wx.TE_LEFT | wx.ST_ELLIPSIZE_END)
        st_number = wx.StaticText(panel, label=u'邀请用户数: ', style=wx.TE_LEFT)
        st_desc_number = wx.StaticText(
            panel, label=u'注:每个用户通过邀请链接注册成功后,你会获得3张文件数量的奖励')
        # 邀请链接输入框
        self.tc_link = wx.TextCtrl(panel, style=wx.TE_LEFT)
        # 邀请用户数选择器
        choices = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
        self.ch_number = wx.Choice(panel, choices=choices)
        self.ch_number.SetSelection(0)
        # self.Bind(wx.EVT_CHOICE, self.onChoice, self.ch_number)
        # 日志
        self.tc_log = wx.TextCtrl(panel,
                                  style=wx.TE_MULTILINE | wx.TE_READONLY
                                  | wx.HSCROLL)
        # 可视化勾选框
        self.ck_visualization = wx.CheckBox(panel,
                                            label=u'可视化',
                                            style=wx.CHK_2STATE)
        # 邀请注册按钮
        self.btn_signup = wx.Button(panel, label=u'邀请注册')
        self.Bind(wx.EVT_BUTTON, self.onSignUpClick, self.btn_signup)

        # 邀请链接组件布局
        bs_link = wx.BoxSizer(wx.HORIZONTAL)
        bs_link.Add(st_link,
                    proportion=0,
                    flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
                    border=5)
        bs_link.Add(self.tc_link,
                    proportion=2,
                    flag=wx.ALL | wx.EXPAND,
                    border=5)

        bs_desc_link = wx.BoxSizer(wx.HORIZONTAL)
        bs_desc_link.Add(st_desc_link,
                         proportion=0,
                         flag=wx.LEFT | wx.RIGHT | wx.ALIGN_LEFT,
                         border=5)

        # 邀请用户数组件布局
        bs_number = wx.BoxSizer(wx.HORIZONTAL)
        bs_number.Add(st_number,
                      proportion=0,
                      flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
                      border=5)
        bs_number.Add(self.ch_number, proportion=0, flag=wx.ALL, border=5)
        bs_number.Add(st_desc_number,
                      proportion=0,
                      flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                      border=5)

        # 日志组件布局
        bs_log = wx.BoxSizer(wx.HORIZONTAL)
        bs_log.Add(self.tc_log,
                   proportion=1,
                   flag=wx.ALL | wx.EXPAND,
                   border=5)

        # 邀请注册按钮组件布局
        bs_signup = wx.BoxSizer(wx.HORIZONTAL)
        bs_signup.AddStretchSpacer(1)
        bs_signup.Add(self.ck_visualization,
                      proportion=0,
                      flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL,
                      border=5)
        bs_signup.Add(self.btn_signup, proportion=0, flag=wx.ALL, border=5)

        bs_all = wx.BoxSizer(wx.VERTICAL)
        bs_all.Add(bs_link,
                   proportion=0,
                   flag=wx.TOP | wx.LEFT | wx.RIGHT | wx.EXPAND,
                   border=5)
        bs_all.Add(bs_desc_link,
                   proportion=0,
                   flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND,
                   border=5)
        bs_all.Add(bs_number, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
        bs_all.Add(bs_log, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
        bs_all.Add(bs_signup, proportion=0, flag=wx.ALL | wx.EXPAND, border=5)
        panel.SetSizer(bs_all)
        self.logger = LOG(name=__name__, topic='log').getLogger()
        # 订阅消息队列
        pub.subscribe(self.updateButtonStatus, 'update')
        pub.subscribe(self.updateLogMessage, 'log')
Beispiel #10
0
def process_data(df, depth):
    LOG('PROC: producing bid/ask pct')
    df['bookratio_{0}_pct'.format(depth)] = np.log(df['bids'] / df['asks'])
    return df
Beispiel #11
0
def load_data(path, depth):
    LOG('LOAD: loading data into pandas dataframe')
    df = pd.read_csv(path + 'bitcoinity_data_{0}_pct.csv'.format(depth),
                     engine='c')
    return df
Beispiel #12
0
def plot_analysis(df):
    colors = df.apply(lambda row: plot_color(row), axis=1)
    fig = go.Figure(data=go.Scatter(x=df.index,
                                    y=df['price'],
                                    mode='lines+markers',
                                    marker=dict(color=colors, line_width=1)))
    fig.show()


if __name__ == '__main__':
    LOGINIT('bookratios')
    full_cfg = BotConfigParser()
    full_cfg.loadcfg()
    cfg = full_cfg.getsection('process')
    depths = sorted([int(item) for item in cfg['depths'].split(',')])
    bookratio_dfs = []
    for depth in depths:
        LOG('INFO: begin depth:' + str(depth))
        raw_data_df = load_data(cfg['datapath'], depth)
        cleaned_data_df = clean_data(raw_data_df)
        bookratio_df = process_data(cleaned_data_df, depth)
        bookratio_dfs.append(bookratio_df)
    analysis_df = combine_dfs(bookratio_dfs, depths)
    analysis_df['order'] = analysis_df.apply(lambda row: analyze_data(row),
                                             axis=1)
    LOG('OUT: saving analysis dataframe as CSV to path:', cfg['output'])
    buy_sell_signals = analysis_df['order'].tolist()
    print('Signals:\n', buy_sell_signals[-10:])
    analysis_df.to_csv(cfg['output'] + 'bookratios_analysis.csv')