def rotate90s(self, data, label): if self.m_rot90sProb >0 and random.uniform(0,1) <= self.m_rot90sProb: k = random.randrange(1, 4, 1) # k*90 is the real rotation degree data = np.rot90(data, k, tuple(range(1,data.ndim))) if data.ndim == label.ndim: label = np.rot90(label, k, tuple(range(1,label.ndim))) elif data.ndim == label.ndim+1: label = np.rot90(label, k) else: self.m_logInfo("Error: in rotate90s, the ndim of data and label does not match.") sys.exi(-1) return data, label
def main(): parser = argparse.ArgumentParser( description='Generate Ed25519 key pair from secret key') parser.add_argument('-s', '--secret', dest='secret', help='secret key file (input)') parser.add_argument('-p', '--public', dest='public', help='public key file (output)') args = parser.parse_args() if args.secret is None: print("You do need a secret... - exiting") sys.exit(1) if args.public is None: print("You do need a public key file nae... - exiting") sys.exit(2) if os.path.isfile(args.secret) and os.access( args.secret, os.R_OK) and os.path.getsize(args.secret) == 32: f = open(args.secret, 'rb') secret = f.read() f.close() else: print("Problem with secret file - exiting") sys.exi(7) # e.g. secret="rdbd-example0001rdbd-example0002".encode('utf-8') if len(secret) != 32: print("Secret has to be 32 octets...(it's " + str(len(secret)) + " - exiting") sys.exit(1) privkey, pubkey = Ed25519.keygen(secret) with open(args.public, "wb") as pubf: pubf.write(pubkey) return
for line in db.query("select DISTINCT(uuid) from cloud_result where `time` like '%" + timedate + "%'").list(): make_result_hours.make(line['uuid']) def make_days(): timedate = str(int(time.strftime('%Y%m%d',time.localtime()))-1) #last day for line in db.query("select DISTINCT(uuid) from cloud_result_hours where `time` like '%" + timedate + "%'").list(): make_result_days.make(line['uuid']) def make_months(): timedate = str(int(time.strftime('%Y%m',time.localtime()))-1) for line in db.query("select DISTINCT(uuid) from cloud_result_days where `time` like '%" + timedate + "%'").list(): make_result_months.make(line['uuid']) if not options: usage() for k,v in options: if k in("-h","--hours"): make_hours() elif k in ("-d","--days"): make_days() elif k in ("-m","--months"): make_months() elif k in ("-y","--year"): make_year() else: usage() sys.exi(1)
content = content.strip() if content: self.line += content self.line += '\n' self.docList.append(self.line) self.line = '' def loadFile(self, filename): try: parser = xml.sax.make_parser() parser.setContentHandler(self) parser.parse(filename) docList = self.docList self.docList = [] for x in docList: self.docList.append(x.rstrip()) except IOError, message: print "Error reading File: ", message except xml.sax.SaxParseException, message: print "Error parsing file:", message if __name__ == "__main__": if len(sys.argv) != 2: print "usage:", sys.argv[0], "<xml file>" sys.exi() model = Model() model.loadFile(sys.argv[1]) docList = model.getDocumentList() for x in docList: print x
def cons(args,env): if(len(args) != 2): print( "Incorrect number of arguments for func getItem. Takes in 2 arguments only. You provided", str(len(args)), "argument(s) instead.") sys.exi(1) args[0].token.append(args[1].token) return Lexeme( [args[0].token,args[1].token] , "ARRAY" )
def main(): #ALustetaan pygame pygame.init() #taustakuvan nimi bg = "img/background.png" beat = pygame.mixer.Sound("sounds/GGJ13_Theme.wav") beat.set_volume(0.0) hello = pygame.mixer.Sound("sounds/hello.wav") beat.play(-1) #FPS:aa varten kello clock = pygame.time.Clock() #ikkuna screen = pygame.display.set_mode([860,640]) #kaljakoppa beer_case = pygame.image.load("img/koppa.png").convert_alpha() beer_case = pygame.transform.scale(beer_case,[130,130]) #Game over bg gameoverpic = pygame.image.load("img/game_over_screen.png").convert() gameoverpic = pygame.transform.scale(gameoverpic, [600,600]) MAX_X = screen.get_width() MAX_Y = screen.get_height() CENTER = [(MAX_X/2),(MAX_Y/2)] posx = 400 posy = 400 #Muutama vari rgb:na vari1 = (200,178,87) vari2 = (100,13,13) #pelisilmukan paattymisehto done = False #gameover ruudun paattymisehto gameover = False #sanat joihin tallennetaan & verrataan sana = "" kirjain = "" sanalista = [] #Pelaajan luonti player = Player(posx,posy) #Friendon luonti friendo = Friendo(55,posy) #Typykka typykka = Typy(150,posy-12) #Sytamet sydan1 = Hearts(180,20) sydan2 = Hearts(260,20) sydan3 = Hearts(340,20) sydan4 = Hearts(420,20) sydan5 = Hearts(500,20) #Tausta background = pygame.image.load(bg).convert() #Kayttajan syottama teksti objekti fontti jne fontti = pygame.font.Font("freesansbold.ttf",20) tulostus = fontti.render(sana,True,vari2) #ALoitusviesti / palauteviesti message = "Try to earn a beer by doing stuff" #Vinkki/ hint pelaajalle a_hint = "Try typing a command" #Ladataan voittoruutu animaatio win_images = glob.glob("img/fireworks*.png") win_images.sort() win_anim = pyganim.PygAnimation([(win_images[0],0.2), (win_images[1],0.2), (win_images[2],0.2), (win_images[3],0.2), (win_images[4],0.2)]) #Helikopteri ;) heli = glob.glob("img/kopteri*.png") heli.sort() for i in range(len(heli)): kuva = pygame.image.load(heli[i]).convert_alpha() heli[i] = pygame.transform.scale(kuva,[100,100]) helikopteri = pyganim.PygAnimation([(heli[0],0.1), (heli[1],0.1), (heli[2],0.1), (heli[3],0.1)]) helikopteri.play() #animoidaan friendo ja typykka friendo.img.play() typykka.img.play() sydan1.img.play() sydan2.img.play() sydan3.img.play() sydan4.img.play() sydan5.img.play() #Aloitusruutu bg = pygame.image.load("img/main_screen.png").convert() bg = pygame.transform.scale(bg,[860,640]) show = True while show == True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_RETURN: show = False elif event.key == K_ESCAPE: pygame.quit() sys.exit() screen.blit(bg,[0,0]) pygame.display.update() #pelisilmukka 1 voitettu vai ei won1 = False #Pelisilmukka1 #arvaukset ja vaarat arvaukset arvauksia = 10 beer_x = 130 beer_y = 240 while done == False: #FPS = 60 clock.tick(60) #katotaan eventit / for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: #shifti pois aiheuttamasta erroreita if event.key == K_RSHIFT or event.key == K_LSHIFT or event.key == K_UP or event.key == K_DOWN or event.key == K_LEFT or event.key == K_RIGHT: continue if event.key == K_RETURN: sanalista = sana.split() sana = "" break #Muutetaan painallukset kirjain muotoon kirjain = str(chr(event.key)) #lisataan painettu nappain sanaan sana += kirjain if event.key == K_BACKSPACE: sana = sana[0:-2] screen.blit(background,[0,0]) tulostus = fontti.render(">"+sana,True,vari2) screen.blit(tulostus,[0,605]) #palaute viesti annetusta komennosta text1 = fontti.render(message,True,vari2,vari1) screen.blit(text1,[0,0]) #hint, vinkki pelaajalle jos ei tajua mita pitaa teha hint = fontti.render(a_hint,True,vari2,vari1) screen.blit(hint,[0,150]) #otetaan kirjoitetut komennot listaan, ja verrataan niita sanoihin command = etsisanat(sanalista) sanalista = [] if command == "get_naked": beer_x += 10 player.state = 2 player.pisteet += 3 if player.nekkid == False: player.nekkid = True elif command == "get_dressed": beer_x += 10 player.pisteet += 1 player.state = 1 elif command == "move_left": player.x += -15 elif command == "move_right": player.x += 15 elif command == "suicide": player.state = 4 done = True gameover = True elif command == "dance": beer_x += 10 player.pisteet += 3 player.state = 5 elif command == "wiggle_wiggle": beer_x += 10 player.pisteet += 2 player.state = 6 elif command == "get_first": message = "one does not simply drink beer without beer" elif command == "winwin": beer_x += 20 player.pisteet += 5 player.state = 7 elif command == "sing": beer_x += 10 player.state = 8 player.pisteet += 2 elif command == "dark_side": message = "Already tried, they didn't have cookies..." elif command == "unknown": arvauksia -= 1 if arvauksia == 0: done = True gameover = True message = "Syntax Error, Key value error, division by zero!" elif command == "moonwalk": player.state = 9 player.pisteet += 4 elif command == "killed": friendo.img = pyganim.PygAnimation([(friendo.kuvat[1],0.2)]) friendo.img.play() elif command == "heli": player.state = 11 elif command == "beer": message = "Can't reach the beer, must use force" elif command == "force": beer_x += 2 message = "Used THE FORCE, got a beer! happy now, so let's get naked" player.pisteet += 3 elif command == "skip": done = True won1 = True elif command == "penus": message = "Behold The mighty Penus Torvalds!" player.pisteet += 3 elif command == "smoke": message = "So you started smoking? huh?" player.pisteet += 3 player.state = 14 elif command == "happy_ending": message = "You had a \"healthy\" massage.." elif command == "jump": player.state = 12 elif command == "fuck_you": player.state = 13 elif command == "stop": player.state = 1 #ja piirretaan sen ruudulle #mittarin piirto friendo.update(screen) player.update(screen) #helikopteri purkka if player.state == 11: helikopteri.blit(screen,[player.x+50,player.y+100]) typykka.update(screen) sydan1.update(screen) if arvauksia > 2: sydan2.update(screen) a_hint = "Play with yourself... furiously!(and yes we are monitoring your webcam)" if arvauksia > 4: sydan3.update(screen) a_hint = "HINT: What would pewds do. you can start by gettin rid of your clothes." if arvauksia > 6: sydan4.update(screen) a_hint = "HINT: Dance monkey DANCE!" if arvauksia > 8: a_hint = "HINT: keep an open mind. makers of this game ar nasty ppl" sydan5.update(screen) screen.blit(beer_case,[beer_x,beer_y]) pygame.display.update() #Katsotaan ollaanko voitettu eli pisteet >= 8 if player.pisteet >= 8: won1 = True done = True #Tason 1 voittoruutu: if won1 == True: player.state = 1 win_anim.play() bg = pygame.image.load("img/level1_won.png").convert() bg = pygame.transform.scale(bg,[860,640]) #Naytetaan voittoruutu, kunnes painetaan nappainta loop_dis = True while loop_dis == True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: loop_dis = False break screen.blit(bg,[0,0]) win_anim.blit(screen,[350,350]) pygame.display.update() #Taso 2 movex = 0 if gameover == True: done = True else: done = False taustat = pyganim.PygAnimation([("img/jate01.png",1.0), ("img/jate02.png",1.0)]) taustat.play() bouncer = Bouncer(100, 400) effects = Effect_holder(400, 400) update_pic = False damage = 0 instructions = "Use left and right arrow keys to move and go fight the bouncer" while done == False: clock.tick(60) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_UP or event.key == K_DOWN: player.state = 10 damage = 0.2 if event.key == K_LEFT: movex = -5 if event.key == K_RIGHT: movex = 5 if event.type == KEYUP: movex = 0 player.state = 1 damage = 0 player.x += movex taustat.blit(screen,[0,0]) #ja piirretaan sen ruudulle bouncer.health -= damage player.update(screen) random_int = random.randint(0,100) if random_int < 5: update_pic = True if player.state == 10: effects.update(screen, update_pic) if bouncer.health <= 0: done = True update_pic = False text2 = fontti.render(instructions,True,vari1,vari2) text1 = fontti.render("The evil bouncer isn't lettin ya in. BEAT HIM UP! (up and down arrows)",True,vari2,vari1) screen.blit(text1,[50,600]) screen.blit(text2,[50,620]) bouncer.update(screen) player.update(screen) pygame.display.update() if won1 == True: bouncer. x -= 50 bouncer.y -= 140 player.state = 1 win_anim.play() bg = pygame.image.load("img/level_2_won.png").convert() bg = pygame.transform.scale(bg,[860,640]) #Naytetaan voittoruutu, kunnes painetaan nappainta loop_dis = True while loop_dis == True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN: loop_dis = False break screen.blit(bg,[0,0]) win_anim.blit(screen,[350,350]) bouncer.update(screen) pygame.display.update() #pelisilmukan paattymisehto done = False #sanat joihin tallennetaan & verrataan #Taso 3 info bg = "img/info_pelille.png" tausta = pygame.image.load(bg) tausta = pygame.transform.scale(tausta,[860,640]) time_now = pygame.time.get_ticks() end_time = time_now + 5000 loop = True while loop == True and gameover == False: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exi() screen.blit(tausta,[0,0]) pygame.display.update() if pygame.time.get_ticks() > end_time: loop = False #Taso 3 #lista kaikista spriteista all_sprites = pygame.sprite.Group() #lista kaikista pulloista pullot = pygame.sprite.Group() #mailan luonti paddle = Paddle(vari1) paddle.rect.y = MAX_Y - paddle.image.get_height() all_sprites.add(paddle) #Pelaajan luonti player = Player(posx,posy) tausta = Valot(0,0) polizei = Polizei(610,450) muumi = Moomin(90, 450) v_pisteet = 0 o_pisteet = 0 paddle_lista = pygame.sprite.Group() paddle_lista.add(paddle) for i in range(100): if i % 2 == 0: polku = "img/beer_green.png" else: polku = "img/beer_orange.png" bottle = Bottle(vari2,polku) bottle.rect.x = random.randint(10,MAX_X-10) bottle.rect.y = random.randint(-4000,-100) all_sprites.add(bottle) pullot.add(bottle) #animoidaan friendo #Pelisilmukka if gameover == True: player.state = 4 player.img = player.kuvat[3] change = 0 time_now = pygame.time.get_ticks() end_time = time_now+25000 player.state = 5 tulostus = fontti.render("Collect more green bottles to score the babe!",True,(200,70,70)) paddle.rect.x = MAX_X/2 - paddle.image.get_width() while done == False and gameover == False: #FPS = 60 clock.tick(60) #katotaan eventit / for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_LEFT: change = -5 if event.key == K_RIGHT: change = 5 if event.type == KEYUP: change = 0 paddle.rect.x += change #katotaan ettei pelaaja mee luos ruudulta if paddle.rect.x <0: paddle.rect.x = 0 if paddle.rect.x > MAX_X-paddle.image.get_width(): paddle.rect.x = MAX_X-paddle.image.get_width() #liikutetaan pulloja alaspain ruudulla for pullo in pullot: x_change = random.randint(-2,2) y_change = random.randint(1,6) pullo.rect.x += x_change pullo.rect.y += y_change poistettavat = pygame.sprite.spritecollide(paddle,pullot,True) for i in poistettavat: if i.vari == "green": v_pisteet += 1 else: o_pisteet += 1 #valojen vilkkumisen randomisuus random_int = random.randint(0,100) if random_int < 10: update_pic = True tausta.update(screen, update_pic) update_pic = False #ja piirretaan sen ruudulle #player.update(screen) polizei.update(screen) muumi.update(screen) all_sprites.draw(screen) screen.blit(tulostus,[100,100]) pygame.display.update() if pygame.time.get_ticks() > end_time: done = True time_now = pygame.time.get_ticks() end_time = time_now + 6000 went_home = True end_time2 = end_time + 6000 done_once = False while went_home == True and gameover == False: for event in pygame.event.get(): if event.type == QUIT: pygame.exit() sys.exit() screen.fill((200,200,199)) beat.set_volume(1.0) tulostus = fontti.render("And you went home with",True,vari1) screen.blit(tulostus,[300,100]) if pygame.time.get_ticks() > end_time: beat.stop() if done_once == False: hello.play() done_once = True polizei.x = 220 polizei.y = 400 polizei.update(screen) if pygame.time.get_ticks() > end_time2: went_home = False pygame.display.update() #Game over screen if gameover == True: loop_this = True while loop_this == True: for event in pygame.event.get(): if event.type == QUIT: loop_this = False if event.type == KEYDOWN: loop_this = False screen.blit(gameoverpic,[0,0]) screen.blit(player.img,[player.x,player.y]) pygame.display.update() pygame.quit()
def getKrCalibration(time_of_day='2019-01-01 00:00:00'): """ it queries the RunDB for data that comes within one 4 hours """ #This function interacts with the XENON1T runDB: #global run_number, pax_version #print("even before we start looking at files: %s" % time_of_day) uri = 'mongodb://*****:*****@copslx50.fysik.su.se:27017/run' uri = uri % os.environ.get('MONGO_PASSWORD') client = pymongo.MongoClient(uri, replicaSet='runs', readPreference='secondaryPreferred') db = client['run'] collection = db['runs_new'] #Create a query of the recent days (rc_days) # -for all Kr data for the last 360 days #dt_today = datetime.datetime.today() #dt_recent = timedelta(days=rc_days) #dt_begin = dt_today - dt_recent #for debug #dt_begin = datetime.datetime(2017, 6, 7, 11, 20, 4) dt_begin = datetime.datetime.strptime(time_of_day, '%Y-%m-%d %H:%M:%S') dt_end = dt_begin + datetime.timedelta( days=0, hours=1, minutes=3, seconds=0) #dt_end = datetime.datetime(2017, 9, 1, 0, 0) query = { "source.type": "Kr83m", "start": { '$gt': dt_begin }, "end": { "$lt": dt_end } } #, "tags.name": "_sciencerun1"}#, "tags.name": "_sciencerun0"} cursor = list( collection.find(query)) # make a list of the results of the querry #get the version of pax if len(cursor): #print('the type of that observable before we get it to querry is: ', type(cursor[0])) for i_c in cursor: #print('the type of this i_c: ', type(i_c)) run_number = i_c['number'] run_name = i_c['name'] #run_start = i_c['start'] #run_end = i_c['end'] run_source = i_c['source']['type'] #print("the type of source", run_source) #if "data" in i_c.keys(): # pax_version = "pax_%s" % i_c["data"][0]["pax_version"] TagFile = False if 'tags' in i_c.keys() and len(i_c['tags']) > 0: for itagdict in i_c['tags']: for v in itagdict.values(): if (isinstance(v, str)) and (v in [ "bad", "messy", "_blinded" ]): #print("this run must be bad: ", run_name, v) TagFile = True break if not TagFile: if run_source in ["Kr83m", "Rn220"]: data_type = "calibration" run_source = "kr" else: data_type = "background" run_source = " " #run_dbtags.append((run_number, run_name) print(data_type, run_source, run_name, run_number) sys.exit(1) else: sys.exi(0)
timedate = str(int(time.strftime('%Y%m%d', time.localtime())) - 1) #last day for line in db.query( "select DISTINCT(uuid) from cloud_result_hours where `time` like '%" + timedate + "%'").list(): make_result_days.make(line['uuid']) def make_months(): timedate = str(int(time.strftime('%Y%m', time.localtime())) - 1) for line in db.query( "select DISTINCT(uuid) from cloud_result_days where `time` like '%" + timedate + "%'").list(): make_result_months.make(line['uuid']) if not options: usage() for k, v in options: if k in ("-h", "--hours"): make_hours() elif k in ("-d", "--days"): make_days() elif k in ("-m", "--months"): make_months() elif k in ("-y", "--year"): make_year() else: usage() sys.exi(1)