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")