示例#1
0
    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()
示例#2
0
def create_time_skeleton():
    with open('FINAL/aktualne/time_plus_3_minutes.csv', 'w') as time:
        base = datetime.datetime.strptime('2017-05-01 00:00:00',
                                          "%Y-%m-%d %H:%M:%S")
        baseP = datetime.datetime.strptime('2017-05-01 00:03:00',
                                           "%Y-%m-%d %H:%M:%S")
        for _ in range(604800):
            time.write(
                base.strftime("%Y-%m-%d %H:%M:%S") + ';' +
                baseP.strftime("%Y-%m-%d %H:%M:%S") + ';\n')
            base += datetime.timedelta(seconds=1)
            baseP += datetime.timedelta(seconds=1)
示例#3
0
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()
示例#4
0
		tn = telnetlib.Telnet(VSwitch_add, VSwitch_port)
		time.sleep(0.3)
		tn.write("\x01\x83\x82\x81")
		tn.close()
	except socket.error:
		print 'no connection to VideoSwitch'

def Painting(str1,str2)
	try:
		tn = telnetlib.Telnet(Relay_add, Relay_port)
		time.sleep(1)
		tn.write("\n")
		time.sleep(1)
		tn.write(str1)
		time.sleep(1)
		time.write(str2)
		time.sleep(1)
		tn.close()
	except socket.error:
		print 'no connection to Painting'


try:
	soc.bind((host, port))              # Bind to the port
except socket.error as e:
	print(str(e))

soc.listen(5)                           # Now wait for client connection.
print("Waiting for connections..")

while True:
示例#5
0
            if ball.xcor() > 340 and ball.xcor() < 350 and ball.ycor() < paddle_b.ycor() + 40 and ball.ycor() > paddle_b.ycor() - 40:
                ball.setx(340)
                ball.dx *=-1    
            
            if ball.xcor() <-340 and ball.xcor() > -350 and ball.ycor() < paddle_a.ycor() + 40 and ball.ycor() > paddle_a.ycor() - 40:
                ball.setx(-340)
                ball.dx *=-1    
            
              #for calculating score in endless mode using time

            elapsed_time = time.time() - start_time 

            score = int(elapsed_time)#FOR DETERMINING HIGHSCORE(NEEDED)
        
            if score_a==5: # game end
                something(score)
                WRITE_SCORE(user_name,score)
                time=turtle.Turtle()
                time.speed(0)
                time.color("white")
                time.penup()
                time.hideturtle()
                time.goto(0,-260)
                time.write( "SCORE ACHIEVED: {} HIGHSCORE: {}".format( int(elapsed_time), getHighScore()) , align="center", font=("Courier", 20,"normal"))
                sys.exit()




            
示例#6
0
文件: 1.py 项目: aglab2/PythonApps
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 - документация
示例#7
0
    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