def test_count(self): for bitstr in self.v_str: bm = BitMap.fromstring(bitstr) self.assertEqual(bitstr.count("1"), bm.count()) self.assertEqual(bitstr.count("1"), len([i for i in xrange(bm.size()) if bm.test(i)])) for bitstr in self.v_str[:-4]: self.assertTrue(BitMap.fromstring(bitstr).any()) self.assertTrue(BitMap.fromstring(self.v_str[-2]).all()) self.assertTrue(BitMap.fromstring(self.v_str[-1]).none())
def test_count(self): """ Test BitMap: create """ for bitstr in self.v_str: bm = BitMap.fromstring(bitstr) self.assertEqual(bitstr.count("1"), bm.count()) self.assertEqual(bitstr.count("1"), len([i for i in xrange(bm.size()) if bm.test(i)])) for bitstr in self.v_str[:-4]: self.assertTrue(BitMap.fromstring(bitstr).any()) self.assertTrue(BitMap.fromstring(self.v_str[-2]).all()) self.assertTrue(BitMap.fromstring(self.v_str[-1]).none())
def test_op(self): """ Test BitMap: create """ bitstr = "000000000000000000000000000000000" bitlst = list(bitstr) bm = BitMap.fromstring(bitstr) v_pos = [1, 2, 3, 5, 9] for i in v_pos: bm.set(i) bitlst[-i-1] = '1' self.assertEqual(self.helper_str_zfill("".join(bitlst)), bm.tostring()) self.assertEqual(bm.count(), len(v_pos)) for i in v_pos: bm.reset(i) bitlst[-i-1] = '0' self.assertEqual(self.helper_str_zfill("".join(bitlst)), bm.tostring()) self.assertEqual(self.helper_str_zfill(bitstr), bm.tostring()) self.assertEqual(bm.count(), 0) for i in v_pos: bm.flip(i) bitlst[-i-1] = '1' self.assertEqual(self.helper_str_zfill("".join(bitlst)), bm.tostring()) self.assertEqual(bm.count(), len(v_pos))
def test_op(self): """ Test BitMap: create """ bitstr = "000000000000000000000000000000000" bitlst = list(bitstr) bm = BitMap.fromstring(bitstr) v_pos = [1, 2, 3, 5, 9] for i in v_pos: bm.set(i) bitlst[-i - 1] = '1' self.assertEqual(self.helper_str_zfill("".join(bitlst)), bm.tostring()) self.assertEqual(bm.count(), len(v_pos)) for i in v_pos: bm.reset(i) bitlst[-i - 1] = '0' self.assertEqual(self.helper_str_zfill("".join(bitlst)), bm.tostring()) self.assertEqual(self.helper_str_zfill(bitstr), bm.tostring()) self.assertEqual(bm.count(), 0) for i in v_pos: bm.flip(i) bitlst[-i - 1] = '1' self.assertEqual(self.helper_str_zfill("".join(bitlst)), bm.tostring()) self.assertEqual(bm.count(), len(v_pos))
def test_str(self): """ Test BitMap: create """ for bitstr in self.v_str: bm = BitMap.fromstring(bitstr) self.assertEqual(self.helper_str_zfill(bitstr), bm.tostring())
def test_str(self): """ Test BitMap: create """ for bitstr in self.v_str: bm = BitMap.fromstring(bitstr) self.assertEqual(self.helper_str_zfill(bitstr), bm.tostring())
def historical_data_handler(msg): global newDataList if ("finished" in str(msg.date)) == False: new_symbol = new_symbolinput[msg.reqId] data = [] data.append(new_symbol) data.append(strftime("%Y-%m-%d %H:%M:%S", localtime(int(msg.date)))) data.append(msg.open) data.append(msg.high) data.append(msg.low) data.append(msg.close) data.append(msg.volume) newDataList.append(data) print data else: # find if gaps exits between the lowest and highest points arrayList = np.array(newDataList) highs = arrayList[:, 3].astype(np.float) lows = arrayList[:, 4].astype(np.float) highest = max(highs) lowest = min(lows) num_slots = int((highest - lowest) * 1000) bm = BitMap.fromstring("1" * num_slots) # print bm.tostring() gap_exits = None for i in range(0, len(arrayList)): for i in range(int((lows[i] - lowest) * 1000), int((highs[i] - lowest) * 1000)): bm.flip(i) if bm.count() > 0: gap_exits = True print ( "INVALIDATED: Gap exits before MEJT AM sequence, no prediction given!" + str(newDataList[bm.nonzero()[0]]) ) # 1. Determine the MEJT reference bar am_o = newDataList[-3][2] am_h = newDataList[-3][3] am_l = newDataList[-3][4] am_c = newDataList[-3][5] am1_o = newDataList[-2][2] am1_h = newDataList[-2][3] am1_l = newDataList[-2][4] am1_c = newDataList[-2][5] am2_o = newDataList[-1][2] am2_h = newDataList[-1][3] am2_l = newDataList[-1][4] am2_c = newDataList[-1][5] # The default reference line is am0, but if am1 or am2 has a lower low and higher high # then it is the RL reference_line = 0 if am1_l < am_l and am1_h > am_h: reference_line = 1 if am2_l < am_l and am2_h > am_h and am2_l < am1_l and am2_h > am1_h: reference_line = 2 print ( "Reference line is AM+" + str(reference_line) + " Time(Local): " + str(newDataList[reference_line - 3][1]) )