def mosrun_live(starttime): #1. 首先是下载EC数据, # yearint=datetime.datetime.now().year # hours=datetime.datetime.now().hour yearint = starttime.year hours = starttime.hour if hours >= 17: datestr = datetime.datetime.strftime(starttime, '%Y-%m-%d') pdatetimestring00 = datestr + " 00:00:00" print "2018-08-21 00:00:00" else: nowdate = starttime + datetime.timedelta(days=-1) datestr = datetime.datetime.strftime(nowdate, '%Y-%m-%d') pdatetimestring00 = datestr + ' 12:00:00' initial_datetime = datetime.datetime.strptime(pdatetimestring00, '%Y-%m-%d %H:%M:%S') #2.拷贝解压EC数据,线上的数据是拷贝的 oldfilepath = '/opt/meteo/cluster/data/ecmwf/orig' dirpath = '/moji/ecdata' print "2018-08-21 00:00:00-----------------------------------------------------------" ecpath = copyAndUnzipfile(initial_datetime, oldfilepath, dirpath) logger.info(ecpath) #3.DEM模型预测 # path = '/moji/ecdata' outpath = '/home/wlan_dev/result' csvfile = '/home/wlan_dev/stations.csv' demcsv = '/mnt/data/dem.csv' modelProdict(ecpath, outpath, csvfile, demcsv, starttime) #4.准确率计算 calculateAccuracy(initial_datetime) # 模型预测和准确率计算 modelpredict001(ecpath, outpath, csvfile, starttime) calculateAccuracy001(initial_datetime) print ecpath
def run(): #1. 首先是下载EC数据, starttime = datetime.datetime.now() yearint = datetime.datetime.now().year hours = datetime.datetime.now().hour if hours > 17: datestr = datetime.datetime.strftime(starttime, '%Y-%m-%d') pdatetimestring00 = datestr + " 00:00:00" else: nowdate = starttime + datetime.timedelta(days=-1) datestr = datetime.datetime.strftime(nowdate, '%Y-%m-%d') pdatetimestring00 = datestr + ' 12:00:00' initial_datetime = datetime.datetime.strptime(pdatetimestring00, '%Y-%m-%d %H:%M:%S') downloadECdatafrombigdata_processing(initial_datetime) #2.解压EC数据 oldfilepath = '/opt/meteo/cluster/data/ecmwf/orig' dirpath = '/moji/ecdata' ecpath = unzipfile(oldfilepath, dirpath) logger.info(ecpath) #3.DEM模型预测 # path = '/moji/ecdata' outpath = '/home/wlan_dev/result' csvfile = '/home/wlan_dev/stations.csv' demcsv = '/mnt/data/dem.csv' modelProdict(ecpath, outpath, csvfile, demcsv, starttime) #4.准确率计算 calculateAccuracy(initial_datetime) # 模型预测和准确率计算 modelpredict001(ecpath, outpath, csvfile, starttime) calculateAccuracy001(initial_datetime) #5.删除EC数据 if hours < 12: print ecpath deleteECMWF(ecpath)
def mosrun_history(starttime): #1. 首先是下载EC数据, # yearint=datetime.datetime.now().year # hours=datetime.datetime.now().hour yearint = starttime.year hours = starttime.hour if hours > 17: datestr = datetime.datetime.strftime(starttime, '%Y-%m-%d') pdatetimestring00 = datestr + " 00:00:00" print "2018-08-21 00:00:00" else: nowdate = starttime + datetime.timedelta(days=-1) datestr = datetime.datetime.strftime(nowdate, '%Y-%m-%d') pdatetimestring00 = datestr + ' 12:00:00' initial_datetime = datetime.datetime.strptime(pdatetimestring00, '%Y-%m-%d %H:%M:%S') logger.info(initial_datetime) #传入时间为00点或者是12点 downloadECdatafrombigdata(initial_datetime) #2.解压EC数据 dirpath = '/moji/ecdata' print "2018-08-21 00:00:00-----------------------------------------------------------" ecpath = unzipfile(initial_datetime, dirpath) print ecpath + '===================================================================' #3.DEM模型预测 # path = '/moji/ecdata' outpath = '/home/wlan_dev/result' csvfile = '/home/wlan_dev/stations.csv' demcsv = '/mnt/data/dem.csv' modelProdict(ecpath, outpath, csvfile, demcsv, initial_datetime) #4.准确率计算 calculateAccuracy(initial_datetime) # 模型预测和准确率计算 modelpredict001(ecpath, outpath, csvfile, starttime) calculateAccuracy001(initial_datetime) print ecpath #5.删除EC数据 if hours < 12: deleteECMWF(ecpath)
def mosrun_history(starttime): #1. 首先是下载EC数据, # yearint=datetime.datetime.now().year # hours=datetime.datetime.now().hour yearint=starttime.year hours=starttime.hour #给定时间世界时大于17计算本天的,否则计算昨天的12点的 if hours>17: datestr=datetime.datetime.strftime(starttime,'%Y-%m-%d') pdatetimestring00 = datestr+" 00:00:00" else: nowdate=starttime+datetime.timedelta(days=-1) datestr=datetime.datetime.strftime(nowdate,'%Y-%m-%d') pdatetimestring00 = datestr+' 12:00:00' initial_datetime = datetime.datetime.strptime(pdatetimestring00,'%Y-%m-%d %H:%M:%S') #传入时间为00点或者是12点 downloadECdatafrombigdata(initial_datetime) #2.解压EC数据 dirpath='/home/wlan_dev/mosdata' print "-----------------------------------------------------------" ecpath=unzipfile(initial_datetime,dirpath) print ecpath+'===================================================================' #3.DEM模型预测 # path = '/moji/ecdata' outpath = '/home/wlan_dev/mos/mosresult' csvfile = '/mnt/data/mosfile/stations.csv' demcsv = '/mnt/data/mosfile/dem0.1.csv' #modelProdict(ecpath, csvfile, demcsv,initial_datetime) ecfilename= os.path.split(ecpath)[1] readymodel(initial_datetime,dirpath) #4.准确率计算 calculateAccuracy(initial_datetime) calculateAccuracy2(initial_datetime) # 模型预测和准确率计算 # modelpredict001(ecpath,outpath,csvfile,starttime) # calculateAccuracy001(initial_datetime) print ecpath
def runmodel(oldfilepath, dirpath): starttime = datetime.datetime.now() #这里还是开始时间 starttimestring = datetime.datetime.strftime(starttime, '%Y-%m-%d %H:%M:%S') #starttime=datetime.datetime.strptime('2018-09-15 20:00:00','%Y-%m-%d %H:%M:%S') yearstr = starttime.year monthstr = starttime.month daystr = starttime.day hourstr = starttime.hour if hourstr < 17: #把实时时间转成00时的时间传给计算准确率的函数 ppdatetime = datetime.datetime(yearstr, monthstr, daystr, 0, 0, 0) starttimestring = datetime.datetime.strftime(ppdatetime, '%Y-%m-%d %H:%M:%S') dict = {} nowdate = starttime + datetime.timedelta(days=-1) datepath = datetime.datetime.strftime(nowdate, '%Y-%m-%d') filepath = oldfilepath + '/' + str(yearstr) + '/' + datepath midpath = dirpath + '/' + str(yearstr) if not os.path.exists(midpath): os.mkdir(midpath) tofilepath = dirpath + '/' + str(yearstr) + '/' + datepath if not os.path.exists(tofilepath): os.mkdir(tofilepath) for root, dirs, files in os.walk(filepath): for file in files: if file[:3] == 'D1D' and file[7:9] == '12' and file[ -7:-4] == '001' and file[-4:] == '.bz2': filename = os.path.join(root, file) logging.info(filename) dict[filename] = tofilepath #chain为串行,group并行 result = group( simplemodelProdict.s(key, value, yearstr) for key, value in dict.items())() #logging.info(result) else: #传入的日期的时间 ppdatetime = datetime.datetime(yearstr, monthstr, daystr, 12, 0, 0) starttimestring = datetime.datetime.strftime(ppdatetime, '%Y-%m-%d %H:%M:%S') dict00 = {} datepath = datetime.datetime.strftime(starttime, '%Y-%m-%d') filepath = oldfilepath + '/' + str(yearstr) + '/' + datepath midpath = dirpath + '/' + str(yearstr) if not os.path.exists(midpath): os.mkdir(midpath) tofilepath = dirpath + '/' + str(yearstr) + '/' + datepath if not os.path.exists(tofilepath): os.mkdir(tofilepath) for root, dirs, files in os.walk(filepath): for file in files: if file[:3] == 'D1D' and file[7:9] == '00' and file[ -7:-4] == '001' and file[-4:] == '.bz2': filename = os.path.join(root, file) logging.info(filename) dict00[filename] = tofilepath #注意后面有个括号。 result = group( simplemodelProdict.s(key, value, yearstr) for key, value in dict00.items())() #logging.info(result) #然后计算准确率 calculateAccuracy(starttimestring) deleteECMWF(dirpath)