def test_get_times(self): """Testing converting a string of times into a list of Time namedtuples""" raw_simple = '7:00\n12:00\n15:00\n18:00\n22:00' raw_complex = '0:0\n00000000001:00000\n18:00000001\n22:59\n23:00\n1:45\n00:00\n23:59\n1:01\n01:00\n01:02\n11:32' list_simple = [ utils.Time(hour=7, minute=0), utils.Time(hour=12, minute=0), utils.Time(hour=15, minute=0), utils.Time(hour=18, minute=0), utils.Time(hour=22, minute=0) ] list_complex = [ utils.Time(hour=0, minute=0), utils.Time(hour=0, minute=0), utils.Time(hour=1, minute=0), utils.Time(hour=1, minute=0), utils.Time(hour=1, minute=1), utils.Time(hour=1, minute=2), utils.Time(hour=1, minute=45), utils.Time(hour=11, minute=32), utils.Time(hour=18, minute=1), utils.Time(hour=22, minute=59), utils.Time(hour=23, minute=0), utils.Time(hour=23, minute=59) ] self.assertEqual(utils.get_times(raw_simple), list_simple) self.assertEqual(utils.get_times(raw_complex), list_complex)
def main(): t0 = get_times() #Capture the data if args.iterations is None: cap = cpd(nsamples=100000, divisor=args.divisor, volt_range=args.volt_range, nblocks=args.nblocks, dual_mode=True) print(cap.shape) else: cap=[] for i in range(args.iterations): cap.append(cpd(divisor=args.divisor, volt_range=args.volt_range, nblocks=args.nblocks, dual_mode=True)) print('completed {} captures'.format(i+1)) tf = get_times() cap = np.array(cap).reshape(args.iterations, 2, -1, 100000) cap = cap.transpose([1,0,2,3]).copy() cap.shape = (2, -1, 100000) #Organize real and complex components #cap = organize_caps(cap, args) #test with a histogram #test_hist(cap) # Compute coordintes before and after data capture, store in dict coords_0 = get_pos(args, t0) coords_f = get_pos(args, tf) np.savez(args.path + '\captures' + args.file_name , real=cap[0], image=cap[1], t0=t0, tf=tf, coords_0=coords_0, coords_f=coords_f)
def _timed_medias(self, media_count=None, with_pbar=False, timeframe=None): seen = set() start_time, end_time = get_times(timeframe) for page in self.pages(media_count=media_count, with_pbar=with_pbar): for media in page['entry_data'][self._page_name][0][ self._section_name]['media']['nodes']: media_date = datetime.date.fromtimestamp(media['date']) if start_time >= media_date >= end_time: if media['id'] in seen: return yield media seen.add(media['id']) elif media_date < end_time: return
def write_to_log(self, conn, t1, t2, d1, d2, data): logger = Log._instance.logger # 获取到日志开关不为True时,移除处理器,不再将数据记录到文件中 if not self.log_switch: logger.remove_my_handler() # if not self.user: # self.user = get_username() # if not self.tid: # self.tid = create_transaction_id() logger.debug("", extra={ 'times': utils.get_times(), 'node': utils.get_global_dict_value(conn), 't1': t1, 't2': t2, 'd1': d1, 'd2': d2, 'data': data })
def test_get_times(self): times = utils.get_times(self.link) self.assertEqual(times, 'Monday, Nov 27, 10:00 AM - 11:00 AM')
def load_config(path): """ Load the configuration file from path and set defaults if not given. The configuration is set to the CONFIG global variable. :type path: str :param path: path to the conf file """ global CONFIG conf = configparser.ConfigParser() conf.read(path) CONFIG = { 'basic': { 'dm_errors': conf['basic'].getboolean('dm_errors', True), 'units': conf['basic'].get('units', 'us'), 'tweet_location': conf['basic'].getboolean('tweet_location', True), 'hashtag': conf['basic'].get('hashtag', '#MorrisWeather'), 'refresh': conf['basic'].getint('refresh', 3), 'strings': conf['basic'].get('strings', 'strings.yml') }, 'scheduled_times': { 'forecast': utils.parse_time_string(conf['scheduled times'].get('forecast', '6:00')), 'conditions': utils.get_times(conf['scheduled times'].get('conditions', '7:00\n12:00\n15:00\n18:00\n22:00')) }, 'default_location': models.WeatherLocation(lat=conf['default location'].getfloat('lat', 45.585), lng=conf['default location'].getfloat('lng', -95.91), name=conf['default location'].get('name', 'Morris, MN')), 'variable_location': { 'enabled': conf['variable location'].getboolean('enabled', False), 'user': conf['variable location'].get('user', 'BrianMitchL'), 'unnamed_location_name': conf['variable location'].get('unnamed_location_name', 'The Wilderness') }, 'log': { 'enabled': conf['log'].getboolean('enabled', True), 'log_path': conf['log'].get('log_path', os.path.expanduser('~') + '/weatherBot.log') }, 'throttles': { 'default': conf['throttles'].getint('default', 120), 'wind-chill': conf['throttles'].getint('wind-chill', 120), 'medium-wind': conf['throttles'].getint('medium-wind', 180), 'heavy-wind': conf['throttles'].getint('heavy-wind', 120), 'fog': conf['throttles'].getint('fog', 180), 'cold': conf['throttles'].getint('cold', 120), 'hot': conf['throttles'].getint('hot', 120), 'dry': conf['throttles'].getint('dry', 120), 'heavy-rain': conf['throttles'].getint('heavy-rain', 60), 'moderate-rain': conf['throttles'].getint('moderate-rain', 60), 'light-rain': conf['throttles'].getint('light-rain', 90), 'very-light-rain': conf['throttles'].getint('very-light-rain', 120), 'heavy-snow': conf['throttles'].getint('heavy-snow', 60), 'moderate-snow': conf['throttles'].getint('moderate-snow', 60), 'light-snow': conf['throttles'].getint('light-snow', 90), 'very-light-snow': conf['throttles'].getint('very-light-snow', 120), 'heavy-sleet': conf['throttles'].getint('heavy-sleet', 45), 'moderate-sleet': conf['throttles'].getint('moderate-sleet', 60), 'light-sleet': conf['throttles'].getint('light-sleet', 90), 'very-light-sleet': conf['throttles'].getint('very-light-sleet', 120), 'heavy-hail': conf['throttles'].getint('heavy-hail', 15), 'moderate-hail': conf['throttles'].getint('moderate-hail', 15), 'light-hail': conf['throttles'].getint('light-hail', 20), 'very-light-hail': conf['throttles'].getint('very-light-hail', 30) } }
def load_config(path): """ Load the configuration file from path and set defaults if not given. The configuration is set to the CONFIG global variable. :type path: str :param path: path to the conf file """ global CONFIG conf = configparser.ConfigParser() conf.read(path) CONFIG = { 'basic': { 'dm_errors': conf['basic'].getboolean('dm_errors', True), 'units': conf['basic'].get('units', 'us'), 'tweet_location': conf['basic'].getboolean('tweet_location', True), 'hashtag': conf['basic'].get('hashtag', '#MorrisWeather'), 'refresh': conf['basic'].getint('refresh', 3), 'strings': conf['basic'].get('strings', 'strings.yml') }, 'scheduled_times': { 'forecast': utils.parse_time_string(conf['scheduled times'].get('forecast', '6:00')), 'conditions': utils.get_times(conf['scheduled times'].get('conditions', '7:00\n12:00\n15:00\n18:00\n22:00')) }, 'default_location': models.WeatherLocation(lat=conf['default location'].getfloat('lat', 45.585), lng=conf['default location'].getfloat('lng', -95.91), name=conf['default location'].get('name', 'Morris, MN')), 'variable_location': { 'enabled': conf['variable location'].getboolean('enabled', False), 'user': conf['variable location'].get('user', 'BrianMitchL') }, 'log': { 'enabled': conf['log'].getboolean('enabled', True), 'log_path': conf['log'].get('log_path', os.path.expanduser('~') + '/weatherBot.log') }, 'throttles': { 'default': conf['throttles'].getint('default', 120), 'wind-chill': conf['throttles'].getint('wind-chill', 120), 'medium-wind': conf['throttles'].getint('medium-wind', 180), 'heavy-wind': conf['throttles'].getint('heavy-wind', 120), 'fog': conf['throttles'].getint('fog', 180), 'cold': conf['throttles'].getint('cold', 120), 'hot': conf['throttles'].getint('hot', 120), 'dry': conf['throttles'].getint('dry', 120), 'heavy-rain': conf['throttles'].getint('heavy-rain', 60), 'moderate-rain': conf['throttles'].getint('moderate-rain', 60), 'light-rain': conf['throttles'].getint('light-rain', 90), 'very-light-rain': conf['throttles'].getint('very-light-rain', 120), 'heavy-snow': conf['throttles'].getint('heavy-snow', 60), 'moderate-snow': conf['throttles'].getint('moderate-snow', 60), 'light-snow': conf['throttles'].getint('light-snow', 90), 'very-light-snow': conf['throttles'].getint('very-light-snow', 120), 'heavy-sleet': conf['throttles'].getint('heavy-sleet', 45), 'moderate-sleet': conf['throttles'].getint('moderate-sleet', 60), 'light-sleet': conf['throttles'].getint('light-sleet', 90), 'very-light-sleet': conf['throttles'].getint('very-light-sleet', 120), 'heavy-hail': conf['throttles'].getint('heavy-hail', 15), 'moderate-hail': conf['throttles'].getint('moderate-hail', 15), 'light-hail': conf['throttles'].getint('light-hail', 20), 'very-light-hail': conf['throttles'].getint('very-light-hail', 30) } }
from bs4 import BeautifulSoup import sys import utils html_filename = './AWS re_Invent 2017.htm' if (len(sys.argv) > 1): html_filename = sys.argv[1] soup = utils.read_main_html(html_filename) links = soup.findAll('a', attrs={'class':'openInPopup'}) for link in links: session_name = utils.get_session_name(link) venue = utils.get_venue(link) session_type = utils.get_session_type(link) session_time = utils.get_times(link) print(utils.print_row(session_name, venue, session_type, session_time))
def test_drbd_quorum(self): if len(self.conn.list_vplx_ssh) != 3: utils.prt_log( '', f"Please make sure there are three nodes for this test", 2) sp = self.get_sp() resource = "res_quorum" test_times = self.config.get_test_times() use_case = self.config.get_use_case() vtel_conn = None if None not in self.conn.list_vplx_ssh: vtel_conn = self.conn.list_vplx_ssh[0] self.clean_dmesg() # utils.prt_log(None, f"Start to install software ...", 0) # self.install_software() # TODO 可优化,使用 LINSTOR API 代码 install_obj = action.InstallSoftware(vtel_conn) install_obj.update_pip() install_obj.install_vplx() self.create_linstor_resource(vtel_conn, sp, resource) stor_obj = action.Stor(vtel_conn) utils.prt_log('', f"Check DRBD quorum...", 0) if not stor_obj.check_drbd_quorum(resource): utils.prt_log(vtel_conn, f'Abnormal quorum status of {resource}', 1) self.get_log() self.delete_linstor_resource(vtel_conn, sp, resource) utils.prt_log('', f"Finished to collect dmesg and exit testing ...", 2) if not self.cycle_check_drbd_status(resource): self.get_log() self.delete_linstor_resource(vtel_conn, sp, resource) utils.prt_log('', f"Finished to collect dmesg and exit testing ...", 2) device_name = stor_obj.get_device_name(resource) device_list = [ vplx_config["private_ip"]["device"] for vplx_config in self.vplx_configs ] if use_case == 1: test_conn_list = zip( self.conn.list_vplx_ssh, self.conn.list_vplx_ssh[1:] + self.conn.list_vplx_ssh[:1]) mode_total_test_times = 3 if use_case == 2: test_conn_list = [ (self.conn.list_vplx_ssh[0], self.conn.list_vplx_ssh[1]), (self.conn.list_vplx_ssh[2], self.conn.list_vplx_ssh[1]) ] mode_total_test_times = 2 device_list.pop(1) mode_times = 0 total_times = mode_total_test_times * test_times for conn_list in test_conn_list: device = device_list.pop(0) node_a = utils.get_global_dict_value(conn_list[0]) node_b = utils.get_global_dict_value(conn_list[1]) stor_a = action.Stor(conn_list[0]) stor_b = action.Stor(conn_list[1]) ip_a = action.IpService(conn_list[0]) dd_a = action.RWData(conn_list[0]) dd_b = action.RWData(conn_list[1]) mode_str = f"\nMode:({node_a}, {node_b}). Mode expect test times: {mode_total_test_times}." utils.prt_log('', mode_str, 0) for i in range(test_times): times = utils.get_times() + 1 utils.set_times(times) utils.prt_log( '', f"\n{mode_str} test times: {i + 1}. Current test times: {times}. Expect test times: {total_times}.", 0) stor_a.primary_drbd(resource) utils.prt_log(conn_list[0], f"Primary resource on {node_a} ...", 0) time.sleep(3) thread1 = threading.Thread(target=dd_a.dd_operation, args=(device_name, ), name="thread1") thread2 = threading.Thread(target=ip_a.down_device, args=(device, ), name="thread2") thread3 = threading.Thread(target=dd_b.dd_operation, args=(device_name, ), name="thread3") thread4 = threading.Thread(target=stor_a.secondary_drbd, args=(resource, ), name="thread4") thread1.start() time.sleep(20) thread2.start() utils.prt_log(conn_list[0], f"Down {device} on {node_a} ...", 0) thread2.join() time.sleep(3) stor_b.primary_drbd(resource) utils.prt_log(conn_list[1], f"Primary resource on {node_b} ...", 0) time.sleep(3) thread3.start() time.sleep(10) resource_status_result = stor_a.get_drbd_status(resource) if check_drbd_no_quorum(conn_list[0], resource_status_result): kill_dd(conn_list[0], device_name) if thread1.is_alive(): stop_thread(thread1) else: utils.prt_log(conn_list[0], f"Configuration 'quorum:no' not exist ...", 0) self.get_log() self.email.send_autotest_mail() utils.prt_log( '', f"Finished to collect dmesg and exit testing ...", 2) thread4.start() utils.prt_log(conn_list[0], f"Secondary resource on {node_a} ...", 0) thread4.join() thread1.join() time.sleep(10) kill_dd(conn_list[1], device_name) time.sleep(5) if thread3.is_alive(): stop_thread(thread3) time.sleep(5) thread3.join() ip_a.up_device(device) utils.prt_log(conn_list[0], f"Up {device} on {node_a} ...", 0) ip_a.netplan_apply() time.sleep(5) if not self.cycle_check_drbd_status(resource): self.get_log() stor_b.secondary_drbd(resource) self.delete_linstor_resource(vtel_conn, sp, resource) self.email.send_autotest_mail() utils.prt_log( '', f"Finished to collect dmesg and exit testing ...", 2) stor_b.secondary_drbd(resource) utils.prt_log(conn_list[1], f"Secondary resource on {node_b} ...", 0) if times == mode_times * test_times + 1: self.get_log() mode_times = mode_times + 1 utils.prt_log('', f"Success. Wait 3 minutes.", 0) time.sleep(180) self.delete_linstor_resource(vtel_conn, sp, resource) self.email.send_autotest_mail()