| 
									
										
										
										
											2020-02-23 10:30:37 +11:00
										 |  |  | ##################################################### | 
					
						
							|  |  |  | # Copyright (c) Xuanyi Dong [GitHub D-X-Y], 2019.01 # | 
					
						
							|  |  |  | ##################################################### | 
					
						
							| 
									
										
										
										
											2019-09-05 15:07:12 +08:00
										 |  |  | import time, sys | 
					
						
							|  |  |  | import numpy as np | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-30 12:05:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 15:07:12 +08:00
										 |  |  | def time_for_file(): | 
					
						
							| 
									
										
										
										
											2021-03-30 12:05:52 +00:00
										 |  |  |     ISOTIMEFORMAT = "%d-%h-at-%H-%M-%S" | 
					
						
							|  |  |  |     return "{:}".format(time.strftime(ISOTIMEFORMAT, time.gmtime(time.time()))) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 15:07:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def time_string(): | 
					
						
							| 
									
										
										
										
											2021-03-30 12:05:52 +00:00
										 |  |  |     ISOTIMEFORMAT = "%Y-%m-%d %X" | 
					
						
							|  |  |  |     string = "[{:}]".format(time.strftime(ISOTIMEFORMAT, time.gmtime(time.time()))) | 
					
						
							|  |  |  |     return string | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 15:07:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def time_string_short(): | 
					
						
							| 
									
										
										
										
											2021-03-30 12:05:52 +00:00
										 |  |  |     ISOTIMEFORMAT = "%Y%m%d" | 
					
						
							|  |  |  |     string = "{:}".format(time.strftime(ISOTIMEFORMAT, time.gmtime(time.time()))) | 
					
						
							|  |  |  |     return string | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 15:07:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def time_print(string, is_print=True): | 
					
						
							| 
									
										
										
										
											2021-03-30 12:05:52 +00:00
										 |  |  |     if is_print: | 
					
						
							|  |  |  |         print("{} : {}".format(time_string(), string)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def convert_secs2time(epoch_time, return_str=False): | 
					
						
							|  |  |  |     need_hour = int(epoch_time / 3600) | 
					
						
							|  |  |  |     need_mins = int((epoch_time - 3600 * need_hour) / 60) | 
					
						
							|  |  |  |     need_secs = int(epoch_time - 3600 * need_hour - 60 * need_mins) | 
					
						
							|  |  |  |     if return_str: | 
					
						
							|  |  |  |         str = "[{:02d}:{:02d}:{:02d}]".format(need_hour, need_mins, need_secs) | 
					
						
							|  |  |  |         return str | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         return need_hour, need_mins, need_secs | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-05 15:07:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def print_log(print_string, log): | 
					
						
							| 
									
										
										
										
											2021-03-30 12:05:52 +00:00
										 |  |  |     # if isinstance(log, Logger): log.log('{:}'.format(print_string)) | 
					
						
							|  |  |  |     if hasattr(log, "log"): | 
					
						
							|  |  |  |         log.log("{:}".format(print_string)) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         print("{:}".format(print_string)) | 
					
						
							|  |  |  |         if log is not None: | 
					
						
							|  |  |  |             log.write("{:}\n".format(print_string)) | 
					
						
							|  |  |  |             log.flush() |