def __init__(self): # # 继承基类 DataRecorder.__init__(self) # # -------------------------------------------------- # self.symbol = "rb1610" # self.exchange = "SHFE" self.period_key_list = ['M01', 'M03', 'M05', 'M10', 'M15', 'M30'] self.PERIOD = {} self.PERIOD['M01'] = PERIOD_M01 self.PERIOD['M03'] = PERIOD_M03 self.PERIOD['M05'] = PERIOD_M05 self.PERIOD['M10'] = PERIOD_M10 self.PERIOD['M15'] = PERIOD_M15 self.PERIOD['M30'] = PERIOD_M30 # Bar的时间戳 self.last_dt_bar = {} # 当前累积的Bar self.CntBar = {} # 上一个Bar self.last_bar = {} # # 有效的时间段 self.Section = {} self.Section['S10_beg'] = dt.time(9, 0, 0) self.Section['S10_end'] = dt.time(10, 15, 0) self.Section['S20_beg'] = dt.time(10, 30, 0) self.Section['S20_end'] = dt.time(11, 30, 0) self.Section['S30_beg'] = dt.time(13, 30, 0) self.Section['S30_end'] = dt.time(15, 0, 0) self.Section['S01_beg'] = dt.time(21, 0, 0) self.Section['S01_end'] = dt.time(23, 0, 0) self.Section['S02_beg'] = dt.time(0, 0, 0) self.Section['S02_end'] = dt.time(2, 30, 0)
def __init__(self,camera, now): global fdr global idr global currentTime self.camera = camera self.now = now fdr = DataRecorder() idr = DataRecorder() if not os.path.exists(RGB_path): os.makedirs(RGB_path) if not os.path.exists(GS_path): os.makedirs(GS_path) if not os.path.exists(Otsu_path): os.makedirs(Otsu_path)
def __init__(self): # # 继承基类 DataRecorder.__init__(self) # # -------------------------------------------------- self.tickfilter = False self.period_key_list = [ 'M01', 'M03', 'M05', 'M10', 'M15', 'M30', 'H01', 'D01', 'W01' ] self.PERIOD = {} self.PERIOD['M01'] = PERIOD_M01 self.PERIOD['M03'] = PERIOD_M03 self.PERIOD['M05'] = PERIOD_M05 self.PERIOD['M10'] = PERIOD_M10 self.PERIOD['M15'] = PERIOD_M15 self.PERIOD['M30'] = PERIOD_M30 self.PERIOD['H01'] = PERIOD_H01 self.PERIOD['D01'] = PERIOD_D01 self.PERIOD['W01'] = PERIOD_W01 # Bar的时间戳 self.last_dt_bar = {} # 当前累积的Bar self.CntBar = {} # 上一个Bar self.last_bar = {} # # 获取合约 req = BfGetContractReq(symbol="*", exchange="*") resps = self.GwGetContract(req) symbol_list = [] for resp in resps: print resp self.InsertContract(resp) symbol_list = symbol_list + [resp.symbol] print '*' * 60 # # 根据合约初始化 for symbol in symbol_list: if symbol not in self.last_dt_bar.keys(): self.last_dt_bar[symbol] = {} self.CntBar[symbol] = {} self.last_bar[symbol] = {} dt_now = dt.datetime.now() for k in self.period_key_list: self.last_dt_bar[symbol][k] = dt.datetime( dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / int(k[1:]) * int(k[1:]), 0) self.CntBar[symbol][k] = BfBarData() self.last_bar[symbol][k] = BfBarData()
def OnGotContracts(self, response): # # 继承基类 DataRecorder.OnGotContracts(self, response) # # 获取合约 req = BfGetContractReq(symbol="*", exchange="*") resps = self.GwGetContract(req) symbol_list = [] for resp in resps: print resp self.InsertContract(resp) symbol_list = symbol_list + [resp.symbol] print '*' * 60 # # 根据合约初始化 for symbol in symbol_list: if symbol not in self.last_dt_bar.keys(): self.last_dt_bar[symbol] = {} self.CntBar[symbol] = {} self.last_bar[symbol] = {} dt_now = dt.datetime.now() for k in self.period_key_list: self.last_dt_bar[symbol][k] = dt.datetime( dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / int(k[1:]) * int(k[1:]), 0) self.CntBar[symbol][k] = BfBarData() self.last_bar[symbol][k] = BfBarData()
def __init__(self): # # 继承基类 DataRecorder.__init__(self) # # -------------------------------------------------- self.tickfilter = False self.period_key_list = ['M01', 'M03', 'M05', 'M10', 'M15', 'M30', 'H01', 'D01', 'W01'] self.PERIOD = {} self.PERIOD['M01'] = PERIOD_M01 self.PERIOD['M03'] = PERIOD_M03 self.PERIOD['M05'] = PERIOD_M05 self.PERIOD['M10'] = PERIOD_M10 self.PERIOD['M15'] = PERIOD_M15 self.PERIOD['M30'] = PERIOD_M30 self.PERIOD['H01'] = PERIOD_H01 self.PERIOD['D01'] = PERIOD_D01 self.PERIOD['W01'] = PERIOD_W01 # Bar的时间戳 self.last_dt_bar = {} # 当前累积的Bar self.CntBar = {} # 上一个Bar self.last_bar = {} # # 获取合约 req = BfGetContractReq(symbol="*", exchange="*") resps = self.GwGetContract(req) symbol_list = [] for resp in resps: print resp self.InsertContract(resp) symbol_list = symbol_list + [resp.symbol] print '*' * 60 # # 根据合约初始化 for symbol in symbol_list: if symbol not in self.last_dt_bar.keys(): self.last_dt_bar[symbol] = {} self.CntBar[symbol] = {} self.last_bar[symbol] = {} dt_now = dt.datetime.now() for k in self.period_key_list: self.last_dt_bar[symbol][k] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / int(k[1:]) * int(k[1:]), 0) self.CntBar[symbol][k] = BfBarData() self.last_bar[symbol][k] = BfBarData()
class LogSpeed: def __init__(self, config): self._config = config logging.basicConfig(level=self._config.logging_level) self.logger = logging.getLogger('SpeedTrap.LogSpeed') self.logger.debug("Creating LogSpeed() instance") self._current_max = 0 self._video_recorder = VideoRecorder2(config) self._data_recorder = DataRecorder(config) self._video_recorder.start_recorder() self._current_filename = None self._current_record = False def log_speed(self, speed): self.logger.debug("Entering log_speed()") if self._current_max == 0 and speed == 0: pass elif speed >= self._config.log_threshold: if self.current_record: self._video_recorder.set_speed(speed) if speed > self._current_max: self.logger.debug("Current maximum speed was %s now %s", self._current_max, speed) self._current_max = speed if speed >= self._config.record_threshold: self.logger.debug("Logging speed %s to video", speed) if not self._current_record: self._current_record = True self._current_filename = self._video_recorder.start_recording( speed) elif speed < self._config.log_threshold - 10: file_name = self._video_recorder.stop_recording() if self._current_max >= self._config.log_threshold: self._data_recorder.record(self._current_max, time.localtime(), file_name) self._current_max = 0 self._current_filename = None self.logger.debug("Leaving log_speed()")
def OnGotContracts(self, response): # # 继承基类 DataRecorder.OnGotContracts(self, response) # # 获取合约 req = BfGetContractReq(symbol="*", exchange="*") resps = self.GwGetContract(req) symbol_list = [] for resp in resps: print resp self.InsertContract(resp) symbol_list = symbol_list + [resp.symbol] print '*' * 60 # # 根据合约初始化 for symbol in symbol_list: if symbol not in self.symbol_df.index: sym_df = pd.DataFrame([ re.findall(r'[a-zA-Z]+', symbol), re.findall(r'[0-9]+', symbol) ], index=['symN', 'symC'], columns=[symbol]).T self.symbol_df = self.symbol_df.append(sym_df) print self.symbol_df symN_list = list(set(self.symbol_df['symN'])) for symN in symN_list: if symN not in self.lastPrice_df.keys(): self.lastPrice_df[symN] = pd.DataFrame( 0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.openInterest_df[symN] = pd.DataFrame( 0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.volume_df[symN] = pd.DataFrame( 0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.last_dt_bar[symN] = {} self.CntBar[symN] = {} self.last_bar[symN] = {} for k in self.period_key_list: self.last_dt_bar[symN][k] = dt.datetime( 2016, 1, 1, 0, 0, 0) self.CntBar[symN][k] = BfBarData() self.last_bar[symN][k] = BfBarData()
def OnTick(self, response): # # 继承基类 DataRecorder.OnTick(self, response) # print response dt_now = dt.datetime.strptime( response.actionDate + " " + response.tickTime, "%Y%m%d %H:%M:%S.%f") # print dt_now # # 当前bar时间戳 dt_bar = {} dt_bar['M01'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute, 0) dt_bar['M03'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 3 * 3, 0) dt_bar['M05'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 5 * 5, 0) dt_bar['M10'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 10 * 10, 0) dt_bar['M15'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 15 * 15, 0) dt_bar['M30'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 30 * 30, 0) dt_bar['H01'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, 0, 0) dt_now_shift4 = dt_now + dt.timedelta(hours=4) dt_bar['D01'] = dt.datetime(dt_now_shift4.year, dt_now_shift4.month, dt_now_shift4.day, 0, 0, 0) dt_bar['W01'] = dt_bar['D01'] - dt.timedelta( days=dt_bar['D01'].weekday()) symN = re.findall(r'[a-zA-Z]+', response.symbol)[0] if dt_now not in self.lastPrice_df[symN].index: self.lastPrice_df[symN] = self.lastPrice_df[symN].append( pd.DataFrame(index=[dt_now])) self.openInterest_df[symN] = self.openInterest_df[symN].append( pd.DataFrame(index=[dt_now])) self.volume_df[symN] = self.volume_df[symN].append( pd.DataFrame(index=[dt_now])) self.lastPrice_df[symN].ix[dt_now, response.symbol] = response.lastPrice self.openInterest_df[symN].ix[dt_now, response.symbol] = response.openInterest self.volume_df[symN].ix[dt_now, response.symbol] = response.volume if dt_bar['M01'] != self.last_dt_bar[symN]['M01']: self.Tick_To_M01(symN, dt_bar, response)
def OnTick(self, response): # # 继承基类 DataRecorder.OnTick(self, response) # # -------------------------------------------------- # # 第一次订阅 # if response.symbol not in self.last_dt_bar.keys(): # self.last_dt_bar[response.symbol] = {} # self.CntBar[response.symbol] = {} # self.last_bar[response.symbol] = {} # dt_now = dt.datetime.now() # for k in self.period_key_list: # self.last_dt_bar[response.symbol][k] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, # dt_now.minute / int(k[1:]) * int(k[1:]), 0) # self.CntBar[response.symbol][k] = BfBarData() # self.last_bar[response.symbol][k] = BfBarData() # # 当前时刻 dt_now = dt.datetime.strptime( response.actionDate + " " + response.tickTime, "%Y%m%d %H:%M:%S.%f") # print dt_now # # 当前bar时间戳 dt_bar = {} dt_bar['M01'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute, 0) dt_bar['M03'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 3 * 3, 0) dt_bar['M05'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 5 * 5, 0) dt_bar['M10'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 10 * 10, 0) dt_bar['M15'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 15 * 15, 0) dt_bar['M30'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, dt_now.minute / 30 * 30, 0) dt_bar['H01'] = dt.datetime(dt_now.year, dt_now.month, dt_now.day, dt_now.hour, 0, 0) dt_now_shift4 = dt_now + dt.timedelta(hours=4) dt_bar['D01'] = dt.datetime(dt_now_shift4.year, dt_now_shift4.month, dt_now_shift4.day, 0, 0, 0) dt_bar['W01'] = dt_bar['D01'] - dt.timedelta( days=dt_bar['D01'].weekday()) # print '*'*60 self.Tick_To_M01(dt_bar, response, PERIOD_M01)
def writeCameraStatus(self): global camera global now fdr = DataRecorder() fdr.openFDR() if camera is None: now = datetime.datetime.now() currentTime = str(now.hour)+":"+str(now.minute)+":"+str(now.second) camStatus = [currentTime+"\t\tCamera\t\t\t\tNot Connected.\t\t\tInactive\n"] sys.exit(0) else: now = datetime.datetime.now() currentTime = str(self.now.hour)+":"+str(self.now.minute)+":"+str(self.now.second) camStatus = [currentTime+"\t\tCamera\t\t\t\tOK.\t\t\tActive\n"] fdr.writeToFDR(camStatus) fdr.closeFDR()
def writeCameraStatus(self): global camera global now fdr = DataRecorder() fdr.openFDR() if camera is None: now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str( now.second) camStatus = [ currentTime + "\t\tCamera\t\t\t\tNot Connected.\t\t\tInactive\n" ] sys.exit(0) else: now = datetime.datetime.now() currentTime = str(self.now.hour) + ":" + str( self.now.minute) + ":" + str(self.now.second) camStatus = [currentTime + "\t\tCamera\t\t\t\tOK.\t\t\tActive\n"] fdr.writeToFDR(camStatus) fdr.closeFDR()
def generatePixelData(self): global counter global idr global image_Data global imgh global previous_Height global previous_Width idr = DataRecorder() imgh = 0 colnum = 0 cell_Height = 0 current_Cell_Height = 0 cell_Width = 0 current_Cell_Width = 0 address = Otsu_path+str(counter)+".jpg" image = Image.open(address) imwidth, imheight = image.size pix = image.load() impix = (126, 0, 0) image_Data = [0 for i in xrange(16)] cell_Height = imheight * 0.25 cell_Width = imwidth * 0.25 current_Cell_Height = current_Cell_Height + cell_Height #150 current_Cell_Width = current_Cell_Width + cell_Width #200 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #400 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #600 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #800 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) previous_Height = imgh #150 previous_Width = 0 current_Cell_Width = 0 current_Cell_Height = current_Cell_Height + cell_Height #300 current_Cell_Width = current_Cell_Width + cell_Width #200 colnum = colnum + 1 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #400 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #600 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #800 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) previous_Height = imgh previous_Width = 0 current_Cell_Width = 0 current_Cell_Height = current_Cell_Height + cell_Height #450 current_Cell_Width = current_Cell_Width + cell_Width #200 colnum = colnum + 1 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #400 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #600 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #800 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) previous_Height = imgh previous_Width = 0 current_Cell_Width = 0 current_Cell_Height = current_Cell_Height + cell_Height #600 current_Cell_Width = current_Cell_Width + cell_Width #200 colnum = colnum + 1 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #400 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #600 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) colnum = colnum + 1 current_Cell_Width = current_Cell_Width + cell_Width #800 self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix) previous_Height = imgh previous_Width = 0 colnum = 0 idr.openIDR() data = "" while colnum<16: data = data + str(image_Data[colnum])+"," colnum = colnum + 1 data = data + "?\n" idr.writeToIDR(str(data)) terminators = "%\n%\n%" idr.writeToIDR(terminators) image_Data = None colnum = 0 idr.closeIDR()
def __init__(self, opt): self.session_id = opt.session_id # Initialize camera and window self.cap = cv.VideoCapture(opt.input_device, eval(f'cv.{opt.input_api}')) assert self.cap.isOpened(), 'Failed to initialize video capture!' self.width, self.height = opt.video_width, opt.video_height self.cap.set(cv.CAP_PROP_FRAME_WIDTH, self.width) self.cap.set(cv.CAP_PROP_FRAME_HEIGHT, self.height) self.window_name = 'tutorial' if opt.fullscreen: cv.namedWindow(self.window_name, cv.WINDOW_NORMAL) cv.setWindowProperty(self.window_name, cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN) else: cv.namedWindow(self.window_name) self.width_qr = self.width // 4 self.width_half = self.width // 2 self.width_3qr = self.width // 4 * 3 self.border_margin = round(max(self.width, self.height) * 0.025) # Initialize openpose library import os import sys sys.path.append(os.fspath(opt.op_path / 'python/openpose/Release')) os.environ['PATH'] += f';{os.fspath(opt.op_path/"x64/Release")}' os.environ['PATH'] += f';{os.fspath(opt.op_path/"bin")}' try: import pyopenpose as op except ImportError as e: print('Error: OpenPose library could not be found.') raise e self._op_wrapper = op.WrapperPython() self._op_wrapper.configure({ 'model_folder': os.fspath(opt.op_path / '../models/'), 'model_pose': 'BODY_25', 'number_people_max': 1 }) self._op_wrapper.start() self._datum = op.Datum() # Raw data recorder if not opt.no_save: self.recorder = DataRecorder( (self.width, self.height), 24, f'records/{opt.session_id}/{int(time())}') else: self.recorder = DummyDataRecorder() # Handler of each state self.handlers = { State.Ready: self.handle_ready, State.PoseReady: self.handle_pose_ready, State.PoseMeasuring: self.handle_pose_measuring, State.Finish: self.handle_finish, } # Load assets self.assets = Assets('assets/') self.poses: List[Posture] = [ Pose_01, Pose_02, Pose_03, Pose_04, Pose_05, Pose_06, Pose_08, Pose_09, Pose_10 ] self.poses_ui: List[InformationLayer] = generate_info_layers( self.poses) self.running: bool = True self.state: State = State.Ready self.pose_index_iter: Iterator[int] = iter(range(len(self.poses))) self.current_pose_i: int = 0 self.t_start: float = perf_counter() self.fail_counter = deque([False] * opt.fail_tolerance, maxlen=opt.fail_tolerance) self.angle: float = np.pi self.confidence: float = 0 self.score: int = 0 self.keypoints: np.ndarray = np.array([], np.float32) self.frame: np.ndarray = np.array([], np.uint8)
def __init__(self): # # 继承基类 DataRecorder.__init__(self) # # -------------------------------------------------- self.tickfilter = False self.period_key_list = [ 'M01', 'M03', 'M05', 'M10', 'M15', 'M30', 'H01', 'D01', 'W01' ] self.PERIOD = {} self.PERIOD['M01'] = PERIOD_M01 self.PERIOD['M03'] = PERIOD_M03 self.PERIOD['M05'] = PERIOD_M05 self.PERIOD['M10'] = PERIOD_M10 self.PERIOD['M15'] = PERIOD_M15 self.PERIOD['M30'] = PERIOD_M30 self.PERIOD['H01'] = PERIOD_H01 self.PERIOD['D01'] = PERIOD_D01 self.PERIOD['W01'] = PERIOD_W01 # Bar的时间戳 self.last_dt_bar = {} # 当前累积的Bar self.CntBar = {} # 上一个Bar self.last_bar = {} # 用于储存一个M01之内的DataFrame self.lastPrice_df = {} self.openInterest_df = {} self.volume_df = {} # # 获取合约 req = BfGetContractReq(symbol="*", exchange="*") resps = self.GwGetContract(req) symbol_list = [] for resp in resps: print resp self.InsertContract(resp) symbol_list = symbol_list + [resp.symbol] print '*' * 60 # # 根据合约初始化 self.symbol_df = pd.DataFrame(columns=['symN', 'symC']) for symbol in symbol_list: if symbol not in self.symbol_df.index: sym_df = pd.DataFrame([ re.findall(r'[a-zA-Z]+', symbol), re.findall(r'[0-9]+', symbol) ], index=['symN', 'symC'], columns=[symbol]).T self.symbol_df = self.symbol_df.append(sym_df) print self.symbol_df symN_list = list(set(self.symbol_df['symN'])) for symN in symN_list: if symN not in self.lastPrice_df.keys(): self.lastPrice_df[symN] = pd.DataFrame( 0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.openInterest_df[symN] = pd.DataFrame( 0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.volume_df[symN] = pd.DataFrame( 0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.last_dt_bar[symN] = {} self.CntBar[symN] = {} self.last_bar[symN] = {} for k in self.period_key_list: self.last_dt_bar[symN][k] = dt.datetime( 2016, 1, 1, 0, 0, 0) self.CntBar[symN][k] = BfBarData() self.last_bar[symN][k] = BfBarData()
def __init__(self): # # 继承基类 DataRecorder.__init__(self) # # -------------------------------------------------- self.tickfilter = False self.period_key_list = ['M01', 'M03', 'M05', 'M10', 'M15', 'M30', 'H01', 'D01', 'W01'] self.PERIOD = {} self.PERIOD['M01'] = PERIOD_M01 self.PERIOD['M03'] = PERIOD_M03 self.PERIOD['M05'] = PERIOD_M05 self.PERIOD['M10'] = PERIOD_M10 self.PERIOD['M15'] = PERIOD_M15 self.PERIOD['M30'] = PERIOD_M30 self.PERIOD['H01'] = PERIOD_H01 self.PERIOD['D01'] = PERIOD_D01 self.PERIOD['W01'] = PERIOD_W01 # Bar的时间戳 self.last_dt_bar = {} # 当前累积的Bar self.CntBar = {} # 上一个Bar self.last_bar = {} # 用于储存一个M01之内的DataFrame self.lastPrice_df = {} self.openInterest_df = {} self.volume_df = {} # # 获取合约 req = BfGetContractReq(symbol="*", exchange="*") resps = self.GwGetContract(req) symbol_list = [] for resp in resps: print resp self.InsertContract(resp) symbol_list = symbol_list + [resp.symbol] print '*' * 60 # # 根据合约初始化 self.symbol_df = pd.DataFrame(columns=['symN','symC']) for symbol in symbol_list: if symbol not in self.symbol_df.index: sym_df = pd.DataFrame([re.findall(r'[a-zA-Z]+', symbol), re.findall(r'[0-9]+', symbol)], index=['symN', 'symC'],columns=[symbol]).T self.symbol_df = self.symbol_df.append(sym_df) print self.symbol_df symN_list = list(set(self.symbol_df['symN'])) for symN in symN_list: if symN not in self.lastPrice_df.keys(): self.lastPrice_df[symN] = pd.DataFrame(0, columns=self.symbol_df [self.symbol_df ['symN']==symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.openInterest_df[symN] = pd.DataFrame(0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.volume_df[symN] = pd.DataFrame(0, columns=self.symbol_df[self.symbol_df['symN'] == symN].index, index=[dt.datetime(2016, 1, 1, 0, 0, 0)]) self.last_dt_bar[symN] = {} self.CntBar[symN] = {} self.last_bar[symN] = {} for k in self.period_key_list: self.last_dt_bar[symN][k] = dt.datetime(2016, 1, 1, 0, 0, 0) self.CntBar[symN][k] = BfBarData() self.last_bar[symN][k] = BfBarData()
class iMaze(object): now = datetime.datetime.now() currentDate = str(now.day) + "." + str(now.month) + "." + str(now.year) currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) fdr = DataRecorder() fdr.openFDR() startOfData = "################################# DATE: " + currentDate + " #################################\n" deviceTableHeaders = "Timestamp\tDevice\t\t\t\tStatus\t\t\tValue\n" fdr.writeToFDR(startOfData) fdr.writeToFDR(deviceTableHeaders) finch = pyfinch.Finch() now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) finchStatus = [currentTime + "\t\tFinch\t\t\t\tOK.\t\t\tActive\n"] fdr.writeToFDR(finchStatus) time.sleep(1.0) finch.led(255, 0, 0) now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) ledOneStatus = [currentTime + "\t\tLED_1\t\t\t\tOK.\t\t\t255,0,0 RGB\n"] fdr.writeToFDR(ledOneStatus) time.sleep(1.0) finch.led(0, 255, 0) now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) ledTwoStatus = [currentTime + "\t\tLED_2\t\t\t\tOK.\t\t\t0,255,0 RGB\n"] fdr.writeToFDR(ledTwoStatus) time.sleep(1.0) finch.led(0, 0, 255) now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) ledThreeStatus = [currentTime + "\t\tLED_3\t\t\t\tOK.\t\t\t0,0,255 RGB\n"] fdr.writeToFDR(ledThreeStatus) time.sleep(1.0) finch.buzzer(0.1, 700) now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) buzzerStatus = [currentTime + "\t\tBuzzer\t\t\t\tOK.\t\t\t0.1s,700Hz\n"] fdr.writeToFDR(buzzerStatus) currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) thermometerStatus = [ currentTime + "\t\tThermometer\t\t\tOK.\t\t\t" + str(finch.temperature()) + " C\n" ] fdr.writeToFDR(thermometerStatus) time.sleep(1.0) finch.wheels(1.0, 0) time.sleep(0.1) now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) leftWheelStatus = [currentTime + "\t\tLeft Wheel\t\t\tOK.\t\t\t255m/s\n"] fdr.writeToFDR(leftWheelStatus) finch.wheels(0, 1.0) time.sleep(0.1) now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) rightWheelStatus = [currentTime + "\t\tRight Wheel\t\t\tOK.\t\t\t255m/s\n"] fdr.writeToFDR(rightWheelStatus) finch.wheels(1.0, 1.0) time.sleep(0.5) currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) accelerometerStatus = [ currentTime + "\t\tAccelerometer\t\t\tOK.\t\t\t" + str(finch.acceleration()) + " m/s\n" ] fdr.writeToFDR(accelerometerStatus) finch.idle() now = datetime.datetime.now() currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) finchStatus = [currentTime + "\t\tFinch\t\t\t\tOK.\t\t\tIdle\n"] fdr.writeToFDR(finchStatus) fdr.closeFDR() cam = Camera(now) cam.setCamera() cam.startCamera() cam.writeCameraStatus() imp = ImageProcessing(cam.getCamera(), now) while True: imp.captureRGBImage() imp.convertRGBtoGS() imp.convertGStoOtsu() imp.generatePixelData() classify = DirectionClassifier() direction = classify.predict("IDR.arff") print direction break