def post_processing(): try: originPath = full_path # Copy INP and Output files to Collect Folder files = get_files_path(originPath) INP_OUT_Directory = originPath + "\%s" % (INP_OUT) WP1_Directory = originPath + "\%s" % (WP1_FOLDER) Complete_WP1_Directory = originPath + "\%s" % (COMPLETE_WP1_FOLDER) # os.remove(os.path.join(PRE_FOLDER_DAT_FILE,WP1MO_DATA_FILE)) fo = open(os.path.join(PRE_FOLDER_DAT_FILE, WP1MO_DATA_FILE), "wb") count = 0 maxLength = getMaxLengthOfFileName(files) for f in files: uF = f.upper() # os.remove(os.path.join(originPath,DAT_FILE_NAME)) if (uF.endswith(EXTEND_FILE_INP)): check_dly_name = f[:f.index('.')] coors = support_WEATHER.get_coordinate_follow_dly_file_name(check_dly_name) #coors = None if (coors): data_coors = coors.split("|") str_X = data_coors[0] str_Y = data_coors[1] else: str_X = "0.00" str_Y = "0.00" if (float(str_X)): fl_X = float(str_X) else: fl_X = 0.0 if (float(str_Y)): fl_Y = float(str_Y) else: fl_Y = 0.0 str_X = "%0.2f" %(fl_X) str_Y = "%0.2f" %(fl_Y) try: count = count + 1 copy_dly_file(os.path.join(originPath, f), INP_OUT_Directory) newName = f[:f.index('.')] newName = newName + ".WP1" os.rename(f, newName) # print ("ThanhNH %d %d" %(maxLength, getLengthString(newName))) if (maxLength == getLengthString(newName)): if (count >= 1 and count <= 9): #fo.write(" %d %s %0.2f %0.2f %s" % (count, newName, 0.0, 0.0, newName)) strContent = " %d %s" % (count, newName) # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) fo.write(strContent) elif (count >= 10 and count <= 99): #fo.write(" %d %s %0.2f %0.2f %s" % (count, newName, 0.0, 0.0, newName)) strContent = " %d %s" % (count, newName) # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) fo.write(strContent) elif (count >= 100 and count <= 999): #fo.write(" %d %s %0.2f %0.2f %s" % (count, newName, 0.0, 0.0, newName)) strContent = " %d %s" % (count, newName) # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) fo.write(strContent) elif (count >= 1000 and count <= 9999): #fo.write(" %d %s %0.2f %0.2f %s" % (count, newName, 0.0, 0.0, newName)) strContent = " %d %s" % (count, newName) # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) fo.write(strContent) elif (count >= 10000 and count <= 99999): #fo.write("%d %s %0.2f %0.2f %s" % (count, newName, 0.0, 0.0, newName)) strContent = "%d %s" % (count, newName) # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) fo.write(strContent) else: sys.exit("---[ERROR] : Number and Index of File are too much. Cannot fix to format of file") else: numberOfSpaces = maxLength - getLengthString(newName) # print("ThanhNH : %d" %(numberOfSpaces)) if (count >= 1 and count <= 9): strContent = " %d" %(count) # Add name for i in range(0,numberOfSpaces): strContent = strContent + " " strContent = strContent + newName # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) elif (count >= 10 and count <= 99): strContent = " %d" %(count) # Add name for i in range(0,numberOfSpaces): strContent = strContent + " " strContent = strContent + newName # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) elif (count >= 100 and count <= 999): strContent = " %d" %(count) # Add name for i in range(0,numberOfSpaces): strContent = strContent + " " strContent = strContent + newName # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) elif (count >= 1000 and count <= 9999): strContent = " %d" %(count) # Add name for i in range(0,numberOfSpaces): strContent = strContent + " " strContent = strContent + newName # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) elif (count >= 10000 and count <= 99999): strContent = "%d" %(count) # Add name for i in range(0,numberOfSpaces): strContent = strContent + " " strContent = strContent + newName # Add Y to number_space = 9 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 9 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" strContent = strContent + " %s" %(newName) else: sys.exit("---[ERROR] : Number and Index of File are too much. Cannot fix to format of file") fo.write(strContent) fo.write("\r\n") copy_dly_file(os.path.join(originPath, newName), WP1_Directory) copy_dly_file(os.path.join(originPath, newName), Complete_WP1_Directory) os.remove(os.path.join(originPath, newName)) except OSError: pass elif uF.endswith(EXTEND_FILE_OUT): try: copy_dly_file(os.path.join(originPath, f), INP_OUT_Directory) os.remove(os.path.join(originPath, f)) except OSError: pass elif uF.endswith(EXTEND_FILE_DAILY_WEATHER): try: os.remove(os.path.join(originPath, f)) except OSError: pass try: os.remove(os.path.join(originPath, DAT_FILE_NAME)) except OSError : pass except Exception, err: print('---[Waiting]: Please waiting to complete task %s' % (err))
def createWDLSTCOMDatFile(weather_folder): if (weather_folder is None): sys.exit("---[Error] : Folder that contains DLY files are NOT existed") if not os.path.exists(weather_folder): sys.exit("---[Error] : Folder that contains DLY files are NOT existed") try: fo = open(os.path.join(PRE_FOLDER_DAT_FILE, WDLST_DATA_FILE), "wb") DLYFiles = get_files_path(weather_folder) count = 0 for f in DLYFiles: check_dly_name = f[:f.index('.')] coors = support_WEATHER.get_coordinate_follow_dly_file_name(check_dly_name) #coors = None if (coors): data_coors = coors.split("|") str_X = data_coors[0] str_Y = data_coors[1] else: str_X = "0.00" str_Y = "0.00" if (float(str_X)): fl_X = float(str_X) else: fl_X = 0.0 if (float(str_Y)): fl_Y = float(str_Y) else: fl_Y = 0.0 str_X = "%0.2f" %(fl_X) str_Y = "%0.2f" %(fl_Y) uF = f.upper() count = count + 1 if uF.endswith(EXTEND_FILE_DAILY_WEATHER): if (count == 1): strContent = " %d %s" % (count, f) # Add Y to number_space = 11 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 11 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" else: if (count >= 2 and count <= 9): strContent = "\r\n %d %s" % (count, f) # Add Y to number_space = 11 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 11 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" elif (count >= 10 and count <= 99): strContent = "\r\n %d %s" % (count, f) # Add Y to number_space = 11 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 11 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" elif (count >= 100 and count <= 999): strContent = "\r\n %d %s" % (count, f) # Add Y to number_space = 11 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 11 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" elif (count >= 1000 and count <= 9999): strContent = "\r\n %d %s" % (count, f) # Add Y to number_space = 11 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 11 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" elif (count >= 10000 and count <= 99999): strContent = "\r\n%d %s" % (count, f) # Add Y to number_space = 11 - len(str_Y) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_Y else: strContent = strContent + " 0.00" # Add X to number_space = 11 - len(str_X) if (number_space > 0): for i in range(0,number_space): strContent = strContent + " " strContent = strContent + str_X else: strContent = strContent + " 0.00" fo.write(strContent) print("---Created %s file already---" % (WDLST_DATA_FILE)) fo.write("\r\n") return 1 except Exception, err: sys.stderr.write('---[Error]: Write file raised Error %s ' % (err))