Commit 023b0969 authored by mickael's avatar mickael

New functions to search and show Buoys

parent 8ed6a81c
......@@ -80,13 +80,13 @@ def findBuoyElement( id, mydatetime, provider ='cdip_globwave_wave',intervaldays
#getFilePattern according to the provider
filepattern = getfilepattern(id,provider)
startdate = datetosearch - timedelta(days=intervaldays)
stopdate = datetosearch + timedelta(days=intervaldays)
startdate = mydatetime - timedelta(days=intervaldays)
stopdate = mydatetime + timedelta(days=intervaldays)
filelist = getfilelist(filepattern,startdate,stopdate,provider)
print len(filelist),"Found in",filepattern
index=-1
filepath=""
#init the interval to 365 days
#if no element is in 2 years interval that won't work
timeinterval=timedelta(days=365)
......@@ -104,10 +104,12 @@ def findBuoyElement( id, mydatetime, provider ='cdip_globwave_wave',intervaldays
timeinterval = tmptimeinterval
index = tmpidx
filepath = buoyFile
print index,filepath
print index,filepath,provider_to_type[provider]
return SpectrumReader.read_spectrum(filepath,provider_to_type[provider],index)
#return index,filepath
def returnBuoyElement( buoyFile, indexSpectrum, provider ='cdip_globwave_wave'):
return SpectrumReader.read_spectrum(buoyFile,provider_to_type[provider],indexSpectrum)
#Find all Element in fileSystem between startDate and endDate
......@@ -115,10 +117,12 @@ def findBuoyElement( id, mydatetime, provider ='cdip_globwave_wave',intervaldays
#Step 2 search in files the elements
#step 3 transform it to Spectrum object and add it to return list
#return list spectra
def findBuoyElementListFromFiles( id, startDate,endDate, provider ='cdip_globwave_wave',limit=50):
def findBuoyElementListFromFiles( id, startDate,endDate=None, provider ='cdip_globwave_wave',limit=50,returnSpectra=True):
#getFilePattern according to the provider
filepattern = getfilepattern(id,provider)
if endDate is None:
endDate = startDate + timedelta(days=365)
#startdate = datetosearch - timedelta(hours=intervalhours)
#stopdate = datetosearch + timedelta(hours=intervalhours)
......@@ -126,10 +130,6 @@ def findBuoyElementListFromFiles( id, startDate,endDate, provider ='cdip_globwav
print len(filelist),"File Found in",filepattern
index=-1
#init the interval to 365 days
#if no element is in 2 years interval that won't work
timeinterval=timedelta(days=365)
#timeinterval
listSpectra = []
cpt=0
for buoyFile in filelist:
......@@ -148,8 +148,10 @@ def findBuoyElementListFromFiles( id, startDate,endDate, provider ='cdip_globwav
endIndex-=1
#get all the elements
while startIndex<=endIndex:
listSpectra.append(SpectrumReader.read_spectrum(buoyFile,provider_to_type[provider],startIndex))
if returnSpectra:
listSpectra.append(SpectrumReader.read_spectrum(buoyFile,provider_to_type[provider],startIndex))
else:
listSpectra.append([buoyFile,provider_to_type[provider],startIndex])
cpt+=1
#If limit exceed return list
if cpt>limit:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment