def delay(type = "basic"): if type in d_delay and d_delay[type] > 0: log("Таймер %s завершен за %s секунд"%(type, floor((curtime() - d_delay[type]) * 10000) / 10000)) d_delay[type] = 0 else: log("Таймер \"%s\" запущен"%(type)) d_delay[type] = curtime()
def calLBP(imageset): ah = np.zeros((59,1)) count=0 for filename in imageset: t = curtime() count+=1 print count matrix = getImageData(filename) vect59x322 = calLBPForSingleImage(matrix) ah = np.hstack((ah, vect59x322)) print curtime()-t ah = ah[:,1:] return ah
def _get_dist_matrix(self, flip_fuse=False, re_ranking=False): self.model.eval() if flip_fuse: print('**** flip fusion based distance matrix ****') if re_ranking: raise NotImplementedError('Not recommended, as it costs too much time.') start = curtime() with torch.no_grad(): if self.opt.eval_phase_num == 1: q_g_dist = - self._compare_images(self.queryloader, self.galleryloader) if flip_fuse: q_g_dist -= self._compare_images(self.queryloader, self.galleryFliploader) q_g_dist -= self._compare_images(self.queryFliploader, self.galleryloader) q_g_dist -= self._compare_images(self.queryFliploader, self.galleryFliploader) q_g_dist /= 4.0 elif self.opt.eval_phase_num == 2: '''phase one''' query_features = self._get_feature(self.queryloader) gallery_features = self._get_feature(self.galleryloader) '''phase two''' q_g_dist = - self._compare_features(query_features, gallery_features) if not flip_fuse: del gallery_features, query_features else: query_flip_features = self._get_feature(self.queryFliploader) q_g_dist -= self._compare_features(query_flip_features, gallery_features) del gallery_features gallery_flip_features = self._get_feature(self.galleryFliploader) q_g_dist -= self._compare_features(query_flip_features, gallery_flip_features) del query_flip_features q_g_dist -= self._compare_features(query_features, gallery_flip_features) del gallery_flip_features, query_features q_g_dist /= 4.0 else: raise ValueError end = curtime() print('it costs {:.0f} s to compute distance matrix' .format(end - start)) return q_g_dist.cpu()
def __init__(self, logfile_path: str) -> None: """ Create output handle :param logfile_path: Path or string file path or "-" for stdout """ # Fail if current working directory does not exist so we don't crash in # standard library path-handling code. try: os.getcwd() except OSError: exit("T: Error: Current working directory does not exist.") if logfile_path == "-": self.logfile = sys.stdout else: # Log file path should be absolute since some processes may run in # different directories: logfile_path = os.path.abspath(logfile_path) self.logfile = _open_logfile(logfile_path) self.logfile_path = logfile_path self.start_time = curtime() self.logtail = deque(maxlen=25) # type: deque # keep last 25 lines self.write("Telepresence {} launched at {}".format( __version__, ctime())) self.write(" {}".format(str_command(sys.argv))) if version_override: self.write(" TELEPRESENCE_VERSION is {}".format(image_version)) elif image_version != __version__: self.write(" Using images version {} (dev)".format(image_version))
def __init__(self, logfile_path: str) -> None: """ Create output handle :param logfile_path: Path or string file path or "-" for stdout """ if logfile_path == "-": self.logfile = sys.stdout else: # Log file path should be absolute since some processes may run in # different directories: logfile_path = os.path.abspath(logfile_path) self.logfile = _open_logfile(logfile_path) self.logfile_path = logfile_path self.start_time = curtime() self.logtail = deque(maxlen=25) # type: deque # keep last 25 lines self.write("Telepresence {} launched at {}".format( __version__, ctime())) self.write(" {}".format(str_command(sys.argv))) if version_override: self.write(" TELEPRESENCE_VERSION is {}".format(image_version)) elif image_version != __version__: self.write(" Using images version {} (dev)".format(image_version))
def main(self, live=True): if live: self.get_urls_to_parse() else: self.parse_functions.update( {Static.DESCRIPTION: self.get_description}) self.get_local_urls() self.collect_articles() print(curtime()) self.reformat_data()
def write(self, message: str, prefix="TEL") -> None: """Write a message to the log.""" if self.logfile.closed: return for sub_message in message.splitlines(): line = "{:6.1f} {} | {}\n".format(curtime() - self.start_time, prefix, sub_message.rstrip()) self.logfile.write(line) self.logtail.append(line) self.logfile.flush()
def move(self): self.x += self.pacex self.y += self.pacey if self.x <= self.r or self.x >= WINDOW_SIDE - self.r: self.revertx() if self.y <= self.r: self.reverty() # if the player missed the ball and this has not been detected yet, # record the death time to use it later to compute when to close the game if self.y >= WINDOW_SIDE - self.r and not self.death_time: self.death_time = curtime()
def reformat_data(self): df = pd.DataFrame().from_dict(self.data).T out = 'scraping\\%s_data scraping_%s.xlsx' % (self.name, str( curtime()).split('.')[0]) df.to_excel(out) for col in self.cleaner['list']: df[col + '_cleaned'] = df[col].apply(lambda x: x if pd.isnull( x) else post_processing_list(x, self.cleaner['list'][col])) for col in self.cleaner['str']: df[col + '_cleaned'] = df[col].apply( lambda x: x if pd.isnull(x) else post_processing_element( x, self.cleaner['str'][col].INLINE)) df.to_excel(out)
def signature(self, time=None, offset=None): """Generate a pygit2.Signature. :param time: (optional) the time for the signature, in UTC seconds. Defaults to current time. :type time: int :param offset: (optional) the time offset for the signature, in minutes. Defaults to the system offset. :type offset: int :returns: a signature :rtype: pygit2.Signature """ offset = offset or (altzone / 60 if daylight else timezone / 60) time = time or int(curtime()) return Signature(self.name, self.email, time, offset)
def signature(name, email, time=None, offset=None): """Convenience method to generate pygit2 signatures. :param name: The name in the signature. :type name: string :param email: The email in the signature. :type email: string :param time: (optional) the time for the signature, in UTC seconds. Defaults to current time. :type time: int :param offset: (optional) the time offset for the signature, in minutes. Defaults to the system offset. :type offset: int :returns: a signature :rtype: pygit2.Signature """ offset = offset or (altzone / 60 if daylight else timezone / 60) time = time or int(curtime()) return Signature(name, email, time, offset)
def main(): Window = pygame.display.set_mode((WINDOW_SIDE, WINDOW_SIDE)) pygame.display.set_caption("bitch please") endtime = 0.0 # load image for bricks brick = pygame.transform.scale(pygame.image.load("skins/brick.png"), (BRICK_WIDTH, BRICK_HEIGHT)) # create game objects angle = radians(randint(-30, 30)) ball = Bullet(WINDOW_SIDE // 2, WINDOW_SIDE - 100, BALL_RADIUS, -BALL_PACE * sin(angle), -BALL_PACE * cos(angle), END_DELAY) board = Board((WINDOW_SIDE - BOARD_WIDTH) // 2, WINDOW_SIDE - 2 * BOARD_HEIGHT, BOARD_WIDTH, BOARD_HEIGHT, BOARD_PACE) bricks = [] cur_pixel_col = 0 cur_pixel_row = 0 for i in range(BRICKS_AMOUNT): if cur_pixel_col + BRICK_WIDTH <= WINDOW_SIDE and cur_pixel_row + BRICK_HEIGHT <= WINDOW_SIDE: bricks.append((cur_pixel_col, cur_pixel_row)) else: cur_pixel_row += BRICK_HEIGHT cur_pixel_col = 0 bricks.append((cur_pixel_col, cur_pixel_row)) cur_pixel_col += BRICK_WIDTH while True: # this cycle is needed to quit the game for action in pygame.event.get(): if action.type == pygame.QUIT: return 0 # 0 represents game closure event. # Numbers -1 and 1 can also be returned (loss and win respectively) ball.move() if ball.check_dead(): # show some offensive text Window.fill((0, 0, 0)) Window.blit( pygame.font.SysFont('Calibri', 225).render(':(', 1, (50, 200, 250)), (230, 180)) pygame.display.update() sleep(1.5) return -1 if check_hit(ball, bricks, board): if not bricks: endtime = curtime() if endtime and curtime() > endtime + END_DELAY: # show some respect Window.fill((0, 0, 0)) Window.blit( pygame.font.SysFont('Calibri', 70).render("mission passed", 1, (250, 250, 250)), (100, 100)) Window.blit( pygame.font.SysFont('Calibri', 30).render("resepct+", 1, (200, 100, 50)), (270, 400)) pygame.display.update() sleep(2.5) return 1 board_control(board) draw(Window, ball, board, bricks, brick)
def check_dead(self): # if current time is greater than the death time plus death delay, return True if self.death_time and curtime() > self.death_time + self.death_delay: return True return False
def format_time(): return strftime("[%H:%M:%S]", gmtime(curtime() + 3600 * 3))
_finpath = os.path.abspath(os.getcwd()) for i in path.split("/")[0:-1]: _finpath += "/" + i #print(_finpath) if not os.path.exists(_finpath): os.makedirs(_finpath) file = open(path, "w") file.write(data) file.close() return True except Exception as er: print("Error (file open) - %s\n%s"%(er, path)) return False global randomid randomid = curtime() def get_randid(): global randomid randomid += randint(0, 120) return randomid def get_token(): #Токен я вам предоставлять не буду return read("token.token") def format_time(): return strftime("[%H:%M:%S]", gmtime(curtime() + 3600 * 3)) def log(*data): print(format_time(), *data) def stop(message = None):
def l1qc_newton(x0, u0, A, b, epsilon, tau, newtontol, newtonmaxiter): alpha = 0.01 beta = 0.5 AtA = dot(A.T, A)#0.05s x = x0 u = u0 r = dot(A,x) - b fu1 = x - u fu2 = -x - u fe = 1./2*(dot(r.T,r)-epsilon**2) f = sum(u) - (1./tau)*(sum(log(-fu1)) + sum(log(-fu2)) + log(-fe)) niter = 0 done = 0 while not done: t = curtime() atr = dot(A.T,r) ntgz = 1./fu1 - 1./fu2 + 1./fe*atr ntgu = -tau - 1./fu1 -1./fu2 gradf = -(1./tau)*np.vstack((ntgz.reshape(-1,1), ntgu.reshape(-1,1))) sig11 = 1./fu1**2 + 1./fu2**2 sig12 = -1./fu1**2 + 1./fu2**2 sigx = sig11 - 1.*sig12**2/sig11 w1p = ntgz - (1.*sig12/sig11)*ntgu H11p = np.diag(sigx) - (1./fe)*AtA + (1./fe)**2*dot(atr,atr.T) w1p.shape = -1,1 dx = np.linalg.solve(H11p, w1p) dx = dx.flatten() Adx = dot(A, dx) du = 1./sig11*ntgu-1.*sig12/sig11*dx ifu1 = (dx-du>0) ifu2 = (-dx-du>0) aqe = dot(Adx.T, Adx) bqe = dot(2*r.T, Adx) cqe = dot(r.T, r) - epsilon**2 aa = -fu1[ifu1]/(dx[ifu1]-du[ifu1]) bb = -fu2[ifu2]/(-dx[ifu2]-du[ifu2]) cc = (-bqe+sqrt(bqe**2-4*aqe*cqe))/(2*aqe) cc = cc.flatten() tmp = np.hstack((aa,bb,cc)) smax = min(1, min(tmp)) s = 0.99*smax suffdec = 0 backiter = 0 gradf = gradf.flatten() while not suffdec: xp = x + s*dx up = u + s*du rp = r + s*Adx fu1p = xp - up fu2p = -xp - up fep = 1./2*(dot(rp.T, rp) - epsilon**2) fp = sum(up) - (1/tau)*(sum(log(-fu1p)) + sum(log(-fu2p)) + log(-fep)) tmp = np.hstack((dx, du)) tmp = dot(gradf, np.hstack((dx, du))) flin = f + alpha*s*tmp suffdec = (fp<=flin) s = beta*s backiter = backiter+1 x = xp u = up r = rp fu1 = fu1p fu2 = fu2p fe = fep f = fp lambda2 = -dot(gradf, np.hstack((dx, du))) stepsize = s*np.linalg.norm(np.hstack((dx, du))) niter = niter+1 print niter, done = (lambda2/2 < newtontol) | (niter >= newtonmaxiter) print (lambda2/2), newtontol return [xp, up, niter]