def set(name, value, type='auto', directory=None): """Saves a resource to disk under the given name. Args: name (str): the file name. Please make sure to get the right file extension. .json files are also OK for many types. value: a Klamp't resource (see list of compatible types in get()) type (str, optional): The resource type. If 'auto', the type is determined by the file extension. If this fails, the type is determined by the value. Returns: (bool): True on success, False otherwise """ if type == 'auto': try: type = loader.filenameToType(name) except Exception: type = types.objectToTypes(value) if isinstance(type, (list, tuple)): type = type[0] if directory == None: directory = getDirectory() fn = os.path.join(directory, name) _ensure_dir(fn) if type == 'xml': #loader can now save some xml files return loader.save(value, 'auto', fn) #if hasattr(value,'saveFile'): # return value.saveFile(fn) #raise NotImplementedError("TODO: save other xml files from Python API") else: return loader.save(value, type, fn)
def remove_medication_preprocessing(num_patients): for i in range(num_patients): print "Removing Medication Preprocessing - " + str(i) p = get_data([i])[0] for m in p['Med']: del m['RXNORM_NAME'] del m['RXNORM_CLASSES'] save(p)
def remove_medication_preprocessing(num_patients): for i in range(num_patients): print "Removing Medication Preprocessing - " + str(i) p = get_data([i])[0] for m in p['Med']: del m['RXNORM_NAME'] del m['RXNORM_CLASSES'] save(p)
def preprocess(i): print "\nPreprocessing Medications - " + str(i) p = get_data([i])[0] for (i, m) in enumerate(p['Med']): (name, rxclasses) = get_rx_classes(m['Medication'], include_name=True) m['RXNORM_NAME'] = name m['RXNORM_CLASSES'] = rxclasses save(p)
def preprocess(i): print "\nPreprocessing Medications - " + str(i) p = get_data([i])[0] for (i, m) in enumerate(p['Med']): (name, rxclasses) = get_rx_classes(m['Medication'], include_name=True) m['RXNORM_NAME'] = name m['RXNORM_CLASSES'] = rxclasses save(p)
def preprocess_medications(num_patients): for i in range(num_patients): print "\nPreprocessing Medications - " + str(i) + " - progress: ", p = get_data([i])[0] for (i, m) in enumerate(p['Med']): if i%100 == 0: print ", " + str(i) + '/' + str(len(p['Med'])), (name, rxclasses) = get_rx_classes(m['Medication'], include_name=True) m['RXNORM_NAME'] = name m['RXNORM_CLASSES'] = rxclasses save(p)
def preprocess_medications(num_patients): for i in range(num_patients): print "\nPreprocessing Medications - " + str(i) + " - progress: ", p = get_data([i])[0] for (i, m) in enumerate(p['Med']): if i % 100 == 0: print ", " + str(i) + '/' + str(len(p['Med'])), (name, rxclasses) = get_rx_classes(m['Medication'], include_name=True) m['RXNORM_NAME'] = name m['RXNORM_CLASSES'] = rxclasses save(p)
def train(toConvergence=False, iterations=None, saveEvery=500): refreshVocabulary() from_iteration = M['state']['task_iterations'][-1] if M['state'][ 'task_iterations'] else 0 while True: if toConvergence: networkStep() if M['state']['iteration'] % 10 == 0: window_size = 1000 window = M['state']['network_losses'][ max(from_iteration, len(M['state']['network_losses']) - window_size):] regress = stats.linregress(range(len(window)), window) print( "Iteration %d" % M['state']['iteration'], "| Network loss: %2.2f" % M['state']['network_losses'][-1], "| Slope: %4.4f" % regress.slope) if len( M['state']['network_losses'] ) >= from_iteration + window_size and regress.slope > -0.0001: break #Break when converged else: networkStep() if M['state']['iteration'] % 10 == 0: print( "Iteration %d" % M['state']['iteration'], "| Network loss: %2.2f" % M['state']['network_losses'][-1]) if len(M['state'] ['network_losses']) >= from_iteration + iterations: break if not args.no_save and len( M['state']['network_losses']) % saveEvery == 0: loader.save(M)
def set(name, value, type='auto', directory=None): """Saves a resource to disk under the given name.""" if type == 'auto': type = filenameToType(name) if directory == None: directory = getDirectory() fn = os.path.join(directory, name) _ensure_dir(fn) if type == 'xml': raise NotImplementedError("TODO: save xml files from Python API") elif type == 'json': f = open(fn, 'w') f.write(loader.toJson(value, type=type)) f.write('\n') f.close() return True else: return loader.save(value, type, fn)
def set(name,value,type='auto',directory=None): """Saves a resource to disk under the given name.""" if type == 'auto': type = filenameToType(name) if directory==None: directory = getDirectory() fn = os.path.join(directory,name) _ensure_dir(fn) if type == 'xml': raise NotImplementedError("TODO: save xml files from Python API") elif type == 'json': f = open(fn,'w') f.write(loader.toJson(value,type=type)) f.write('\n') f.close() return True else: return loader.save(value,type,fn)
def on_key_press(symbol, modifiers): global filename ss = key.symbol_string(symbol) if symbol == key.F1: loader.clear() filename = None elif symbol == key.F2: filename = input('filename:') loader.clear() arr, width, height = loader.load(filename) game.camera.x = width/2 game.camera.y = height/2 for b in arr: b.add() elif symbol == key.F5: loader.clear() if(filename): arr, width, height = loader.load(filename) game.camera.x = width/2 game.camera.y = height/2 for b in arr: b.add() elif symbol == key.S: if modifiers & key.MOD_CTRL: if filename: loader.save(filename) else: filename = input('filename:') loader.save(filename) elif symbol in structs.keys(): change_struct(structs[symbol]) elif symbol == key.Q: bullet.speed_cons *=0.8 elif symbol == key.E: bullet.speed_cons *= 1.25 elif modifiers & key.MOD_CTRL and symbol != 65507: name = 'key-{}.txt'.format(ss) loader.save(name) structs[symbol] = loader.load(name)[0] structs_path[ss] = name with open('structs.json', 'w') as file: json.dump(structs_path, file, indent=4, separators=(',', ': ')) elif ss in structs.keys(): change_struct(structs[ss])
def set(name,value,type='auto',directory=None): """Saves a resource to disk under the given name. Args: name (str): the file name. Please make sure to get the right file extension. .json files are also OK for many types. value: a Klamp't resource (see list of compatible types in get()) type (str, optional): The resource type. If 'auto', the type is determined by the file extension. If this fails, the type is determined by the value. Returns: (bool): True on success """ if type == 'auto': try: type = filenameToType(name) except Exception: type = types.objectToTypes(value) if isinstance(type,(list,tuple)): type = type[0] if directory==None: directory = getDirectory() fn = os.path.join(directory,name) _ensure_dir(fn) if type == 'xml': if hasattr(value,'saveFile'): return value.saveFile(fn) raise NotImplementedError("TODO: save other xml files from Python API") elif type == 'json': f = open(fn,'w') f.write(loader.toJson(value,type=type)) f.write('\n') f.close() return True else: return loader.save(value,type,fn)
_help = '''AutoCal 0.1 - Fred Morcos <*****@*****.**> Usage: ./autocal.py [COMMANDS] < <input-file> Commands: \t--qt\t\t\tShow the Qt user interface. \t--verbose,-v\t\tShow debug output. \t--quiet,-q\t\tDo not output errors. \t--help,-h\t\tShow this help. ''' if __name__ == '__main__': for a in sys.argv: if a == '--verbose' or a == '-v': config.debug = True elif a == '--quiet' or a == '-q': config.verbose_error = False elif a == '--help' or a == '-h': print _help sys.exit(0) elif a == '--qt': from autocalqt import qt_start qt_start() sys.exit(0) input_data = '' for line in sys.stdin: input_data += line s = loader.load(input_data) s = optimize.start(s) print loader.save(s)
def save_database(conf, loader): """Save the password database.""" passphrase = get_password(conf) loader.save(conf["database"].passwords, conf["db"]["filename"], passphrase)
def save(self): loader.save(self)
def save(self, u_path, b_path): loader.save(u_path, self.data_user) loader.save(b_path, self.data_business)
def save(saveNet=False): print("Saving...") loader.saveCheckpoint(M, saveNet) loader.saveRender(M) loader.save(M) print("Saved.")
print(jugement) output.append(jugement + '\n\n') #si les deux max sont positifs, alors on ne peut rien dire if max_gx_gy >= 0 and max_gy_gx >= 0: jugement = f"{name1} ne peut pas être comparé à {name2}" print(jugement) output.append(jugement + '\n\n') print("######################") ######################## # NOTE sur cette fonction : on peut mettre des inégalités larges. # Cela transformerait les comparaisons de type "est meilleur que" en "est au moins aussi bon que". # Cela correspondrait avec la façon dont les préférences sont données. En particulier, on pourrait inférer "x1 au moins aussi bon que x4", ce qui est donné dans les préférences. # Comme la correction de l'exercice propose de garder des inégalités strictes, on les garde pour le programme. Mais on perd l'information que "x1 au moins aussi bon que x4", par exemple. ######################## save("output.txt", output) #tri des sommets selon l'argument en coordonnées polaires cent = (sum([p[0] for p in sommets]) / len(sommets), sum([p[1] for p in sommets]) / len(sommets)) sommets.sort(key=lambda p: math.atan2(p[1] - cent[1], p[0] - cent[0])) #affichage du polyèdre x = [sommets[i][0] for i in range(len(sommets))] y = [sommets[i][1] for i in range(len(sommets))] plt.fill(x, y, color='black') plt.axis('equal') plt.title( f"polyèdre : espace des valeurs acceptables\navec préférences : {pref}") plt.savefig(f'polyedre.png')
def save(): global save_entry, shapes_list file = save_entry.get() file = save_check(file) loader.save(shapes_list, file)