1+ from datetime import datetime
2+ import time
3+
4+ def to_unix_timestamp (date_string ):
5+ # try:
6+ date_format = "%d/%m/%Y %H:%M:%S"
7+ datetime_obj = datetime .strptime (date_string , date_format )
8+ unix_timestamp = int (time .mktime (datetime_obj .timetuple ()))
9+ return unix_timestamp
10+ # except ValueError:
11+ # throw ValueError("Invalid date format. Please provide date string in the format 'DD/MM/YYYY HH:MI:SS'.")
12+
13+ def to_date_string (unix_timestamp ):
14+ # try:
15+ datetime_obj = datetime .fromtimestamp (unix_timestamp )
16+ date_string = datetime_obj .strftime ("%d/%m/%Y %H:%M:%S" )
17+ return date_string
18+ # except ValueError:
19+ # print("Invalid timestamp. Please provide a valid Unix timestamp.")
20+
21+
22+ with open ('8614_pps.txt' ) as f_pps :
23+ with open ('8614_content_csv_ext.out' ) as f_lhc :
24+ print ("fill" , "run" , "LS" , "beta*" , "xangle" , "dip date" , "record" , "LS" , "beta" , "xangle" , "delivLumi" , "IOV" , "IOV date" , "beta* error" , "xangle error" , "" , sep = ";" )
25+
26+ lhc_beta = None
27+ lhc_xangle = None
28+
29+ line_lhc = f_lhc .readline ()
30+ #skip the headers
31+ if "IOV" in line_lhc or line_lhc == "\n " :
32+ # print("skipping the header") #TODO remove
33+ line_lhc = f_lhc .readline ()
34+
35+ split_lhc = line_lhc .split (';' )
36+
37+ for line_pps in f_pps :
38+ line_pps = line_pps [1 :- 2 ]
39+ split_pps = line_pps .split (', ' )
40+
41+ for i , val in enumerate (split_pps ):
42+ print (val , end = ";" if i <= 5 or i == len (split_pps )- 1 else ", " )
43+
44+
45+
46+ # print(" pps:", (split_pps[2]), "lhc:", (split_lhc[2]))
47+ if (len (split_pps ) > 5 and len (split_lhc ) > 5 ):
48+ # if len(split_pps[5][1:-1]) != len('17/04/2023 07:30:42'):
49+ # print(split_pps[5][1:-1], len(split_pps[5][1:-1]), len('17/04/2023 07:30:42'))
50+ # print(split_pps[5][1:-1])
51+ # print('17/04/2023 07:30:42')
52+ # exit(0)
53+ pps_timestamp = to_unix_timestamp (split_pps [5 ][1 :- 1 ]) + 2 * 60 * 60 # - coversion of time zones
54+ # print(pps_timestamp, "-", int(split_lhc[2]), "=", pps_timestamp -int(split_lhc[2]), end = " |; ")
55+ if (abs (pps_timestamp - int (split_lhc [2 ])) < 10 * 60 and split_pps [2 ] == split_lhc [3 ]):
56+ # print(line_lhc, end="")
57+ print (split_lhc [1 ], split_lhc [3 ], split_lhc [5 ], split_lhc [4 ], split_lhc [6 ],
58+ split_lhc [0 ], to_date_string (int (split_lhc [2 ])), sep = ";" , end = ";" )
59+ lhc_beta = float (split_lhc [5 ])
60+ lhc_xangle = float (split_lhc [4 ])
61+
62+ line_lhc = f_lhc .readline ()
63+ split_lhc = line_lhc .split (';' )
64+ else :
65+ print (";;;;;;;" , end = "" )
66+
67+ # lhc_beta = lhc_beta
68+ # lhc_xangle = lhc_xangle
69+ pps_beta = float (split_pps [3 ])
70+ pps_xangle = float (split_pps [4 ])
71+ # print(pps_beta, lhc_beta, pps_xangle, lhc_xangle, sep=" - ", end = " | ")
72+ print (abs (pps_beta - lhc_beta ) if lhc_beta is not None else 0 ,
73+ abs (pps_xangle - lhc_xangle ) if lhc_xangle is not None else 0 , "" , sep = ";" )
74+
75+
0 commit comments