Python time.time() Examples
The following are 30
code examples of time.time().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
time
, or try the search function
.

Example #1
Source File: multiprocessor.py From svviz with MIT License | 11 votes |
def __init__(self, name=""): self.barsToProgress = {} self.t0 = time.time() self.timeRemaining = "--" self.status = "+" self.name = name self.lastRedraw = time.time() self.isatty = sys.stdout.isatty() try: self.handleResize(None,None) signal.signal(signal.SIGWINCH, self.handleResize) self.signal_set = True except: self.term_width = 79
Example #2
Source File: __init__.py From aegea with Apache License 2.0 | 9 votes |
def __new__(cls, t, snap=0): if isinstance(t, (str, bytes)) and t.isdigit(): t = int(t) if not isinstance(t, (str, bytes)): from dateutil.tz import tzutc return datetime.fromtimestamp(t // 1000, tz=tzutc()) try: units = ["weeks", "days", "hours", "minutes", "seconds"] diffs = {u: float(t[:-1]) for u in units if u.startswith(t[-1])} if len(diffs) == 1: # Snap > 0 governs the rounding of units (hours, minutes and seconds) to 0 to improve cache performance snap_units = {u.rstrip("s"): 0 for u in units[units.index(list(diffs)[0]) + snap:]} if snap else {} snap_units.pop("day", None) snap_units.update(microsecond=0) ts = datetime.now().replace(**snap_units) + relativedelta(**diffs) cls._precision[ts] = snap_units return ts return dateutil_parse(t) except (ValueError, OverflowError, AssertionError): raise ValueError('Could not parse "{}" as a timestamp or time delta'.format(t))
Example #3
Source File: flow_oa.py From incubator-spot with Apache License 2.0 | 7 votes |
def start(self): #################### start = time.time() #################### self._create_folder_structure() self._clear_previous_executions() self._add_ipynb() self._get_flow_results() self._add_network_context() self._add_geo_localization() self._add_reputation() self._create_flow_scores() self._get_oa_details() self._ingest_summary() ################## end = time.time() print(end - start) ##################
Example #4
Source File: gui.py From RF-Monitor with GNU General Public License v2.0 | 6 votes |
def __on_rec(self, recording): timestamp = time.time() for monitor in self._monitors: if not recording: monitor.set_level(None, timestamp, None) monitor.set_recording(recording, timestamp) if recording: self.__on_start() else: while self._push.hasFailed(): resp = wx.MessageBox('Web push has failed, retry?', 'Warning', wx.OK | wx.CANCEL | wx.ICON_WARNING) if resp == wx.OK: busy = wx.BusyInfo('Pushing...', self) self._push.send_failed(self._settings.get_push_uri()) del busy else: self._push.clear_failed() self._warnedPush = False self.__set_timeline()
Example #5
Source File: study_robot.py From 21tb_robot with MIT License | 6 votes |
def log(info): """simple log""" print time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), info sys.stdout.flush()
Example #6
Source File: study_robot.py From 21tb_robot with MIT License | 6 votes |
def run(self): """入口""" s = time.time() course_list = [] with open('study.list') as f: for course in f: course_list.append(course.strip()) self.do_login() for course_id in course_list: try: self.study(course_id) except Exception as e: log("exception occured, study next..") cost = int(time.time() - s) log('main end, cost: %ss' % cost)
Example #7
Source File: proxy_oa.py From incubator-spot with Apache License 2.0 | 6 votes |
def start(self): #################### start = time.time() #################### self._create_folder_structure() self._clear_previous_executions() self._add_ipynb() self._get_proxy_results() self._add_reputation() self._add_iana() self._add_network_context() self._create_proxy_scores_csv() self._get_oa_details() self._ingest_summary() ################## end = time.time() print(end - start) ##################
Example #8
Source File: dns_oa.py From incubator-spot with Apache License 2.0 | 6 votes |
def start(self): #################### start = time.time() #################### self._clear_previous_executions() self._create_folder_structure() self._add_ipynb() self._get_dns_results() self._add_tld_column() self._add_reputation() self._add_hh_column() self._add_iana() self._add_network_context() self._create_dns_scores() self._get_oa_details() self._ingest_summary() ################## end = time.time() print(end - start) ##################
Example #9
Source File: dns_oa.py From incubator-spot with Apache License 2.0 | 6 votes |
def _ingest_summary(self): # get date parameters. yr = self._date[:4] mn = self._date[4:6] dy = self._date[6:] self._logger.info("Getting ingest summary data for the day") ingest_summary_cols = ["date","total"] result_rows = [] df_filtered = pd.DataFrame() query_to_load = (""" SELECT frame_time, COUNT(*) as total FROM {0}.{1} WHERE y={2} AND m={3} AND d={4} AND unix_tstamp IS NOT NULL AND frame_time IS NOT NULL AND frame_len IS NOT NULL AND dns_qry_name IS NOT NULL AND ip_src IS NOT NULL AND (dns_qry_class IS NOT NULL AND dns_qry_type IS NOT NULL AND dns_qry_rcode IS NOT NULL ) GROUP BY frame_time; """).format(self._db,self._table_name, yr, mn, dy) results = impala.execute_query_as_list(query_to_load) df = pd.DataFrame(results) # Forms a new dataframe splitting the minutes from the time column df_new = pd.DataFrame([["{0}-{1}-{2} {3}:{4}".format(yr, mn, dy,\ val['frame_time'].replace(" "," ").split(" ")[3].split(":")[0].zfill(2),\ val['frame_time'].replace(" "," ").split(" ")[3].split(":")[1].zfill(2)),\ int(val['total']) if not math.isnan(val['total']) else 0 ] for key,val in df.iterrows()],columns = ingest_summary_cols) #Groups the data by minute sf = df_new.groupby(by=['date'])['total'].sum() df_per_min = pd.DataFrame({'date':sf.index, 'total':sf.values}) df_final = df_filtered.append(df_per_min, ignore_index=True).to_records(False,False) if len(df_final) > 0: query_to_insert=(""" INSERT INTO {0}.dns_ingest_summary PARTITION (y={1}, m={2}, d={3}) VALUES {4}; """).format(self._db, yr, mn, dy, tuple(df_final)) impala.execute_query(query_to_insert)
Example #10
Source File: utils.py From jumpserver-python-sdk with GNU General Public License v2.0 | 6 votes |
def to_unixtime(time_string, format_string): with _STRPTIME_LOCK: return int(calendar.timegm(time.strptime(str(time_string), format_string)))
Example #11
Source File: display.py From vergeml with MIT License | 6 votes |
def _calc_it_per_sec(self): now = time.time() if not self.last_it: self.last_it.append(now) else: self.last_it.append(now) if len(self.last_it) >= 100: self.last_it = self.last_it[-100:] # smooth it/sec intervals = list(map(lambda t: t[1] - t[0], zip(self.last_it[:-1], self.last_it[1:]))) delta = sum(intervals) / len(intervals) if delta != 0.: it_per_sec = 1.0 / delta if it_per_sec > 1_000_00: self.it_per_sec = "{}M".format(int(it_per_sec/1_000_000)) elif it_per_sec > 1_000: self.it_per_sec = "{}K".format(int(it_per_sec/1_000)) else: self.it_per_sec = "{:.2f}".format(it_per_sec) # 6 characters so the progress bar is the same size self.it_per_sec = self.it_per_sec.rjust(6) # self.last_it = now
Example #12
Source File: asthama_search.py From pepper-robot-programming with MIT License | 6 votes |
def _capture2dImage(self, cameraId): # Capture Image in RGB # WARNING : The same Name could be used only six time. strName = "capture2DImage_{}".format(random.randint(1,10000000000)) clientRGB = self.video_service.subscribeCamera(strName, cameraId, AL_kVGA, 11, 10) imageRGB = self.video_service.getImageRemote(clientRGB) imageWidth = imageRGB[0] imageHeight = imageRGB[1] array = imageRGB[6] image_string = str(bytearray(array)) # Create a PIL Image from our pixel array. im = Image.frombytes("RGB", (imageWidth, imageHeight), image_string) # Save the image. image_name_2d = "images/img2d-" + str(self.imageNo2d) + ".png" im.save(image_name_2d, "PNG") # Stored in images folder in the pwd, if not present then create one self.imageNo2d += 1 im.show() return
Example #13
Source File: DataManager.py From Caffe-Python-Data-Layer with BSD 2-Clause "Simplified" License | 6 votes |
def load_all(self): """The function to load all data and labels Give: data: the list of raw data, needs to be decompressed (e.g., raw JPEG string) labels: numpy array, with each element is a string """ start = time.time() print("Start Loading Data from BCF {}".format( 'MEMORY' if self._bcf_mode == 'MEM' else 'FILE')) self._labels = np.loadtxt(self._label_fn).astype(str) if self._bcf.size() != self._labels.shape[0]: raise Exception("Number of samples in data" "and labels are not equal") else: for idx in range(self._bcf.size()): datum_str = self._bcf.get(idx) self._data.append(datum_str) end = time.time() print("Loading {} samples Done: Time cost {} seconds".format( len(self._data), end - start)) return self._data, self._labels
Example #14
Source File: cli.py From RF-Monitor with GNU General Public License v2.0 | 6 votes |
def __on_event(self): event = self._queue.get() if event.type == Events.SCAN_ERROR: self.__on_scan_error(event.data) elif event.type == Events.SCAN_DATA: self.__on_scan_data(event.data) elif event.type == Events.SERVER_ERROR: self.__on_server_error(event.data) elif event.type == Events.GPS_ERROR: self.__std_err(event.data['msg']) self.__restart_gps() elif event.type == Events.GPS_WARN: self.__std_err(event.data['msg']) elif event.type == Events.GPS_TIMEOUT: self.__std_err(event.data['msg']) self.__restart_gps() elif event.type == Events.GPS_LOC: self._location = event.data['loc'] elif event.type == Events.PUSH_ERROR: if not self._warnedPush: self._warnedPush = True self.__std_err('Push failed:\n\t' + event.data['msg']) else: time.sleep(0.01)
Example #15
Source File: simplify_nq_data.py From natural-questions with Apache License 2.0 | 6 votes |
def main(_): """Runs `text_utils.simplify_nq_example` over all shards of a split. Prints simplified examples to a single gzipped file in the same directory as the input shards. """ split = os.path.basename(FLAGS.data_dir) outpath = os.path.join(FLAGS.data_dir, "simplified-nq-{}.jsonl.gz".format(split)) with gzip.open(outpath, "wb") as fout: num_processed = 0 start = time.time() for inpath in glob.glob(os.path.join(FLAGS.data_dir, "nq-*-??.jsonl.gz")): print("Processing {}".format(inpath)) with gzip.open(inpath, "rb") as fin: for l in fin: utf8_in = l.decode("utf8", "strict") utf8_out = json.dumps( text_utils.simplify_nq_example(json.loads(utf8_in))) + u"\n" fout.write(utf8_out.encode("utf8")) num_processed += 1 if not num_processed % 100: print("Processed {} examples in {}.".format(num_processed, time.time() - start))
Example #16
Source File: __init__.py From aegea with Apache License 2.0 | 6 votes |
def wait_for_port(host, port, timeout=600, print_progress=True): if print_progress: sys.stderr.write("Waiting for {}:{}...".format(host, port)) sys.stderr.flush() start_time = time.time() while True: try: socket.socket().connect((host, port)) if print_progress: sys.stderr.write(GREEN("OK") + "\n") return except Exception: time.sleep(1) if print_progress: sys.stderr.write(".") sys.stderr.flush() if time.time() - start_time > timeout: raise
Example #17
Source File: robot_velocity_caliberation.py From pepper-robot-programming with MIT License | 6 votes |
def moveForward(motion_service): X = 1 # forward Y = 0.0 Theta = 0.0 print "Movement Starting" t0= time.time() # Blocking call possible = motion_service.moveTo(X, Y, Theta) t1 = time.time() timeDiff = t1 -t0 timeDiff *= 1000 if not possible: return -1 # if not possible: # print "Interruption case Time : ",timeDiff # else: # print "Journey over Time : ",timeDiff return timeDiff
Example #18
Source File: asthama_search.py From pepper-robot-programming with MIT License | 6 votes |
def _capture3dImage(self): # Depth Image in RGB # WARNING : The same Name could be used only six time. strName = "capture3dImage_{}".format(random.randint(1,10000000000)) clientRGB = self.video_service.subscribeCamera(strName, AL_kDepthCamera, AL_kQVGA, 11, 10) imageRGB = self.video_service.getImageRemote(clientRGB) imageWidth = imageRGB[0] imageHeight = imageRGB[1] array = imageRGB[6] image_string = str(bytearray(array)) # Create a PIL Image from our pixel array. im = Image.frombytes("RGB", (imageWidth, imageHeight), image_string) # Save the image. image_name_3d = "images/img3d-" + str(self.imageNo3d) + ".png" im.save(image_name_3d, "PNG") # Stored in images folder in the pwd, if not present then create one self.imageNo3d += 1 im.show() return
Example #19
Source File: asthama_search.py From pepper-robot-programming with MIT License | 6 votes |
def _startImageCapturingAtGraphNode(self): amntY = 0.3 xdir = [-0.5, 0, 0.5] cameraId = 0 for idx,amntX in enumerate(xdir): self._moveHead(amntX, amntY) time.sleep(0.1) self._checkIfAsthamaInEnvironment(cameraId) if self.pumpFound : # Setting rotation angle of body towards head theta = 0 if idx == 0: # LEFT theta = math.radians(-45) if idx == 2: # RIGHT theta = math.radians(45) self.pumpAngleRotation = theta return "KILLING GRAPH SEARCH : PUMP FOUND" self._moveHead(0, 0) # Bringing to initial view return
Example #20
Source File: multiprocessor.py From svviz with MIT License | 5 votes |
def updateTimeRemaining(self, completed, total): t = time.time() elapsed = t - self.t0 if elapsed == 0 or completed == 0: return "--" rate = completed/float(elapsed) remaining = total - completed t_remaining = remaining / rate #print "\n", total, completed, elapsed, rate, remaining #return t_remaining # in seconds self.timeRemaining = formatTime(t_remaining)
Example #21
Source File: util.py From EDeN with MIT License | 5 votes |
def timeit(method): """Time decorator.""" def timed(*args, **kw): ts = time.time() result = method(*args, **kw) te = time.time() logger.debug('%s %2.2f sec' % (method.__name__, te - ts)) return result return timed
Example #22
Source File: asthama_search.py From pepper-robot-programming with MIT License | 5 votes |
def run(self): self._printLogs("Waiting for the robot to be in wake up position", "OKBLUE") self.motion_service.wakeUp() self.posture_service.goToPosture("StandInit", 0.1) self.create_callbacks() # self.startDLServer() self._addTopic() # graphplots self._initialisePlot() ani = animation.FuncAnimation(self.fig, self._animate, blit=False, interval=500 ,repeat=False) # loop on, wait for events until manual interruption try: # while True: # time.sleep(1) # starting graph plot plt.show() # blocking call hence no need for while(True) except KeyboardInterrupt: self._printLogs("Interrupted by user, shutting down", "FAIL") self._cleanUp() self._printLogs("Waiting for the robot to be in rest position", "FAIL") # self.motion_service.rest() sys.exit(0) return
Example #23
Source File: asthama_search.py From pepper-robot-programming with MIT License | 5 votes |
def capture_image_event(self, value): self._printLogs("Capturing Image : " + str(value), "NORMAL") if str(value) == "2d": cameraId = 0 # DEFAULT TOP self._capture2dImage(cameraId) if str(value) == "3d": self._capture3dImage() time.sleep(1) return
Example #24
Source File: disambiguate.py From svviz with MIT License | 5 votes |
def batchDisambiguate(alnCollections, isd, expectedOrientations, singleEnded=False, flankingRegionCollection=None, maxMultimappingSimilarity=0.9, alnScoreDeltaThreshold=2): t0 = time.time() for alnCollection in alnCollections: scoreAlignmentSetCollection(alnCollection, isd, 0, expectedOrientations, singleEnded=singleEnded, flankingRegionCollection=flankingRegionCollection, maxMultimappingSimilarity=maxMultimappingSimilarity) for alnCollection in alnCollections: disambiguate(alnCollection, singleEnded=singleEnded, alnScoreDeltaThreshold=alnScoreDeltaThreshold) t1 = time.time() logging.info(" Time for disambiguation: {:.2f}s".format(t1-t0))
Example #25
Source File: pairfinder.py From svviz with MIT License | 5 votes |
def domatching(self): t0 = None for i, read in enumerate(self.tomatch):#[:150]): if i % 10000 == 0: if t0 is None: t0 = time.time() elapsed = "Finding mate pairs..." else: t1 = time.time() elapsed = "t={:.1f}s".format(t1-t0) t0 = t1 logging.info(" {:,} of {:,} {}".format(i, len(self.tomatch), elapsed)) if len(self.readsByID[read.qname].reads) < 2: self.findmatch(read)
Example #26
Source File: asthama_search.py From pepper-robot-programming with MIT License | 5 votes |
def _startAsthamaPumpFoundProcedures(self): # After Finding Asthama Pump; Procedures To Follow global PENDING_PHI theta = self.pumpAngleRotation # TEMPORARY RESETING pending_phi = PENDING_PHI PENDING_PHI = 0 self._turnTheta(theta, "TOWARDS ASTHAMA PUMP", withCapture = False) self._showOnTablet() user_msg = "Yaayy ! I found Asthama Pump" self._moveHand() self._makePepperSpeak(user_msg) self.posture_service.goToPosture("StandInit", 0.3) time.sleep(10) # Hide the web view self.tablet_service.hideImage() # TEMPORARY RESETING OVER PENDING_PHI = pending_phi self._turnTheta(-theta, "TOWARDS ORIGINAL DIRECTION", withCapture = False) self.pumpAngleRotation = 0 return
Example #27
Source File: hook.py From apm-python-agent-principle with MIT License | 5 votes |
def func_wrapper(func): @functools.wraps(func) def wrapper(*args, **kwargs): print('start func') start = time.time() result = func(*args, **kwargs) end = time.time() print('spent {}s'.format(end - start)) return result return wrapper
Example #28
Source File: _hook.py From apm-python-agent-principle with MIT License | 5 votes |
def func_wrapper(func): @functools.wraps(func) def wrapper(*args, **kwargs): print('start func') start = time.time() result = func(*args, **kwargs) end = time.time() print('spent {}s'.format(end - start)) return result return wrapper
Example #29
Source File: func_wrapper.py From apm-python-agent-principle with MIT License | 5 votes |
def sleep(n): time.sleep(n) return n
Example #30
Source File: asthama_search.py From pepper-robot-programming with MIT License | 5 votes |
def _moveForward(self, distToMove): X = min(distToMove, ONEUNITDIST) # forward Y = 0.0 Theta = 0.0 x = 0 t0= time.time() # Blocking call a = self.motion_service.moveTo(X, Y, Theta) t1 = time.time() t = t1 -t0 t *= 1000 units = float(t) * (1.0 / TIME_CALIBERATED) # TIME_CALIBERATED is an average time per m length. Need to caliberate according to the flooring. resDist = 0 if units >= 0.2: resDist = units if not a: self._printLogs("# OBSTACLE found in btw, bot moved dist : " + str(resDist), "NORMAL") else: self._printLogs("# Journey Complete : " + str(ONEUNITDIST), "NORMAL") if resDist != 0 : self._startImageCapturingAtGraphNode() # print "dist in m : ",units possible = True # movement possible in direction if units < 0.2: possible = False units = ONEUNITDIST # NOT UPDATING AS OBSTCLE JUST IN FRONT HENCE WE DONT WANT 0 BTW GRID LINES return [possible , units]