-
Notifications
You must be signed in to change notification settings - Fork 23
/
StartTime_2010_2.py
executable file
·58 lines (44 loc) · 2.38 KB
/
StartTime_2010_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
import time
import os
print "Extracting start and end time from the file"
def makeJsonFile(inputFileName, outputFileName):
outputFileRun = open(outputFileName, "w")
outputFileRun.write("{\n")
outputFileRun.write(" label: 'run',\n")
outputFileRun.write(" data: [")
first = True
file = open(inputFileName)
start = False
for line in file:
if line.find("run") != -1:
start = True
elif start and len(line) != 1:
splittedLine = line.split()
runNumber = splittedLine[0]
# results = os.system("./das_client.py --query=\"run = "+str(runNumber)+" | grep run.run_number,run.create_time, run.end_time,run.duration\" --format=plain")
# print results
runTimes = os.popen("./das_client.py --query=\"run = "+str(runNumber)+" | grep run.run_number,run.create_time, run.end_time,run.duration\" --format=plain").readlines()
print "runTimes =", runTimes
if len(runTimes) == 0:
continue
print "start =", runTimes[0].split(" ")[1].split(".")[0]
print "end =", runTimes[0].split(" ")[2].split(".")[0]
startTime = time.mktime(time.strptime(runTimes[0].split(" ")[1].split('.')[0], "%Y-%m-%dT%H:%M:%S"))
endTime = time.mktime(time.strptime(runTimes[0].split(" ")[2].split('.')[0], "%Y-%m-%dT%H:%M:%S"))
# startTime = splittedLine[1]
# endTime = splittedLine[2]
print "run number =", runNumber, "start time =", startTime, "end time =", endTime
if first:
first = False
else:
outputFileRun.write(", ")
# print "starttime =", startTime, "(int(startTime)<<16) =", (int(startTime)<<16)
# print "time =", time.ctime(float(startTime)) #, "and =", time.ctime(float(startTime)<<16)
outputFileRun.write("["+str(int(startTime)*1000-2000)+", 0, "+str(runNumber)+"], ")
outputFileRun.write("["+str(int(startTime)*1000)+", 20000, "+str(runNumber)+"], ")
outputFileRun.write("["+str(int(endTime)*1000)+", 20000, "+str(runNumber)+"], ")
outputFileRun.write("["+str(int(endTime)*1000+2000)+", 0, "+str(runNumber)+"]")
outputFileRun.write("]\n}")
makeJsonFile("times_2010_2.txt", "full_run_2010_2.js")
# makeJsonFile("times_month.txt", "oneMonth_run.js")