-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_comm_time.py
executable file
·121 lines (104 loc) · 4.31 KB
/
read_comm_time.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/proj/sot/ska3/flight/bin/python
#####################################################################################
# #
# read_comm_time.py: read comm time from aspect site #
# #
# author: t. isobe ([email protected]) #
# #
# last update: Dec 09, 2024 #
# #
#####################################################################################
import os
from cxotime import CxoTime
import argparse
#
#--- Define Directory Pathing
#
HOUSE_KEEPING = "/data/mta4/Script/SOH/house_keeping"
HTML_DIR = "/data/mta4/www/CSH"
ARC_DIR = "/data/mta4/www/ASPECT/arc"
DISREGARD_PAST_COMMS = True
#-------------------------------------------------------------------------------
#-- find_comm_pass: read comm pass from aspect site --
#-------------------------------------------------------------------------------
def find_comm_pass():
"""
read comm pass form aspect site
input: none but read from http://cxc.harvard.edu/mta/ASPECT/arc/'
output: <house_keeping>/comm_list --- <start time>\t<start time in sec>\t<stop time in sec>
<html_dir>/comm_list.html
"""
#
#--- start writing comm_list.html top part
#
hline = '<!DOCTYPE html>\n <html>\n <head>\n'
hline += '<title>Comm Timing List</title>\n'
hline += '<link href="css/custom.css" rel="stylesheet">\n'
hline += '</head>\n<body>\n'
hline += '<div style="margin-left:60px;">\n'
hline += '<h2>Comm Timing List</h2>\n'
hline += '<table>\n'
hline += '<tr><th style="text-align:center;">Start</th><td> </td>'
hline += '<th style="text-align:center;">Stop</th></tr>\n'
now = CxoTime().secs
with open(f"{ARC_DIR}/index.html") as f:
data = [line.strip() for line in f.readlines()]
sline = ''
for ent in data:
if 'Comm pass' in ent:
atemp = ent.split('<tt>')
btemp = atemp[1].split('</tt>')
ctime = btemp[0]
atemp = ent.split('duration')
btemp = atemp[1].split(')')
dur = btemp[0].strip()
atemp = dur.split(':')
dur = int((float(atemp[0]) + float(atemp[1]) / 60.0) * 3600.0)
start = int(CxoTime(ctime).secs)
stop = start + dur
if DISREGARD_PAST_COMMS:
if stop < now:
continue
#
#--- data table input
#
sline += f"{ctime}\t{start}\t{stop}\n"
#
#--- html page input
#
hline += f"<tr><td>{ctime}</td><td> </td><td>{CxoTime(stop).date}</td></tr>\n"
#
#--- write out the comm list data
#
with open(f"{HOUSE_KEEPING}/comm_list", 'w') as fo:
fo.write(sline)
#
#--- finish html page
#
hline += '</table>\n'
hline += '<p style="padding-top:5px;"> Time is in <b><em>UT</em></b> </p>\n'
hline += '</div>\n'
hline += '</body>\n</html>\n'
with open(f"{HTML_DIR}/comm_list.html", 'w') as fo:
fo.write(hline)
#-------------------------------------------------------------------------------
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--mode", choices = ['flight','test'], required = True, help = "Determine running mode.")
parser.add_argument("--arc_dir", required = False, help = f"Determine arc data location. (default={ARC_DIR})")
parser.add_argument("--html_dir", required = False, help = f"Determine web output location. (default={HTML_DIR})")
args = parser.parse_args()
if args.mode == "test":
DISREGARD_PAST_COMMS = False
if args.arc_dir:
ARC_DIR = args.arc_dir
if args.html_dir:
HTML_DIR = args.html_dir
else:
HTML_DIR = f"{os.getcwd()}/test/_outTest"
HOUSE_KEEPING = f"{os.getcwd()}/test/_outTest"
os.makedirs(HOUSE_KEEPING, exist_ok = True)
os.makedirs(HTML_DIR, exist_ok = True)
find_comm_pass()
elif args.mode == "flight":
find_comm_pass()