def info_w(): branch_json = src.branch_error_check.branch_main.branch_check( project_assets) duplicate_json = src.duplicate_key_check.duplicate_main.duplicate_main( project_assets) format_json = src.format_char_check.format_main.format_main( project_assets) dir_json = src.lang_dir_check.dir_main.dir_main(project_assets) word_json = src.word_check.word_main.word_check( project_assets, "./check_words.txt") time_json = time_gen() # 重写文件 branch = open("./branch.js", "w", encoding="utf-8") duplicate = open("./duplicate.js", "w", encoding="utf-8") format = open("./format.js", "w", encoding="utf-8") dir = open('./dir.js', "w", encoding="utf-8") word = open('./word.js', "w", encoding="utf-8") time = open("./time.js", "w", encoding="utf-8") # 写 js 数据到文件 branch.write("export let branches=" + branch_json + ";") duplicate.write("export let duplicates=" + duplicate_json + ";") format.write("export let formats=" + format_json + ";") dir.write("export let dirs=" + dir_json + ";") word.write("export let words=" + word_json + ";") time.write("export let times=" + time_json + ";") branch.close() duplicate.close() format.close() dir.close() word.close() time.close()
def sortedProofs(matrix, files): shutil.rmtree("in", ignore_errors=True) shutil.rmtree("out", ignore_errors=True) os.makedirs(os.getcwd() + "/in") os.makedirs(os.getcwd() + "/out") i = 1 genProofs(files) time = open("timeSorted", "w") while i <= files: n, entrada = auxBegin("/in" + str(files)) startRunningTime = time.time() sorted(entrada, key=itemgetter(1)) endRunningTime = time.time() - startRunningTime # se escribe el archivo de tiempos time.write(str(n) + ":" + "{:1.5f}".format(endRunningTime) + "\n") i += 1 time.close()
def main(): time.clock() infile = open(DATA_PATH + 'Brown_tagged_train.txt', 'r') brown_train = infile.readlines() infile.close() brown_words, brown_tags = split_wordtags(brown_train) unigram_c, bigram_c, trigram_c = calc_ngram_counts(brown_tags) unigram_p, bigram_p, trigram_p, trigram_d = calc_ngram_probs( brown_tags, unigram_c, bigram_c, trigram_c) q_values = trigram_d q2_output(q_values, OUTPUT_PATH + 'B2.txt') known_words = calc_known(brown_words) brown_words_rare = replace_rare(brown_words, known_words) q3_output(brown_words_rare, OUTPUT_PATH + 'B3.txt') e_values, taglist = calc_emission(brown_words_rare, brown_tags) q4_output(e_values, OUTPUT_PATH + 'B4.txt') del brown_train del brown_words_rare infile = open(DATA_PATH + 'Brown_dev.txt', 'r') brown_dev = infile.readlines() infile.close() brown_dev_words = [] for sentence in brown_dev: brown_dev_words.append(sentence.split(' ')[:-1]) viterbi_tagged = viterbi(brown_dev_words, taglist, known_words, q_values, e_values) q5_output(viterbi_tagged, OUTPUT_PATH + 'B5.txt') nltk_tagged = nltk_tagger(brown_words, brown_tags, brown_dev_words) q6_output(nltk_tagged, OUTPUT_PATH + 'B6.txt') print 'Time: ' + str(time.close()) + ' sec'
ser.write(textthongbao) rcv = ser.read(9999) sleep(1) print rcv ser.write("\x1A") sleep(1) #ser.close() print "-------------\nDa gui xong sms" time = open('/var/www/html/system/time.txt', 'w+') now = datetime.datetime.now() timedagui = now.strftime("%Y-%m-%d %H:%M") print timedagui time.write(timedagui) time.close() kt = open('/var/www/html/system/check.txt', 'w') kt.write("0") kt.close() elif kiemtra == '0': #gui 1 sms ktsms = open('/var/www/html/sms/check.txt') kiemtrasms = ktsms.read(1) ktsms.close() if kiemtrasms == '1': smstl = open('/var/www/html/sms/memory/sms.txt') noidungsms = smstl.read() smstl.close()
import time #импортирование времени t = time.time() from time import time#импортирование времени и только его import time as f#импортирование как переменная t = f.time() sys.path#путс системы import imp imp.reload(foo)#перезагрузка модуля import os#работа с файловой системой os.getcwd()#где находимся os.chdir()#смена каталога os.listdir()#файлы в каталоге os.path.splittext('filename.ext') == '.ext'# os.isfile() os.isdir()#что именно f = open(a) text = """123""" f.write(text) f.close() g.read() #считывание по символам g.read(2) #docs.python.org - документация
def runTrajectories(self,theta, fonction): ''' Generates all the trajectories of the experimental setup and return the mean cost. This function is used by cmaes to optimize the controller. Input: -theta: vector of parameters, one dimension normalized numpy array Ouput: -meanAll: the mean of the cost of all trajectories generated, float ''' #c = Chrono() self.initTheta(theta) #print "theta avant appel :", theta #compute all the trajectories x times each, x = numberOfRepeat meanCost, meanTime = fonction(self.numberOfRepeat) #cma.plot() #opt = cma.CMAOptions() #print "CMAES options :", opt #c.stop() #print("Indiv #: ", self.call, "\n Cost: ", meanCost) if (self.call==0): self.localBestCost = meanCost self.localWorstCost = meanCost self.localBestTime = meanTime self.localWorstTime = meanTime self.periodMeanCost = 0.0 self.periodMeanTime = 0.0 else: if meanCost>self.localBestCost: self.localBestCost = meanCost elif meanCost<self.localWorstCost: self.localWorstCost = meanCost if meanTime>self.localBestTime: self.localBestTime = meanTime elif meanTime<self.localWorstTime: self.localWorstTime = meanTime if meanCost>self.bestCost: self.bestCost = meanCost if meanCost>0: extension = ".save" + str(meanCost) filename = findDataFilename(self.foldername+"Theta/", "theta", extension) np.savetxt(filename, self.theta) filename2 = self.foldername + "Best.theta" np.savetxt(filename2, self.theta) self.periodMeanCost += meanCost self.periodMeanTime += meanTime self.call += 1 self.call = self.call%self.period if (self.call==0): self.periodMeanCost = self.periodMeanCost/self.period self.periodMeanTime = self.periodMeanTime/self.period self.CMAESCostStore.append((self.localWorstCost,self.periodMeanCost,self.localBestCost)) self.CMAESTimeStore.append((self.localWorstTime,self.periodMeanTime,self.localBestTime)) costfoldername = self.foldername+"Cost/" checkIfFolderExists(costfoldername) cost = open(costfoldername+"cmaesCost.log","a") time = open(costfoldername+"cmaesTime.log","a") cost.write(str(self.localWorstCost)+" "+str(self.periodMeanCost)+" "+str(self.localBestCost)+"\n") time.write(str(self.localWorstTime)+" "+str(self.periodMeanTime)+" "+str(self.localBestTime)+"\n") cost.close() time.close() #np.savetxt(costfoldername+"cmaesCost.log",self.CMAESCostStore) #Note: inefficient, should rather add to the file #np.savetxt(costfoldername+"cmaesTime.log",self.CMAESTimeStore) #Note: inefficient, should rather add to the file return 10.0*(self.rs.rhoCF-meanCost)/self.rs.rhoCF