28 number = 8 * (
int(stave)-1) + module
37 os.chdir(searchFolderPath)
39 print(
'No entries in ' + searchFolderPath)
45 for src_dir, dirs, files
in os.walk(searchFolderPath):
49 sortedFile = os.path.join(src_dir, file_)
50 todaysList.append(
str(sortedFile))
61 def appendEntries(fileName, dataType, dataFolder, dateEntries, largestDates, firstDate, lastDate, borkDate):
64 with open(fileName,
'r')
as rawFiles:
66 returnList = [firstDate, largestDates,
67 borkDate, dateEntries, firstDate]
73 for dataLine
in rawFiles:
75 index_Jennet = index_Jennet + 1
80 commaSplit = dataLine.split(
',')
82 if '!!!!' in dataLine:
85 if len(commaSplit) < 2:
90 moduleList = dataLine.split(
'!!!')
92 for module
in moduleList:
94 elements = module.split(
',')
102 moduleName =
'LI_S' +
str(A) +
'_' +
str(B)
104 moduleNumber =
int(2 * (
int(A)-1)-1)
108 outName = dataFolder+dataType+
'/' + moduleName +
'.ssv'
111 mode =
'a' if os.path.isfile(outName)
else 'w'
112 with open(outName, mode)
as output:
116 for element
in elements:
120 tempLines = element.split()
121 date = tempLines[1].
split(
'-')
122 time1 = tempLines[2].
split(
':')
125 dateTime = datetime.datetime(
int(date[2]),
int(date[1]),
int(
126 date[0]),
int(time1[0]),
int(time1[1]),
int(time1[2]),
int(time1[3]))
128 if (dateTime > lastDate+datetime.timedelta(hours=2))
or (dateTime < firstDate - datetime.timedelta(hours=2)):
129 returnList[2] = lastDate
130 print(
"\nBORK BORK BORK! Error in date of " + fileName +
131 " for " + dataType +
" borkDate " +
str(returnList[2]))
133 "First line reads " + dataLine +
"\n")
135 "Should read " + moduleName+
"_"+dataType+
"\n")
137 with open(dataFolder+dataType+
"BORKBORKBORK.txt",
'w')
as borkRepork:
138 borkRepork.write(
"filename " + fileName +
"date range " +
str(
139 firstDate) +
"-" +
str(lastDate) +
" first line " + dataLine +
'\n')
143 if dateTime > returnList[1][moduleNumber]:
144 returnList[3][moduleNumber] += 1
145 outputLine = moduleName +
"_" + dataType +
" " + \
146 str(dateTime) +
" " +
str(time.mktime(
147 dateTime.timetuple())) +
" " +
str(data) +
"\n"
149 returnList[1][moduleNumber] = dateTime
151 output.write(outputLine)
156 returnList[2] = lastDate
157 print(
"Something broke :( \n")
158 print(
"Could be an error in data values of " + fileName +
159 " for " + dataType +
" borkDate " +
str(returnList[2]))
160 print(
"First line reads " + name +
"\n")
162 with open(dataFolder+dataType+
"BORKBORKBORK.txt",
'w')
as borkRepork:
163 borkRepork.write(
"filename " + fileName +
"date range " +
str(
164 firstDate) +
"-" +
str(lastDate) +
" first line " + dataLine +
'\n')
166 "Try running again... often this is an issue with the connection to eos")
170 print(
"could not open file " +
str(fileName) +
" fool")
180 fillerDate = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
181 returnList = [fillerDate, fillerDate, fillerDate,
False,
"LI_S00_0_M0"]
183 homeDirectory = os.path.expanduser(
184 '/eos/atlas/user/j/jdickins/Pixel/LeakageCurrent/')
187 dataFolder = homeDirectory +
"/IBLData/processedData/"
188 inputFolder = homeDirectory +
"/IBLData/rawData/"+dataType+
"/"
189 entriesFolder = homeDirectory +
"/IBLData/rawData/entriesPerDay/" + dataType +
"/"
192 if not os.path.exists(dataFolder+dataType):
193 os.mkdir(dataFolder+dataType)
195 if not os.path.exists(entriesFolder):
196 os.mkdir(entriesFolder)
204 smallestEndDate = fillerDate
207 if not os.path.exists(dataFolder+dataType+
".txt"):
210 print(
"No any file found! at " + dataFolder +
211 dataType +
" Making default values")
214 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
215 firstTempDate = datetime.datetime(2015, 5, 1, 0, 0, 0, 0)
216 lastTempDate = datetime.datetime(2015, 5, 1, 0, 0, 0, 1)
217 smallestEndDate = lastTempDate
219 for stave
in range(1, 15):
220 staveString =
str(stave)
222 staveString =
"0"+
str(stave)
223 for side
in [
'A',
'C']:
224 moduleName =
'LI_S' +
str(staveString) +
'_' + side
226 moduleName +
" " +
str(firstTempDate) +
" " +
str(lastTempDate) +
" 0 0\n")
227 startingDates.append(firstTempDate)
228 endDates.append(lastTempDate)
229 filesProcessed.append(0)
231 dailyPoints.append(0)
234 print(
"Found " + dataFolder+dataType+
".txt")
235 with open(dataFolder+dataType+
".txt",
'r')
as datesFile:
239 for dateLine
in datesFile:
241 tempDatesLine = dateLine.split()
242 filesProcessed.append(
int(tempDatesLine[5]))
243 dataPoints.append(
int(tempDatesLine[6]))
244 dailyPoints.append(0)
246 firstTemp = tempDatesLine[1].
split(
'-')
247 lastTemp = tempDatesLine[3].
split(
'-')
249 firstTempTime = tempDatesLine[2].
split(
':')
250 lastTempTime = tempDatesLine[4].
split(
':')
252 firstTempTimes = firstTempTime[2].
split(
'.')
253 lastTempTimes = lastTempTime[2].
split(
'.')
255 if len(firstTempTimes) < 2:
256 firstTempTimes.append(0)
257 if len(lastTempTimes) < 2:
258 lastTempTimes.append(0)
260 firstTempDate = datetime.datetime(
int(firstTemp[0]),
int(firstTemp[1]),
int(firstTemp[2]),
int(
261 firstTempTime[0]),
int(firstTempTime[1]),
int(firstTempTimes[0]),
int(firstTempTimes[1]))
262 lastTempDate = datetime.datetime(
int(lastTemp[0]),
int(lastTemp[1]),
int(lastTemp[2]),
int(
263 lastTempTime[0]),
int(lastTempTime[1]),
int(lastTempTimes[0]),
int(lastTempTimes[1]))
265 startingDates.append(firstTempDate)
266 endDates.append(lastTempDate)
269 returnList[0] = firstTempDate
270 returnList[1] = lastTempDate
271 smallestEndDate = lastTempDate
274 if firstTempDate < returnList[0]:
275 returnList[0] = firstTempDate
276 if lastTempDate > returnList[1]:
277 returnList[1] = lastTempDate
278 if lastTempDate < smallestEndDate:
279 smallestEndDate = lastTempDate
283 print(
"Investigating " + dataType +
" from " +
str(smallestEndDate))
290 firstTempDate = startingDates[0]
291 lastTempDate = endDates[0]
295 for fileName
in fileList:
300 endDate1 = fileName[end-4:end]
301 endDate2 = fileName[end-7:end-6]
304 if endDate1 ==
'.txt' and endDate2 ==
'_':
306 startDate = fileName[end-23:end-15]
307 endDate = fileName[end-12:end-4]
308 endDateSplit = endDate.split(
'_')
309 endDateFile = datetime.datetime(
310 2000+
int(endDateSplit[0]),
int(endDateSplit[1]),
int(endDateSplit[2]), 0, 0, 0, 1)
312 startDateSplit = startDate.split(
'_')
313 startDateFile = datetime.datetime(
314 2000+
int(startDateSplit[0]),
int(startDateSplit[1]),
int(startDateSplit[2]), 0, 0, 0, 1)
316 if endDateFile > smallestEndDate:
319 lastTempDate = endDateFile
320 [firstTempDate, endDates, fillerDate, tempDataNumbers, smallestEndDate] =
appendEntries(
321 fileName, dataType, dataFolder, dailyPoints, endDates, startDateFile, endDateFile, fillerDate)
325 for i
in range(0, 28):
326 filesProcessed[i] += 1
328 dataPoints[i] += tempDataNumbers[i]
333 for stave
in range(1, 15):
334 staveString =
str(stave)
336 staveString =
"0"+
str(stave)
337 for side
in [
'A',
'C']:
338 moduleName =
'LI_S' +
str(staveString) +
'_' + side
339 outName = entriesFolder + moduleName +
".txt"
340 dataLine =
str(startDate) +
" " + \
341 str(tempDataNumbers[holderX]) +
"\n"
342 tempDataNumbers[holderX] = 0
344 mode =
'a' if os.path.isfile(outName)
else 'w'
345 with open(outName, mode)
as output:
346 output.write(dataLine)
350 if returnList[2] != fillerDate:
351 returnList[2] = fillerDate
352 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
354 for stave
in range(1, 15):
355 staveString =
str(stave)
357 staveString =
"0"+
str(stave)
358 for side
in [
'A',
'C']:
359 moduleName =
'LI_S' + \
360 str(staveString) +
'_' + side
361 datesFile.write(moduleName +
" " +
str(startingDates[tempHolder]) +
" " +
str(
362 endDates[tempHolder]) +
" " +
str(filesProcessed[tempHolder]) +
" " +
str(dataPoints[tempHolder]) +
"\n")
377 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
379 for staveX
in range(1, 15):
380 staveStringX =
str(staveX)
382 staveStringX =
"0"+
str(staveX)
383 for sideX
in [
'A',
'C']:
384 moduleNameX =
'LI_S' +
str(staveStringX) +
'_' + sideX
385 datesFile.write(moduleNameX +
" " +
str(startingDates[tempHolder]) +
" " +
str(
386 endDates[tempHolder]) +
" " +
str(filesProcessed[tempHolder]) +
" " +
str(dataPoints[tempHolder]) +
"\n")
396 threading.Thread.__init__(self)
401 print(
"Starting getPipeDate.py for " + self.
name)
403 print(
"Exiting getPipeDate.py for " + self.
name +
" with no issues, data range from " +
404 str(returnList[0]) +
" to " +
str(returnList[1]))
417 if __name__ ==
"__main__":