def readFromTimeStampSKR(firstTimeStampIn): # read the first line of QKDSequece.log line = datafile.readline() print("Reading SKR data from QKDSequence.log file...") # list to hold QBER data entries dataEntriesSKR = [] # pass each line in file until program reaches first timestamp of interest while line != "": entryComps = line.split("INFO") # process timestamp of each entry timeStampComps = entryComps[0].split() calendarComps = timeStampComps[0].split("-") year = int(calendarComps[0]) month = int(calendarComps[1]) day = int(calendarComps[2]) timeComps = timeStampComps[1].split(":") hour = int(timeComps[0]) minute = int(timeComps[1]) second = int(timeComps[2]) entryTimestamp = TimeStamp(year, month, day, hour, minute, second) if entryTimestamp.__str__() == enteredTimestamp.__str__(): break line = datafile.readline() # read each line until the end of the file while line != "": # split the entry into a timestamp and a message entryComps = line.split("INFO") # process timestamp of each entry timeStampComps = entryComps[0].split() calendarComps = timeStampComps[0].split("-") year = int(calendarComps[0]) month = int(calendarComps[1]) day = int(calendarComps[2]) timeComps = timeStampComps[1].split(":") hour = int(timeComps[0]) minute = int(timeComps[1]) second = int(timeComps[2]) entryTimestamp = TimeStamp(year, month, day, hour, minute, second) # Not all message types follow the same structure. If the entry # components list is only of length 1, it is not SKR data and can be ignored if len(entryComps) > 1: # split the message into message type and message title/value messageComps = entryComps[1].split(":") # make sure that there is more than one component in the message if len(messageComps) > 1: # if the entry contains secret key rate data, record this entry if "Secret Key Rate" in messageComps[1]: # splits privacy amplification data into title of value and value type = "Secret Key Rate" # extract the SKR value from the entry titleAndValue = messageComps[1].split("=") valueAndUnit = titleAndValue[1].split() value = float(valueAndUnit[0]) entrySKR = DataEntry(entryTimestamp, type, value) dataEntriesSKR.append(entrySKR) # read next line of data line = datafile.readline() datafile.close() # Create a file to store SKR Data SKRfile = open("SKR.txt", "w+") for entry in dataEntriesSKR: SKRfile.write(str(entry.timestamp.getRelativeSeconds(enteredTimestamp)) \ + "\t" + str(entry.value) + "\n") print(str(entry)) SKRfile.close()
firstTimestamp = TimeStamp(inputYear, inputMonth, inputDay, inputHour, \ inputMinute, inputSecond) # read the first line of rawlogs line = datafile.readline() print("Reading QBER data from rawlogs file...") # list to hold QBER data entries dataEntries = [] # pass each line in rawlogs until program reaches first timestamp of interest while line != "": dataEntryComps = line.split() dataTimestamp = dataEntryComps[0] if dataTimestamp.__str__() == firstTimestamp.__str__(): break line = datafile.readline() # process each data entry following first timestamp of interest while line != "": dataEntryComps = line.split() dataTimestampString = dataEntryComps[0] # extract timestamp data from each line calendarComps = dataTimestampString.split("-") year = int(calendarComps[0]) month = int(calendarComps[1]) day = int(calendarComps[2]) timeComps = calendarComps[3].split(":") hour = int(timeComps[0])