def simulation(num_seconds, pages_per_minuite): printers=printer.Printer(200) printers.tick() print('after ticking') lab_printer = printer.Printer(pages_per_minuite) print_queue = queue.Queue() waiting_times= [] for current_second in range(num_seconds): if new_print_task(): tasks = task.Task(current_second) print_queue.enqueue(tasks) print("this is the current task: ", print_queue.dequeue()) if (not lab_printer.busy()) and (not print_queue.is_empty()): next_task = print_queue.dequeue() print("this is the new task ", next_task) waiting_times.append(next_task.wait_time(current_second)) lab_printer.start_next(next_task) print("this is waiting time ", waiting_times) lab_printer.tick() average_wait = sum(waiting_times) / len(waiting_times) print("Average Wait %6.2f secs %3d tasks remaining." % (average_wait, print_queue.size())) print(waiting_times)
def strftime(target): printer.Printer().plus("Target: %s"%target) if 'http://' in target: t = "%s"%target.split('http://')[1] else: t = "%s"%target.split('https://')[1] try: printer.Printer().plus('IP: %s'%socket.gethostbyaddr('%s'%t)[2][0]) except socket.error,t: printer.Printer().plus('IP: Host name lookup failure')
def strftime(target): printer.Printer().plus("Target: %s" % target) if 'http://' in target: t = "%s" % target.split('http://')[1] else: t = "%s" % target.split('https://')[1] try: printer.Printer().plus('IP: %s' % socket.gethostbyaddr('%s' % t)[2][0]) except socket.error: printer.Printer().plus('IP: Host name lookup failure') printer.Printer().plus("Starting: %s\n" % time.strftime('%d/%m/%Y %H:%M:%S'))
def do(self): prn=printer.Printer(printer.Printer.UI_CONSOLE) config=ConfigParser.ConfigParser() config.read("config.cfg") adb=ADB(config.get("ADB","path")) sands4getedk = SandS4GetEDK(prn, config, sandy.sandy.Sandy._settings['projectname']) params=sands4getedk.getparams() phone = getphonewithos(adb) params["phonewithos"]["value"] = phone config2params(config, params, phone) sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sands4getedk.setparams(params) su=checkforsu(adb) sands4getedk.getedk() return
def handle_file(args): mylogger.logger.debug("In Handle_File") filepath = os.path.realpath(args.path) if not os.path.isfile(filepath): print("[Handle File] File path {} does not exist. Exiting...".format( filepath)) mylogger.logger.debug( "[Handle File] File path {} does not exist. Exiting...".format( filepath)) sys.exit() with open(filepath) as file: devices = client.get_devices(args.ip, args.port) for line in file: device = None filedevice = format(line).split()[0] deviceid = format(line).split()[1] # print("DEVICE : " + filedevice) # print("DEVICE ID : " + deviceid) # filedevice = format(line).replace('\n', '').replace('\r', '') for de in devices: if (de['id'] == filedevice): device = de if device == None: mylogger.logger.error("Capteur [" + filedevice + "] inexistant ou impossible à trouver.") else: mylogger.logger.debug("Capteur trouvé [" + filedevice + "].") my_sensor_printer = printer.Printer(filedevice, deviceid, args.ip, args.port, args.api) my_sensor_printer.start()
def _get_all_printers(self): query = "SELECT id,host FROM {}".format(Queue.p_table) self.printer_ids = dict() for p_id, host in self._database.read(query): p = printer.Printer(p_id, host) p.refresh_data() self.printer_ids[int(p_id)] = p
def footer2binkey(footerfile, password): binkey = "" mode = "phone" try: f = open(footerfile, "rb") try: f.seek(0x24) check = f.read(3) if (check == "aes"): mode = "phone" else: mode = "sdcard" if (mode == "sdcard"): offset = 0x20 else: offset = 0x84 f.seek(offset) keypaddingsalt = f.read(80) finally: f.close() except IOError as e: prn = printer.Printer(printer.Printer.UI_CONSOLE) prn.print_err("I/O error({0}): {1}: {2}".format( e.errno, e.strerror, file)) return -1 binkey, mkey = decrypt_key(keypaddingsalt[:32], keypaddingsalt[64:], password) padding = create_padding(keypaddingsalt[:32], mkey) return binkey
def do(self): prn=printer.Printer(printer.Printer.UI_CONSOLE) config=ConfigParser.ConfigParser() config.read("config.cfg") #prn.print_info(config.sections()) adb = ADB(config.get("ADB","path")) sandgetfooter = SandGetFooter(prn, config, sandy.sandy.Sandy._settings['projectname']) params = sandgetfooter.getparams() phone = getphonewithos(adb) #phone="GT-I9300 4.1.2" params["phonewithos"]["value"] = phone config2params(config, params, phone) sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sandgetfooter.setparams(params) su=checkforsu(adb) sandgetfooter.getfooter()
def run(self): #First let's read our config file, in this case a yaml file yaml = yamlFile.ReadYaml() #Initialization of storage class, passing the configuration storage = dbStorage.Storage(yaml) #Initialization of the Genetic algorithm for seeking the solution genetic = algorithm.GeneticAlgorithm(self.__queens) #Finally , print the solution myPrinter = printer.Printer(genetic, storage)
def _update_printer_dict(self): query = "SELECT id,host FROM {}".format(Queue.p_table) self.printer_ids = dict() existing_ids = self.printer_ids.keys() for p_id, host in self._database.read(query): if p_id not in existing_ids: p = printer.Printer(p_id, host) p.refresh_data() self.printer_ids[int(p_id)] = p
def __init__(self, name, ptype, volume=(0, 0, 0)): self.name = name self.ptype = ptype self.volume = volume self.idle = True self.gcodes = list() self.taskMaster = clientSocket.talk(HOST, PORT) try: self.printLink = printer.Printer(PPORT, BUAD) except: print("Failed to start printer connection will try again when its important")
def handle_printer(args): mylogger.logger.debug("In Handle_Printer") my_sensor_printer = printer.Printer(args.id, 0, args.ip, args.port, args.api) my_sensor_printer.start() try: while 1: time.sleep(.01) except Exception as err: my_sensor_printer.join() print("Exit")
def do(self): prn=printer.Printer(printer.Printer.UI_CONSOLE) sand2john = Sand2John(prn, sandy.sandy.Sandy._settings['projectname'], mode="sdcard") params=sand2john.getparams() sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sand2john.setparams(params) sand2john.convert2john() return
def printer_worker(prefix, pause, exitRequest, pipelineIn, pipelineOut): """ This function is used for multiprocessing. The controller of the process(es) will be referred to as the manager (just to make it easier). Parameters ---------- prefix: Data for class constructor pause: A mutex lock used to pause/resume this process exitRequest: Queue used for indicating that this process should exit pipelineIn: Queue used for consumer data input pipelineOut: Queue used for producer data output Returns ------- """ print("Printer start!") # Instantiate a class object for this process printerClass = printer.Printer(prefix) while (True): # Pause turnstile pause.acquire() pause.release() # Queues are process-safe, so no need to protect it # IMPORTANT: If the queue is empty it will be stuck here forever, # This is bad if an exit is requested, so a way to get it unstuck # is to have the manager manually push a few items (see manager below) inData = pipelineIn.get() # Do the work (in the class, not in this wrapper function) # Single Responsibility Principle ret, outData = printerClass.print(inData) # outData should also be the only thing coming out, already packed and ready to go # Something went wrong so we'll skip if (not ret): continue print("Inserting data: " + outData) # Gets stuck if full pipelineOut.put(outData) # Check whether a reset was called if (exit_requested(exitRequest)): break # Once the process reaches the end of the function it will die automatically print("Printer finished!") return
def __init__(self, codeLength=4, maxGuesses=10, symbolList=None): if symbolList is None: self.symbolList = ['R', 'G', 'B', 'W', 'Y', 'O'] else: self.symbolList = symbolList self.codeLength = codeLength self.maxGuesses = maxGuesses self.solution = '' # using a tuple ("RGBY", (1,2)) -> (code, (blackPegs, whitePegs)) self.guesses = [] self.didWin = False self.printer = printer.Printer(self)
def do(self): prn = printer.Printer(printer.Printer.UI_CONSOLE) sandgetfooterfromdd = SandGetFooterFromdd( prn, sandy.sandy.Sandy._settings['projectname']) params = sandgetfooterfromdd.getparams() sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sandgetfooterfromdd.setparams(params) sandgetfooterfromdd.do()
def do(self): prn = printer.Printer(printer.Printer.UI_CONSOLE) sandmountsdcardfrompwd = SandMountSdcardFromPwd(prn, sandy.sandy.Sandy._settings['projectname']) params = sandmountsdcardfrompwd.getparams() sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sandmountsdcardfrompwd.do() return
def __init__(self): self.printer = printer.Printer() self.ascii = ascii.Ascii("big") #self.font_list = ["big", "doom", "isometric1", "isometric3", "larry3d", "stop", "standard", "small", "shadow", # "rectangles", "kban", "fender", "chunky", "block"] self.text = "Die Poesie der Entropie \n\n" \ "Ordnung ist Symmetrie. \nSymmetrie ist Schoenheit.\n\nIn einer von den " \ "Kraeften der Entropie beherrschten Welt\nist Schoenheit selten und unwahrscheinlich.\n" \ "Und doch gibt es Schoenheit ueberall.\nBuecher koennen schoen sein, wenn sie eine gute " \ "Geschichte erzaehlen.\nGute Geschichten sind eine Ansammlung wohl formulierter Saetze,\n" \ "welche aus sorgfaeltig ausgewaehlten Worten bestehen.\nWorte bestehen aus Buchstaben.\n" \ "Worte sind die logische Aneinanderreihung\nausgewaehlter Buchstaben des Alphabets.\n\n" \ "Schoenheit ist Ordnung. \nSchoenheit sind Buchstaben. \nSchoenheit ist die Ordnung von Buchstaben. "
def do(self): prn=printer.Printer(printer.Printer.UI_CONSOLE) sandmountddfromkey= SandMountDDFromKey(prn, sandy.sandy.Sandy._settings['projectname']) params=sandmountddfromkey.getparams() sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sandmountddfromkey.setparams(params) sandmountddfromkey.do() return
def __init__(self, hashtag=None, interval=DEFAULT_INTERVAL, user_agent=USER_AGENT, printer_name="PRINTER", kwargs=None): threading.Thread.__init__(self) self.daemon = True self.hashtag = hashtag self.interval = int(interval) self.data_path = DATA_PATH self.data_uri = DATA_URI self.paused = False self.printer_wait = False self.printer_name = printer_name self._lp = printer.Printer(name=self.printer_name) self._kill = False self._lock = threading.Lock() self._posts = None self._loader = instaloader.Instaloader(user_agent=user_agent,filename_pattern="{date_utc}_UTC_{mediaid}_{shortcode}", download_videos=False, compress_json=False, download_geotags=False, download_comments=False, dirname_pattern=self.data_path+"/{target}")
def do(self): prn = printer.Printer(printer.Printer.UI_CONSOLE) config = ConfigParser.ConfigParser() config.read("config.cfg") adb = ADB(config.get("ADB", "path")) sandgetsdcard = SandGetSDCard( prn, config, sandy.sandy.Sandy._settings['projectname']) params = sandgetsdcard.getparams() sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sandgetsdcard.setparams(params) sandgetsdcard.get_sdcard_file() return
def do(self): prn=printer.Printer(printer.Printer.UI_CONSOLE) #config=ConfigParser.ConfigParser() #config.read("config.cfg") #adb=ADB(config.get("ADB","path")) sandmountsdcardfromkey = SandMountSdcardFromKey(prn, sandy.sandy.Sandy._settings['projectname']) params=sandmountsdcardfromkey.getparams() sandy.sandyutils.print_params(params) sandy.sandyutils.set_params(params) sandmountsdcardfromkey.do() return
def __init__(self, game): self.game = game self.foreground = libtcod.console_new(settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT) libtcod.console_set_default_background(self.foreground, libtcod.black) self.width, self.height = settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT self.printer_manager = printer.PrinterManager() for text in sample_texts[::-1]: new_printer = printer.Printer([], 1, 1, self.foreground) text_block = printer.typeset_text(text) for w in text_block: new_printer.add_word(w) new_printer.arrange_forme() self.printer_manager.add_printer(new_printer) self.printer_manager.reset_queue()
def __init__(self): self.argumentParser = ap.ArgumentParser(self) self.fileFinder = ff.FileFinder(self) self.inputs = 1 self.nLayers = self.argumentParser.nLayers() self.nNodes = self.argumentParser.nNodes() self.outputs = 1 self.networkType = self.argumentParser.type() self.network = nn.NeuralNetwork(self) self.network.constructNetwork(inputs=self.inputs, nNodes=self.nNodes, nLayers=self.nLayers, outputs=self.outputs, networkType=self.networkType) self.saver = ckps.CheckpointSaver(self, self.argumentParser().save) self.networkTrainer = nt.NetworkTrainer(self, self.saver) self.function = lambda r: r / r * np.random.normal( 0, 1) # +np.sin(7.0*np.pi*r) self.function = lambda r: 1 / r**12 - 1 / r**6 self.function = lambda r: 4 * (1.0 / (r**12) - 1.0 / (r**6)) - 4 * (1.0 / (2.5**12) - 1.0 / (2.5**6)) self.dataGenerator = gen.DataGenerator(0.87, 2.5, self) self.dataGenerator.setFunction(self.function) if not self.argumentParser().file == None: self.dataGenerator.setGeneratorType("file") else: self.dataGenerator.setGeneratorType("function") #self.dataGenerator.setGeneratorType("VMC") #self.dataGenerator.setGeneratorType("noise") self.dataSize = int(9987) self.numberOfEpochs = int(100) self.batchSize = int(500) self.testSize = self.dataSize #int(600) self.testInterval = 5000 self.printer = printer.Printer(self) self.printer.printSetup() self.plotter = plotter.Plotter(self)
def __init__(self): self.NUM_PLACES = 5 self.output_folder = "images" self.printer = printer.Printer() # Initialize counter max = 0 for i in os.listdir(self.output_folder): number = int(os.path.splitext(i)[0].split('_')[1]) if number > max: max = number self.counter = max + 1 print("Starting counter at:", self.counter) # Gallery Information self.current_image = self.counter - 1 self.font = pygame.font.SysFont("monospace", 12) self.font_large = pygame.font.SysFont("monospace", 14) print("current image:", self.current_image)
def simulation(num_seconds, pages_per_second): lab_printer = printer.Printer(pages_per_second) print_queue = queue.Queue() waiting_times = [] for current_second in range(num_seconds): if new_print_task(): _task = task.Task(current_second) print_queue.enqueue(_task) if (not lab_printer.busy()) and (not print_queue.is_empty()): next_task = print_queue.dequeue() waiting_times.append(next_task.wait_time(current_second)) lab_printer.start_next(next_task) lab_printer.tick() average_wait = sum(waiting_times) / len(waiting_times) print('Average wait %6.2f secs %3d task remaining.' % (average_wait, print_queue.size()))
def read(concurrency, nb_readers=1, slowMode=False): """Function that read cloudamqp 'presentation' queue """ amqp_url = env.amqp_key # Parse CLODUAMQP_URL (fallback to localhost) url = os.environ.get('CLOUDAMQP_URL', amqp_url) global ccrcy ccrcy = concurrency if concurrency: #if on concurrency mode, create readers readers = [] pr = printer.Printer() pr.start() for i in range(nb_readers): r = reader.Reader( url, pr, 'presentation’', concurrency, "reader " + str(i), (i == 1 and slowMode)) #if slow mode is enable, slow reader 1 readers.append(r) r.start() sc = scanner.Scanner(readers, pr) sc.start() else: params = pika.URLParameters(url) params.socket_timeout = 5 connection = pika.BlockingConnection(params) # Connect to CloudAMQP channel = connection.channel() auto_acknow = not concurrency channel.queue_declare(queue='presentation’') channel.basic_consume(queue='presentation’', on_message_callback=callback, auto_ack=auto_acknow) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming()
def process(self, descriptor): files = self.s3_client.get_pending_files("GCODES/TOPRINT", ".gcode") file = files[0] if len(files) > 0 else None try: if file: local_file, file_name = self.s3_client.download_file( file, "gcodes") descriptor["name"] = file_name printer_instance = printer.Printer(self.save_state, descriptor) procedure = procedures.Procedures(self.save_state, descriptor) self.save_state(descriptor) connected = printer_instance.connect_printer() if connected: printer_instance.process_message() procedure.print_model(printer_instance, local_file) except Exception as ex: logger.error(ex) descriptor["error"] = str(ex) finally: self.s3_client.move_file(file, str(file).replace("TOPRINT", "PRINTED")) descriptor["end_date"] = str(datetime.datetime.now()) self.save_state(descriptor)
def __init__(self): self.reloadClasses = False self.Printer = printer.Printer() #Controller has a Printer
def main(_): pter = printer.Printer() pter('reading test data') init_file = './data/initial_vectors/init_vec' init_vec = pickle.load(open(init_file, 'rb')) mode = FLAGS.mode export_path = FLAGS.data_path if mode == 'hit_k_100' or mode == 'hit_k_200': f = open("./data/raw_data/relation2id.txt", "r") content = f.readlines()[1:] id2rel = {} for i in content: rel, rid = i.strip().split() id2rel[(int)(rid)] = rel f.close() fewrel = {} if mode == 'hit_k_100': f = open("./data/rel100.txt", "r") else: f = open("./data/rel200.txt", "r") content = f.readlines() for i in content: fewrel[i.strip()] = 1 f.close() if mode == 'pr' or mode == 'hit_k_100' or mode == 'hit_k_200': test_instance_triple = np.load(export_path + 'test_entity_pair.npy') test_instance_scope = np.load(export_path + 'test_entity_scope.npy') test_len = np.load(export_path + 'test_len.npy') test_label = np.load(export_path + 'test_label.npy') test_word = np.load(export_path + 'test_word.npy') test_pos1 = np.load(export_path + 'test_pos1.npy') test_pos2 = np.load(export_path + 'test_pos2.npy') test_mask = np.load(export_path + 'test_mask.npy') test_en1 = np.load(export_path + 'test_en1.npy') test_en2 = np.load(export_path + 'test_en2.npy') test_sen_hier1 = np.load(export_path + 'test_sen_hier1.npy') test_sen_hier2 = np.load(export_path + 'test_sen_hier2.npy') exclude_na_flatten_label = np.load(export_path + 'all_true_label.npy') else: test_instance_triple = np.load(export_path + 'pn/test_entity_pair_pn.npy') test_instance_scope = np.load(export_path + 'pn/test_entity_scope_' + mode + '.npy') test_len = np.load(export_path + 'pn/test_len_' + mode + '.npy') test_label = np.load(export_path + 'pn/test_label_' + mode + '.npy') test_word = np.load(export_path + 'pn/test_word_' + mode + '.npy') test_pos1 = np.load(export_path + 'pn/test_pos1_' + mode + '.npy') test_pos2 = np.load(export_path + 'pn/test_pos2_' + mode + '.npy') test_mask = np.load(export_path + 'pn/test_mask_' + mode + '.npy') test_en1 = np.load(export_path + 'pn/test_en1_' + mode + '.npy') test_en2 = np.load(export_path + 'pn/test_en2_' + mode + '.npy') test_sen_hier1 = np.load(export_path + 'pn/test_hier1_' + mode + '.npy') test_sen_hier2 = np.load(export_path + 'pn/test_hier2_' + mode + '.npy') exclude_na_flatten_label = np.load(export_path + 'pn/true_label.npy') exclude_na_label = np.reshape(exclude_na_flatten_label, [-1, FLAGS.num_classes - 1]) index_non_zero = np.sum(exclude_na_label, 0) > 0 print('reading test data finished') print('entity pairs : %d' % (len(test_instance_triple))) print('sentences : %d' % (len(test_len))) print('relations : %d' % (FLAGS.num_classes)) print('hier1 relations : %d' % (FLAGS.num_hier1_classes)) print('hier2 relations : %d' % (FLAGS.num_hier2_classes)) print('word size : %d' % (FLAGS.word_size)) print('position size : %d' % (FLAGS.pos_size)) print('hidden size : %d' % (FLAGS.hidden_size)) print('building network...') sess = tf.Session(config=tf_configs) model = CoRA(is_training=False, init_vec=init_vec) sess.run(tf.global_variables_initializer()) saver = tf.train.Saver() print('building finished...') def test_step(word, pos1, pos2, mask, leng, label_index, label, scope, en1, en2, sen_hier1, sen_hier2): feed_dict = { model.word: word, model.pos1: pos1, model.pos2: pos2, model.mask: mask, model.len: leng, model.label_index: label_index, model.label: label, model.scope: scope, model.en1: en1, model.en2: en2, model.sen_hier1: sen_hier1, model.sen_hier2: sen_hier2, model.keep_prob: FLAGS.keep_prob } output = sess.run(model.test_output, feed_dict) return output start_ckpt = FLAGS.test_start_ckpt start_step = FLAGS.test_start_step if FLAGS.test_single: end_ckpt = FLAGS.test_start_ckpt end_step = FLAGS.test_start_step else: end_ckpt = FLAGS.test_end_ckpt end_step = FLAGS.test_end_step if FLAGS.test_use_step == False: iteration_list = range(start_ckpt, end_ckpt + 1) else: iteration_list = range(start_step, end_step + 1, FLAGS.test_step) for iters in iteration_list: if FLAGS.test_use_step == False: pter('waiting for epoch' + str(FLAGS.save_epoch * iters) + '...') while FLAGS.model + "-" + str(FLAGS.save_epoch * FLAGS.test_step * iters) + '.index' not in os.listdir( FLAGS.checkpoint_path): time.sleep(FLAGS.test_sleep) saver.restore( sess, FLAGS.checkpoint_path + FLAGS.model + "-" + str(FLAGS.save_epoch * FLAGS.test_step * iters)) else: pter('waiting for step' + str(iters) + '...') while FLAGS.model + "-" + str(iters) + '.index' not in os.listdir( FLAGS.checkpoint_path): time.sleep(FLAGS.test_sleep) saver.restore( sess, FLAGS.checkpoint_path + FLAGS.model + "-" + str(iters)) stack_output = [] iteration = len(test_instance_scope) // FLAGS.batch_size for i in range(iteration): if FLAGS.test_use_step == False: pter('running ' + str(i) + '/' + str(iteration) + ' for epoch ' + str(FLAGS.save_epoch * iters) + '...') else: pter('running ' + str(i) + '/' + str(iteration) + ' for step ' + str(iters) + '...') input_scope = test_instance_scope[i * FLAGS.batch_size:(i + 1) * FLAGS.batch_size] index = [] scope = [0] label = [] for num in input_scope: index = index + list(range(num[0], num[1] + 1)) label.append(test_label[num[0]]) scope.append(scope[len(scope) - 1] + num[1] - num[0] + 1) label_ = np.zeros((FLAGS.batch_size, FLAGS.num_classes)) label_[np.arange(FLAGS.batch_size), label] = 1 output = test_step(test_word[index, :], test_pos1[index, :], test_pos2[index, :], test_mask[index, :], test_len[index], test_label[index], label_, np.array(scope), test_en1[index], test_en2[index], test_sen_hier1[index], test_sen_hier2[index]) stack_output.append(output) if FLAGS.test_use_step == False: pter('evaluating epoch ' + str(FLAGS.save_epoch * iters) + '...') else: pter('evaluating step ' + str(iters) + '...') "case save" stack_output = np.concatenate(stack_output, axis=0) np.save(FLAGS.logits_path + 'stack_output' + str(iters), stack_output) exclude_na_output = stack_output[:, 1:] exclude_na_flatten_output = np.reshape(stack_output[:, 1:], (-1)) if mode == 'hit_k_100' or mode == 'hit_k_200': ss = 0 ss10 = 0 ss15 = 0 ss20 = 0 ss_rel = {} ss10_rel = {} ss15_rel = {} ss20_rel = {} for j, label in zip(exclude_na_output, exclude_na_label): score = None num = None for ind, ll in enumerate(label): if ll > 0: score = j[ind] num = ind break if num is None: continue if id2rel[num + 1] in fewrel: ss += 1.0 mx = 0 for sc in j: if sc > score: mx = mx + 1 if not num in ss_rel: ss_rel[num] = 0 ss10_rel[num] = 0 ss15_rel[num] = 0 ss20_rel[num] = 0 ss_rel[num] += 1.0 if mx < 10: ss10 += 1.0 ss10_rel[num] += 1.0 if mx < 15: ss15 += 1.0 ss15_rel[num] += 1.0 if mx < 20: ss20 += 1.0 ss20_rel[num] += 1.0 print("mi") print(ss10 / ss) print(ss15 / ss) print(ss20 / ss) print("ma") print((np.array([ss10_rel[i] / ss_rel[i] for i in ss_rel])).mean()) print((np.array([ss15_rel[i] / ss_rel[i] for i in ss_rel])).mean()) print((np.array([ss20_rel[i] / ss_rel[i] for i in ss_rel])).mean()) elif mode == 'pr': m = average_precision_score(exclude_na_flatten_label, exclude_na_flatten_output) M = average_precision_score(exclude_na_label[:, index_non_zero], exclude_na_output[:, index_non_zero], average='macro') np.save(FLAGS.logits_path + FLAGS.model + str(iters), exclude_na_flatten_output) print(m, M) else: order = np.argsort(-exclude_na_flatten_output) print(np.mean(exclude_na_flatten_label[order[:100]])) print(np.mean(exclude_na_flatten_label[order[:200]])) print(np.mean(exclude_na_flatten_label[order[:300]]))