import sys
import numpy as np

############## Channels ##############
# 1 - H1:SUS-ETMX_L3_CAL_EXCMON ######
# 2 - H1:SUS-ETMX_L2_CAL_EXCMON ######
# 3 - H1:SUS-ETMX_L1_CAL_EXCMON ######
# 4 - H1:CAL-PCALY_SWEPT_SINE_EXCMON #
# 5 - H1:LSC-DARM1_EXCMON ############
######################################

channel_names = ["H1:SUS-ETMX_L3_CAL_EXCMON", "H1:SUS-ETMX_L2_CAL_EXCMON", "H1:SUS-ETMX_L1_CAL_EXCMON", "H1:CAL-PCALY_SWEPT_SINE_EXCMON", "H1:LSC-DARM1_EXCMON"]
report_IDs = ["20230504T055052Z", "20230505T012609Z", "20230505T174611Z", "20230506T182203Z", "20230508T180014Z", "20230509T070754Z", "20230510T062635Z", "20230517T163625Z", "20230616T161654Z", "20230620T234012Z", "20230621T191615Z", "20230621T211522Z",  "20230628T015112Z", "20230716T034950Z", "20230727T162112Z", "20230802T000812Z", "20230817T214248Z", "20230823T213958Z", "20230830T213653Z", "20230906T220850Z", "20230913T183650Z", "20230928T193609Z", "20231004T190945Z", "20231018T190729Z", "20231027T203619Z"]

measurement_gps_times = np.loadtxt("measurement_gps_times.csv", delimiter = ",", usecols = range(1, 11), comments = "#")

desired_report, channel = str(sys.argv[1]), int(sys.argv[2])
channel -= 1
print("###################################################################### \nReport ID = {}, channel name = {}".format(desired_report, channel_names[channel]))

for n, i in enumerate(report_IDs):
    if desired_report == i:
        if measurement_gps_times[n][channel*2] == 0 or measurement_gps_times[n][channel*2+1] == 0:
            print("No measurement was found in this channel within the searched time frame (+/- 2.5 hours). \nTry channels 4 or 5?")
            break
        else:
            s, e = measurement_gps_times[n][channel*2], measurement_gps_times[n][channel*2+1]
            print("Measurement start time = {:.0f} s, end time = {:.0f} s".format(s, e))
            print("###################################################################### \nndscope H1:SUS-ETMX_L3_CAL_EXCMON , H1:CAL-PCALY_SWEPT_SINE_EXCMON . H1:SUS-ETMX_L2_CAL_EXCMON , H1:LSC-DARM1_EXCMON . H1:SUS-ETMX_L1_CAL_EXCMON -t {:.0f} -t {:.0f} --trend min".format(s, e))
            break