def unzipGZ(fileNameGZ, fromDir, destDir): """ Unzip the file named fromDir+fileNameGZ in the folder destDir. """ # fromFile = fromDir + s.sepDir() + fileNameGZ destFile = destDir + s.sepDir() + fileNameGZ.rstrip(".gz") # print("Unzipping file %s in %s" % (fromFile, destDir)) # src = gzip.GzipFile(fromFile, 'rb') sRead = src.read() src.close() d = open(destFile, 'wb') d.write(sRead) d.close() print("Unzipped.")
def pwaFileChoice(chooseMode=None): """ finds the files contained in the "FOLDER_PWA" directory, and proposes to choose them, or not (for test instance creation). :Param chooseMode : None Asc for use the current files / 1 Always answer YES, 0 Always answer NO, Returns the list of selected files as a list files[] """ files = [] logDir = s.folder(s.FOLDER_PWA) content = os.listdir(logDir) for item in content: if chooseMode == None: r = int(input("Use this file %s ? (1 yes 0 no) : " % (item))) else: r = chooseMode # END IF if r == 1: files.append(logDir + s.sepDir() + item) # END IF # END FOR print(files) return files
def create(self, campaignName, campaignUser, campaignDate, generateMethode, seed, realFilesName, a, b, alpha, beta, lmbda, m, n, sType, matTimes, lowBound, matStatIndicators, optimal=None): # complete file name resDir = folderResultMatrix(campaignName, campaignUser, campaignDate) print(resDir) self.completeFileName = resDir + s.sepDir( ) + "instance_" + sType + "_" + generateMethode + "_" + str( seed) + "_" + str(n) + "_" + str(m) + ".json" print(self.completeFileName) # self.fileObj : json content # self.fileObj['campaign'] = [] self.fileObj['campaign'].append({ 'campaignName': campaignName, 'campaignUser': campaignUser, 'campaignDate': campaignDate }) # self.fileObj['generation_method'] = [] self.fileObj['generation_method'].append({ 'generateMethode': generateMethode, 'n': n, 'm': m, 'type': sType, 'seed': seed, 'reelFileName': realFilesName, 'a': a, 'b': b, 'alpha': alpha, 'beta': beta, 'lambda': lmbda }) # self.fileObj['features'] = [] self.fileObj['features'].append({ 'lowBound': lowBound, 'optimal': optimal, 'indicators': matStatIndicators }) # self.fileObj['matrix'] = [] self.fileObj['matrix'].append({'timeList': matTimes}) # Save file self.save()
def exportCSV(self): #==================================================================== # # EXPORT RESULT VIA DATA FRAME # #==================================================================== #------------------------------------ # target file # ...../result/campaignname_user_date/ file.csv #------------------------------------ resDir = s.folderResult(self.campaignName, self.campaignUser, self.campaignDate) filenameResult = resDir + s.sepDir()+ self.compainCompleteName+".csv" #------------------------------------ # chck for user #------------------------------------ print("Exporting campaign result to %s . please wait..." % (filenameResult)) # # collumns = "" dataResult = [] #print(len(self.matricies)) #------------------------------------ # one row per matrice instance and per algorithm. # one time for native instance # one time for completed m-1 instance #------------------------------------ for k in range(len(self.matricies)): # matricies[k] is a PTimes object items = self.matricies[k].getResultForCSV() for i in range(len(items)): dataResult.append(items[i]) # END FOR (for i in range(len(items)):) # END FOR (for k in range(len(self.matricies)):) #------------------------------------ # EXPORT #------------------------------------ expResultHeader = cm.PTimes.getResultForCSVHeader() expResult = pd.DataFrame(dataResult) #, collumns) expResult.to_csv(filenameResult, index=False, header=expResultHeader) #==================================================================== # # EXPORT matricies (Time lists) # #==================================================================== if s.EXP_INSTANCES: for k in range(len(self.matricies)): # matricies[k] is a PTimes object items = self.matricies[k] #------------------------------------ # native matrix part (json InstanceFile) #------------------------------------ instanceFileNative = s.InstanceFile() instanceFileNative.create(self.campaignName, self.campaignUser, self.campaignDate, items.generateMethode, items.seed, items.fileName, items.a, items.b, items.alpha,items.beta,items.lambd, items.m, items.n, "NATIVE", items.Times, items.LowBound, items.StatIndicators) #------------------------------------ # completed with m-1 jobs matrix part (json InstanceFile) #------------------------------------ instanceFileNative = s.InstanceFile() instanceFileNative.create(self.campaignName, self.campaignUser, self.campaignDate, items.generateMethode, items.seed, items.fileName, items.a, items.b, items.alpha,items.beta,items.lambd, items.m, items.m1_n, "COMPLETEDM1", items.m1Times, items.m1LowBound, items.m1StatIndicators, items.m1Optimal) # END FOR # END IF if s.EXP_INSTANCES: #==================================================================== # # COPY ANALYSIS SCRIPTS FROM AALYSIS TO RESULTS FOLDER # and EXECUTE THEME # #==================================================================== a = s.folder(s.FOLDER_ANALYSIS) content = os.listdir(a) for fileName in content: if fileName.endswith(".r"): # copy filePath = shutil.copy(a+s.sepDir()+fileName, resDir) # execute s.analysisExecute(resDir+s.sepDir()+fileName, resDir) # END IF # END FOR #==================================================================== # # COPY ANALYSIS SCRIPTS FROM AALYSIS TO RESULTS FOLDER # #==================================================================== #------------------------------------ # check for user #------------------------------------ print("Done !")
def create(self, campaignName, campaignUser, seedForce, N_NumberBegin, N_NumberEnd, N_List, M_NumberBegin, M_NumberEnd, M_List, matUniformNumber, matNonUniformNumber, matGammaNumber, matBetaNumber, matExponentialNumber, matRealFiles, A, B, Alpha, Beta, Lmbda, useLPT, useSLACK, useLDM, useCOMBINE, useMULTIFIT): # JSON PARAMETERS FILE self.campaignName = campaignName self.campaignUser = campaignUser # complete file name resDir = folderResult(self.campaignName, self.campaignUser, self.campaignDate) self.completeFileName = resDir + s.sepDir( ) + campaignFileParametersName(campaignName, campaignUser, self.campaignDate) # self.fileObj : json content # self.fileObj['campaign'] = [] self.fileObj['campaign'].append({ 'campaignName': self.campaignName, 'campaignUser': self.campaignUser, 'campaignDate': self.campaignDate }) # self.fileObj['size'] = [] self.fileObj['size'].append({ 'N_NumberBegin': N_NumberBegin, 'N_NumberEnd': N_NumberEnd, 'M_NumberBegin': M_NumberBegin, 'M_NumberEnd': M_NumberEnd, 'N_List': N_List, 'M_List': M_List }) # self.fileObj['generation_methods'] = [] self.fileObj['generation_methods'].append({ 'seedForce': seedForce, 'matUniformNumber': matUniformNumber, 'matNonUniformNumber': matNonUniformNumber, 'matGammaNumber': matGammaNumber, 'matBetaNumber': matBetaNumber, 'matExponentialNumber': matExponentialNumber }) # self.fileObj['generation_PWA'] = [] self.fileObj['generation_PWA'].append({'matRealFiles': matRealFiles}) # self.fileObj['generation_properties'] = [] self.fileObj['generation_properties'].append({ 'A': A, 'B': B, 'Alpha': Alpha, 'Beta': Beta, 'Lambda': Lmbda }) # self.fileObj['algorithms'] = [] self.fileObj['algorithms'].append({ 'useLPT': useLPT, 'useSLACK': useSLACK, 'useLDM': useLDM, 'useCOMBINE': useCOMBINE, 'useMULTIFIT': useMULTIFIT, }) # Save file self.save()