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:
76 index_Jennet = index_Jennet + 1
81 commaSplit = dataLine.split(
',')
83 if '!!!!' in dataLine:
86 if len(commaSplit) < 2:
91 tempLines = dataLine.split()
97 moduleName =
'LI_S' + \
100 moduleNumber =
int(8 * (
int(A)-1) +
int(C)-1)
105 if (name != moduleName+
"_"+dataType)
or (len(tempLines) < 3):
106 returnList[2] = lastDate
107 print(
"\nBORK BORK BORK! Error in data values of " + fileName +
108 " for " + dataType +
" borkDate " +
str(returnList[2]))
109 print(
"First line reads " + dataLine+
"\n")
110 print(
"should read " + moduleName+
"_"+dataType+
"\n")
112 with open(dataFolder+dataType+
"BORKBORKBORK.txt",
'w')
as borkRepork:
113 borkRepork.write(
"filename " + fileName +
"date range " +
str(
114 firstDate) +
"-" +
str(lastDate) +
" first line " + dataLine +
'\n')
118 outName = dataFolder+dataType+
'/' + moduleName + \
121 date = tempLines[1].
split(
'-')
122 time1 = tempLines[2].
split(
':')
126 if dataType ==
'TModule':
129 data = abs(
float(tempLines[3]))
130 dateTime = datetime.datetime(
int(date[2]),
int(date[1]),
int(
131 date[0]),
int(time1[0]),
int(time1[1]),
int(time1[2]),
int(time1[3]))
134 if (dateTime > lastDate+datetime.timedelta(hours=2))
or (dateTime < firstDate - datetime.timedelta(hours=2)):
135 returnList[2] = lastDate
136 print(
"\nBORK BORK BORK! Error in date of " + fileName +
137 " for " + dataType +
" borkDate " +
str(returnList[2]))
138 print(
"First line reads " + dataLine +
"\n")
139 print(
"should read " + moduleName+
"_"+dataType+
"\n")
141 with open(dataFolder+dataType+
"BORKBORKBORK.txt",
'w')
as borkRepork:
142 borkRepork.write(
"filename " + fileName +
"date range " +
str(
143 firstDate) +
"-" +
str(lastDate) +
" first line " + dataLine +
'\n')
147 if dateTime > returnList[1][moduleNumber]:
148 returnList[3][moduleNumber] += 1
151 outputLine = moduleName+
'_'+dataType +
" " + \
152 str(dateTime) +
" " +
str(time.mktime(dateTime.timetuple())
153 ) +
" " +
str(data) +
"\n"
155 returnList[1][moduleNumber] = dateTime
158 mode =
'a' if os.path.isfile(outName)
else 'w'
159 with open(outName,
'w')
as output:
160 output.write(outputLine)
165 moduleList = dataLine.split(
'!!!')
167 for module
in moduleList:
169 elements = module.split(
',')
180 moduleName =
'LI_S' + \
184 moduleNumber =
int(8 * (
int(A)-1) +
int(C)-1)
188 outName = dataFolder+dataType+
'/' + moduleName +
'.ssv'
191 mode =
'a' if os.path.isfile(outName)
else 'w'
192 with open(outName, mode)
as output:
196 for element
in elements:
200 tempLines = element.split()
201 date = tempLines[1].
split(
'-')
202 time1 = tempLines[2].
split(
':')
206 if dataType ==
'TModule':
209 data = abs(
float(tempLines[0]))
211 dateTime = datetime.datetime(
int(date[2]),
int(date[1]),
int(
212 date[0]),
int(time1[0]),
int(time1[1]),
int(time1[2]),
int(time1[3]))
215 if (dateTime > lastDate+datetime.timedelta(hours=2))
or (dateTime < firstDate - datetime.timedelta(hours=2)):
216 returnList[2] = lastDate
217 print(
"\nBORK BORK BORK! Error in date of " + fileName +
218 " for " + dataType +
" borkDate " +
str(returnList[2]))
220 "First line reads " + dataLine +
"\n")
222 "Should read " + moduleName+
"_"+dataType+
"\n")
224 with open(dataFolder+dataType+
"BORKBORKBORK.txt",
'w')
as borkRepork:
225 borkRepork.write(
"filename " + fileName +
"date range " +
str(
226 firstDate) +
"-" +
str(lastDate) +
" first line " + dataLine +
'\n')
230 if dateTime > returnList[1][moduleNumber]:
231 returnList[3][moduleNumber] += 1
232 outputLine = moduleName +
"_" + dataType +
" " + \
233 str(dateTime) +
" " +
str(time.mktime(
234 dateTime.timetuple())) +
" " +
str(data) +
"\n"
236 returnList[1][moduleNumber] = dateTime
238 output.write(outputLine)
245 returnList[2] = lastDate
246 print(
"Something broke :( \n")
247 print(
"Could be an error in data values of " + fileName +
248 " for " + dataType +
" borkDate " +
str(returnList[2]))
249 print(
"First line reads " + name +
"\n")
251 with open(dataFolder+dataType+
"BORKBORKBORK.txt",
'w')
as borkRepork:
252 borkRepork.write(
"filename " + fileName +
"date range " +
str(
253 firstDate) +
"-" +
str(lastDate) +
" first line " + dataLine +
'\n')
255 "Try running again... often this is an issue with the connection to eos")
259 print(
"could not open file " +
str(fileName) +
" fool")
269 fillerDate = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
270 returnList = [fillerDate, fillerDate, fillerDate,
False,
"LI_S00_0_M0"]
272 homeDirectory = os.path.expanduser(
273 '/eos/atlas/user/j/jdickins/Pixel/LeakageCurrent/')
276 dataFolder = homeDirectory +
"/IBLData/processedData/"
277 inputFolder = homeDirectory +
"/IBLData/rawData/"+dataType+
"/"
278 entriesFolder = homeDirectory +
"/IBLData/rawData/entriesPerDay/" + dataType +
"/"
281 if not os.path.exists(dataFolder+dataType):
282 os.mkdir(dataFolder+dataType)
284 if not os.path.exists(entriesFolder):
285 os.mkdir(entriesFolder)
293 smallestEndDate = fillerDate
296 if not os.path.exists(dataFolder+dataType+
".txt"):
299 print(
"No any file found! at " + dataFolder +
300 dataType +
" Making default values")
303 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
304 firstTempDate = datetime.datetime(2015, 5, 1, 0, 0, 0, 0)
305 lastTempDate = datetime.datetime(2015, 5, 1, 0, 0, 0, 1)
306 smallestEndDate = lastTempDate
308 for stave
in range(1, 15):
309 staveString =
str(stave)
311 staveString =
"0"+
str(stave)
312 for side
in [
'A',
'C']:
313 for DCSGroup
in range(1, 5):
314 moduleName =
'LI_S' + \
315 str(staveString) +
'_' + \
316 side +
'_M' +
str(DCSGroup)
318 moduleName +
" " +
str(firstTempDate) +
" " +
str(lastTempDate) +
" 0 0\n")
319 startingDates.append(firstTempDate)
320 endDates.append(lastTempDate)
321 filesProcessed.append(0)
323 dailyPoints.append(0)
326 print(
"Found " + dataFolder+dataType+
".txt")
327 with open(dataFolder+dataType+
".txt",
'r')
as datesFile:
331 for dateLine
in datesFile:
333 tempDatesLine = dateLine.split()
334 filesProcessed.append(
int(tempDatesLine[5]))
335 dataPoints.append(
int(tempDatesLine[6]))
336 dailyPoints.append(0)
338 firstTemp = tempDatesLine[1].
split(
'-')
339 lastTemp = tempDatesLine[3].
split(
'-')
341 firstTempTime = tempDatesLine[2].
split(
':')
342 lastTempTime = tempDatesLine[4].
split(
':')
344 firstTempTimes = firstTempTime[2].
split(
'.')
345 lastTempTimes = lastTempTime[2].
split(
'.')
347 if len(firstTempTimes) < 2:
348 firstTempTimes.append(0)
349 if len(lastTempTimes) < 2:
350 lastTempTimes.append(0)
352 firstTempDate = datetime.datetime(
353 int(firstTemp[0]),
int(firstTemp[1]),
int(firstTemp[2]),
354 int(firstTempTime[0]),
int(firstTempTime[1]),
355 int(firstTempTimes[0]),
int(firstTempTimes[1]))
356 lastTempDate = datetime.datetime(
357 int(lastTemp[0]),
int(lastTemp[1]),
int(lastTemp[2]),
358 int(lastTempTime[0]),
int(lastTempTime[1]),
359 int(lastTempTimes[0]),
int(lastTempTimes[1]))
361 startingDates.append(firstTempDate)
362 endDates.append(lastTempDate)
365 returnList[0] = firstTempDate
366 returnList[1] = lastTempDate
367 smallestEndDate = lastTempDate
370 if firstTempDate < returnList[0]:
371 returnList[0] = firstTempDate
372 if lastTempDate > returnList[1]:
373 returnList[1] = lastTempDate
374 if lastTempDate < smallestEndDate:
375 smallestEndDate = lastTempDate
379 print(
"Investigating " + dataType +
" from " +
str(smallestEndDate))
386 firstTempDate = startingDates[0]
387 lastTempDate = endDates[0]
391 for fileName
in fileList:
396 endDate1 = fileName[end-4:end]
397 endDate2 = fileName[end-7:end-6]
400 if endDate1 ==
'.txt' and endDate2 ==
'_':
402 startDate = fileName[end-23:end-15]
403 endDate = fileName[end-12:end-4]
404 endDateSplit = endDate.split(
'_')
405 endDateFile = datetime.datetime(
406 2000+
int(endDateSplit[0]),
int(endDateSplit[1]),
int(endDateSplit[2]), 0, 0, 0, 1)
408 startDateSplit = startDate.split(
'_')
409 startDateFile = datetime.datetime(
410 2000+
int(startDateSplit[0]),
int(startDateSplit[1]),
int(startDateSplit[2]), 0, 0, 0, 1)
412 if endDateFile > smallestEndDate:
415 lastTempDate = endDateFile
416 [firstTempDate, endDates, fillerDate, tempDataNumbers, smallestEndDate] =
appendEntries(
417 fileName, dataType, dataFolder, dailyPoints, endDates, startDateFile, endDateFile, fillerDate)
421 for i
in range(0, 112):
423 filesProcessed[i] += 1
425 dataPoints[i] += tempDataNumbers[i]
430 for stave
in range(1, 15):
431 staveString =
str(stave)
433 staveString =
"0"+
str(stave)
434 for side
in [
'A',
'C']:
435 for DCSGroup
in range(1, 5):
436 moduleName =
'LI_S' + \
437 str(staveString) +
'_' + \
438 side +
'_M' +
str(DCSGroup)
439 outName = entriesFolder + moduleName +
".txt"
440 dataLine =
str(startDate) +
" " + \
441 str(tempDataNumbers[holderX]) +
"\n"
442 tempDataNumbers[holderX] = 0
444 mode =
'a' if os.path.isfile(outName)
else 'w'
445 with open(outName, mode)
as output:
446 output.write(dataLine)
450 if returnList[2] != fillerDate:
451 returnList[2] = fillerDate
452 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
454 for stave
in range(1, 15):
455 staveString =
str(stave)
457 staveString =
"0"+
str(stave)
458 for side
in [
'A',
'C']:
459 for DCSGroup
in range(1, 5):
460 moduleName =
'LI_S' + \
461 str(staveString) +
'_' + \
462 side +
'_M' +
str(DCSGroup)
463 datesFile.write(moduleName +
" " +
str(startingDates[tempHolder]) +
" " +
str(
464 endDates[tempHolder]) +
" " +
str(filesProcessed[tempHolder]) +
" " +
str(dataPoints[tempHolder]) +
"\n")
479 with open(dataFolder+dataType+
".txt",
'w')
as datesFile:
481 for staveX
in range(1, 15):
482 staveStringX =
str(staveX)
484 staveStringX =
"0"+
str(staveX)
485 for sideX
in [
'A',
'C']:
486 for DCSGroupX
in range(1, 5):
487 moduleNameX =
'LI_S' + \
488 str(staveStringX) +
'_' + sideX +
'_M' +
str(DCSGroupX)
489 datesFile.write(moduleNameX +
" " +
str(startingDates[tempHolder]) +
" " +
str(
490 endDates[tempHolder]) +
" " +
str(filesProcessed[tempHolder]) +
" " +
str(dataPoints[tempHolder]) +
"\n")
500 threading.Thread.__init__(self)
505 print(
"Starting getIBLDate.py for " + self.
name)
507 print(
"Exiting getIBLDate.py for " + self.
name +
" with no issues, data range from " +
508 str(returnList[0]) +
" to " +
str(returnList[1]))
530 if __name__ ==
"__main__":