23 from os.path
import expanduser
25 from datetime
import date, timedelta
33 yield curr,
min(curr + delta, end)
42 yield max(curr - delta, start), curr
51 os.chdir(searchFolderPath)
53 print(
'No entries in ' + searchFolderPath)
59 for src_dir, dirs, files
in os.walk(searchFolderPath):
64 sortedFile = os.path.join(src_dir, file_)
65 todaysList.append(
str(sortedFile))
77 fillerDate = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
78 tempDate = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
79 returnList = [fillerDate, fillerDate, fillerDate]
87 if not os.path.exists(dataFolder+dataType+
".txt"):
88 print(
"No any file found! at " + dataFolder +
89 dataType +
" Making default values")
91 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
92 firstTempDate = datetime.datetime(2015, 1, 1, 1, 1, 1, 1)
93 lastTempDate = datetime.datetime(2015, 1, 1, 1, 1, 1)
95 datesFile.write(dataType +
" " +
str(firstTempDate) +
" " +
96 str(lastTempDate) +
"\n")
97 startingDates.append(firstTempDate)
98 endDates.append(lastTempDate)
102 print(
"Found " + dataFolder+dataType+
".txt")
103 with open(dataFolder+dataType+
".txt",
'r')
as datesFile:
105 for dateLine
in datesFile:
106 tempDatesLine = dateLine.split()
107 firstTemp = tempDatesLine[1].
split(
'-')
108 lastTemp = tempDatesLine[3].
split(
'-')
110 firstTempTime = tempDatesLine[2].
split(
':')
111 lastTempTime = tempDatesLine[4].
split(
':')
113 firstTempTimes = firstTempTime[2].
split(
'.')
114 lastTempTimes = lastTempTime[2].
split(
'.')
116 if len(firstTempTimes) < 2:
117 firstTempTimes.append(0)
118 if len(lastTempTimes) < 2:
119 lastTempTimes.append(0)
121 firstTempDate = datetime.datetime(
122 int(firstTemp[0]),
int(firstTemp[1]),
int(firstTemp[2]),
123 int(firstTempTime[0]),
int(firstTempTime[1]),
124 int(firstTempTimes[0]),
int(firstTempTimes[1]))
125 lastTempDate = datetime.datetime(
126 int(lastTemp[0]),
int(lastTemp[1]),
int(lastTemp[2]),
127 int(lastTempTime[0]),
int(lastTempTimes[0]),
128 int(lastTempTimes[0]),
int(lastTempTimes[1]))
130 startingDates.append(firstTempDate)
131 endDates.append(lastTempDate)
133 datesList = [startingDates, endDates]
143 url =
'http://atlas-ddv.cern.ch:8089/multidata/getDataSafely'
144 url2 =
'http://atlas-ddv.cern.ch:8089/multidata/downloadTxtData'
147 defaultPath = os.path.expanduser(
148 '/eos/atlas/user/j/jdickins/Pixel/LeakageCurrent/')
151 dataFolder = defaultPath +
"/IBLData/rawData/"
154 if not os.path.exists(dataFolder):
157 if not os.path.exists(dataFolder+dataType):
158 os.mkdir(dataFolder+dataType)
160 [startDates, endDates] =
checkDates(dataType, dataFolder)
161 currentDay = date.today()
162 firstDay = endDates[0].
date()-timedelta(days=1)
171 if firstDay+timedelta(days=1) < currentDay:
172 for s, e
in perdelta(firstDay, currentDay, timedelta(days=1)):
173 if not os.path.exists(dataFolder+dataType+
'/'):
174 os.mkdir(dataFolder+dataType+
'/')
176 if not os.path.exists(dataFolder+dataType+
'Stave/'):
177 os.mkdir(dataFolder+dataType+
'Stave/')
179 saveFileName2 = dataFolder+dataType+
'/' + \
180 s.strftime(
"%Y_%m_%d") +
'-' + e.strftime(
"%Y_%m_%d") +
'.txt'
181 if os.path.exists(saveFileName2):
182 os.remove(saveFileName2)
184 with open(saveFileName2,
'w')
as saveFile:
188 staveString =
"stave"
189 staveLetter =
"stave"
190 letterDict = {1:
'a', 2:
'b', 3:
'c', 4:
'd', 5:
'e', 6:
'f', 7:
'g', 8:
'h',
191 9:
'i', 10:
'j', 11:
'k', 12:
'l', 13:
'm', 14:
'n'}
192 for staveNumber
in range(1, 15):
194 staveString =
"0" +
str(staveNumber)
196 staveString =
str(staveNumber)
197 staveLetter = letterDict[staveNumber]
198 if staveNumber % 2 == 1:
205 dataFolder+dataType+
'Stave/'+s.strftime(
"%Y_%m_%d") +
206 '-' + e.strftime(
"%Y_%m_%d") +
'Stave' + staveString +
208 if os.path.exists(saveFileName):
209 os.remove(saveFileName)
211 dataType2 = dataType + staveLetter
214 cmd =
'wget --post-data "queryInfo=atlas_pvssPIX, alias, LI_S' + staveString +
'_A_' + dataType2 +
', ' + s.strftime(
"%d-%m-%Y") +
' 00:00, ' + e.strftime(
215 "%d-%m-%Y") +
' 00:01, , , , , ,no, , +2!atlas_pvssPIX, alias, LI_S' + staveString +
'_C_' + dataType2 +
', ' + s.strftime(
"%d-%m-%Y") +
' 00:00, ' + e.strftime(
"%d-%m-%Y") +
' 00:01, , , , , ,no, , +2!" ' + url +
' --output-document=' + saveFileName
220 if (os.path.getsize(saveFileName) < 300):
223 sleepTime = random.randint(30, 62)
224 time.sleep(sleepTime)
225 os.remove(saveFileName)
227 cmd =
'wget --post-data "queryInfo=atlas_pvssPIX, alias, LI_S' + staveString +
'_A_' + dataType2 +
', ' + s.strftime(
"%d-%m-%Y") +
' 00:00, ' + e.strftime(
228 "%d-%m-%Y") +
' 00:01, , , , , ,no, , +2!atlas_pvssPIX, alias, LI_S' + staveString +
'_C_' + dataType2 +
', ' + s.strftime(
"%d-%m-%Y") +
' 00:00, ' + e.strftime(
"%d-%m-%Y") +
' 00:01, , , , , ,no, , +2!" ' + url +
' --output-document=' + saveFileName
233 if (0 < os.path.getsize(saveFileName) < 300):
236 os.remove(saveFileName)
237 print(
"bork bork at " + s.strftime(
"%Y_%m_%d") +
238 " please sign off yourself!")
241 with open(saveFileName,
'r')
as bloop:
243 if (staveNumber != 1):
244 saveFile.write(
"!!!")
248 for bloopLine
in bloop:
249 saveFile.write(bloopLine)
252 introubleMean += introuble
254 introubleCount.append(introuble)
255 sleepTime = random.randint(30, 62)
257 time.sleep(sleepTime)
259 breakThatStick =
False
261 if introubleMean > 30:
262 for checker
in range(0, 14):
263 if introubleCount[checker] < 2:
265 print(
"borkalork in stave " +
str(checker+1))
266 breakThatStick =
True
269 print(
"breaking now at " + s.strftime(
"%d-%m-%Y"))
272 firstTempDate =
min(datetime.datetime(
273 s.year, s.month, s.day, 0, 0, 0, 0), startDates[0])
274 startDates[0] = firstTempDate
276 lastTempDate =
max(datetime.datetime(
277 e.year, e.month, e.day, 0, 0, 0, 0), endDates[0])
278 endDates[0] = lastTempDate
280 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
281 datesFile.write(dataType +
" " +
str(firstTempDate) +
" " +
282 str(lastTempDate) +
"\n")
284 sleepTime = random.randint(10, 30)
285 time.sleep(sleepTime)
304 if __name__ ==
"__main__":