예제 #1
0
파일: MetaDB.py 프로젝트: alpine9000/EWGM
 def load_header(self, line):
     pos = line.find(':')
     if pos == -1:
         raise IOError("Invalid xdfmeta header! (no colon in line)")
     # first extract volume name
     vol_name = line[:pos]
     self.vol_name = vol_name.decode("UTF-8")
     line = line[pos + 1:]
     # now get parameters
     comp = line.split(',')
     if len(comp) != 4:
         raise IOError(
             "Invalid xdfmeta header! (wrong number of parameters found)")
     # first dos type
     dos_type_str = comp[0]
     if len(dos_type_str) != 4:
         raise IOError("Invalid xdfmeta dostype string")
     num = ord(dos_type_str[3]) - ord('0')
     if num < 0 or num > 5:
         raise IOError("Invalid xdfmeta dostype number")
     self.dos_type = DosType.DOS0 + num
     # then time stamps
     create_ts = TimeStamp()
     ok1 = create_ts.parse(comp[1])
     disk_ts = TimeStamp()
     ok2 = disk_ts.parse(comp[2])
     mod_ts = TimeStamp()
     ok3 = mod_ts.parse(comp[3])
     if not ok1 or not ok2 or not ok3:
         raise IOError("Invalid xdfmeta header! (invalid timestamp found)")
     self.vol_meta = RootMetaInfo(create_ts, disk_ts, mod_ts)
예제 #2
0
    def __init__(self, row=1, col=20, option=DataplotOption.TIMESTAMP_AUTO, time_type='millis'):
        """Constructor

        @param row: y axis data ~ data for 1 measurand
        @param col: x axis data ~ data reading point (numerical or time ticks in seconds or milliseconds)
        @param option: timestamp enable/disable auto/custom
        @param row: y data ~ data for 1 measurand

        @return:  Description
        @rtype :  Type

        @raise e:  Description
        """
        self.row = row
        self.col = col
        self.data_regs = []
        self.time_ticks = []
        # TODO: use numpy to save data in matrix
        self.data = []
        for i in range(row):
            self.data_regs.append(deque(maxlen=col))
        self.option = option
        if self.option == DataplotOption.TIMESTAMP_AUTO:
            self.timestamp = TimeStamp(time_type=time_type)
            self.time_ticks = deque(maxlen=col)
        if self.option == DataplotOption.TIMESTAMP_CUSTOM:
            self.row = len(self.data_regs)
            self.time_ticks = deque(maxlen=col)
예제 #3
0
 def __init__(self,
              channel_name,
              ip,
              port,
              timeout=10.0,
              latency_threshold=1000):
     '''
     The constructor of the server. It takes ip and port number from user input
     '''
     self.channel_name = channel_name
     self.name = channel_name + "_server"
     self.ip = ip
     self.port = port
     self.timeout = timeout
     self.latency_threshold = latency_threshold  # latency threshold in millyseconds
     self.comm_dict = {
     }  # a look up table linking client name and corresponding communication channel
     self.server_socket = socket.socket(
         socket.AF_INET, socket.SOCK_STREAM)  # initiate basic socket
     self.server_socket.bind(
         (self.ip, self.port)
     )  # bind the server socket to the host ip and the corresponding port
     self.server_socket.listen(5)  # let the socket listening on the network
     self.ts = TimeStamp(self.name)
     self.rrt = 0
     self.clients = []
예제 #4
0
파일: MetaDB.py 프로젝트: alpine9000/EWGM
 def load_entry(self, line):
     line = line.strip()
     # path
     pos = line.find(':')
     if pos == -1:
         raise IOError("Invalid xdfmeta file! (no colon in line)")
     path = line[:pos].decode("UTF-8")
     # prot
     line = line[pos + 1:]
     pos = line.find(',')
     if pos == -1:
         raise IOError("Invalid xdfmeta file! (no first comma)")
     prot_str = line[:pos]
     prot = ProtectFlags()
     prot.parse(prot_str)
     # time
     line = line[pos + 1:]
     pos = line.find(',')
     if pos == -1:
         raise IOError("Invalid xdfmeta file! (no second comma)")
     time_str = line[:pos]
     time = TimeStamp()
     time.parse(time_str)
     # comment
     comment = FSString(line[pos + 1:].decode("UTF-8"))
     # meta info
     mi = MetaInfo(protect_flags=prot, mod_ts=time, comment=comment)
     self.set_meta_info(path, mi)
예제 #5
0
 def __init__(self, c_sock, c_addr, file='out/serverTimeData.txt'):
     threading.Thread.__init__(self)                         # create a new thread
     self._socket = c_sock
     self._addr = c_addr
     self._socket.setblocking(False)                         # non-blocking mode
     print('A Client has connected at address:\t', self._addr)
     self._ts = TimeStamp(datetime.datetime.now())
     self._file = open(file, 'a')
예제 #6
0
def ConvertToSpectrogram(filepath, seconds=None, pieces=None, subdir=True):
	# get details about the file
	command = f"{SOX_PATH} --i \"{filepath}\""
	output = subprocess.check_output(command)
	details = soxiMatch(output)

	# decide how long the snapshots should be
	increment = 5000  # default is 5 seconds
	if seconds:
		increment = seconds * 1000
	if pieces:
		increment = (details["Samples"] // details["SampleRate"] // pieces) * 1000

	directory, name, ext = splitDirNameExt(filepath)
	# destination should look like: D:\Music\SongName\
	dest_dir = directory
	if subdir:
		dest_dir = buildDirPath(directory, name)
	makeDirectory(dest_dir)

	begin = TimeStamp(0)
	step = TimeStamp(increment)
	end = TimeStamp.parse(details["Duration"])
	i = 1
	pad = paddingZeros(ceil(end // step))
	# it does not matter if (step > end)
	while begin < end:
		for channel in range(1, details["Channels"] + 1):
			dest_file = buildDirPath(dest_dir, f"{name}_ch{channel}_part{i:0{pad}}.png")
			# -n (I don't know why, but it needs this flag)
			# remix {channel} (select a specific channel)
			# -S {begin} (process starting with the specified position)
			# -d {step} (duration of the segment)
			# -m (Spectrogram will be monochrome)
			# -r (Raw spectrogram: suppress the display of axes and legends)
			# -o (Name of the spectrogram output PNG file)
			command = f"\"{SOX_PATH}\" \"{filepath}\" -n " \
					  f"remix {channel} " \
					  f"spectrogram -S {begin} -d {step} -m -r -o \"{dest_file}\""
			subprocess.run(command)

		# increment stuff (note: in the main loop)
		begin.add(step)
		i += 1
예제 #7
0
 def __init__(self, name, ip, port, timeout=10.0):
     self.name = name
     self.ip = ip
     self.port = port
     self.timeout = timeout
     self.Client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.connected = False
     self.channel_name = None
     self.ts = TimeStamp(self.name)
     self._rrt = 0
예제 #8
0
 def __init__(self, name, owner, terminate, frameQ, msgQ, resultFrameQ):
     super(FrameProcessor, self).__init__()
     self.name = name
     self.event = mt.Event()
     self.owner = owner
     self.terminate = terminate
     self.msgQ = msgQ
     self.frameQ = frameQ
     self.resultFrameQ = resultFrameQ
     self.ts = TimeStamp("FrameProcessor")
     self.font = cv2.FONT_HERSHEY_SIMPLEX
     self.time_collector = []
     self.start()
예제 #9
0
 def __init__(self, id, host=cmd.host, port=cmd.port):
     threading.Thread.__init__(self)  # create a new thread
     self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self._socket.connect((host, port))
     self._socket.setblocking(False)  # non-blocking mode
     self._host_ip = host
     self._my_ip = socket.gethostbyname(socket.gethostname())
     self._ts = TimeStamp(datetime.datetime.now())
     self._file = open(fname0 + str(id) + fname1,
                       'a')  # append to this file
     self._peer = PeerNetwork(id,
                              self._file.name)  # has a listener for peers
     self._id = id
     self._me_str = 'Client ' + str(self._id) + ' '
    def __init__(self, camera):
        super(VideoCapture, self).__init__(camera)
        self.frameQ = queue.Queue() # queue to store incoming video frame
        self.msgQ = queue.PriorityQueue() # priority queue to store processing result
        self.resultFrameQ = queue.PriorityQueue() # priority queue to store processed frame
        self.terminate = mt.Event() # a threading event (flag) to notify all threads the end of the process

        self.t_pring_msg = mt.Thread(target=self.print_msg).start() # thread to show processing result concurrently
        self.t_visual = mt.Thread(target=self.show).start() # thread to show processed frame concurrently

        self.ts = TimeStamp("VideoCapture TS") # time-stamp object
        self.cap_frame_count = 0
        self.cap_start = None

        # lists to store the excecuting time (in msec) of different funcitons
        self.time_collector_frameCap = []
        self.time_collector_print = []
        self.time_collector_show = []
예제 #11
0
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()
예제 #12
0
 def change_mod_ts_by_string(self, tm_str):
     t = TimeStamp()
     t.parse(tm_str)
     self.change_meta_info(MetaInfo(mod_ts=t))
예제 #13
0
def readFromStartSKR():

    # read the first line
    line = datafile.readline()

    dataEntriesSKR = []

    # variables used to save first timestamp of file in order to calculate the
    # relative time between a given entry and the first entry in the file
    first = True
    firstTimeStamp = None

    # 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)

        # save the timestamp of the first entry
        if first:
            firstTimestamp = entryTimestamp
            first = False

        # 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(":")

        # 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(firstTimestamp)) \
          + "\t" + str(entry.value) + "\n")
        print(str(entry))

    SKRfile.close()
예제 #14
0
# program will read from QKDSequence.log file
datafile = open("QKDSequence.log", "r")

# prompt user to choose first timestamp of interest or read from the beginning
# of the file
userInput = input("Would you like to read from the beginning of the " \
    + "QKDSequece.log file? ('y' or 'n'): ")
if userInput == "y":
    readFromStartSKR()
elif userInput == "n":

    # prompt user to enter the first timestamp of interest
    output = "Enter the following information regrading the first timestamp " \
        + "of interest..."
    print(output)

    inputYear = input("Year (4 digits please!): ")
    inputMonth = input("Month (Ex. February = 02): ")
    inputDay = input("Day: ")
    inputHour = input("Hour (military time): ")
    inputMinute = input("Minute: ")
    inputSecond = input("Second: ")

    enteredTimestamp = TimeStamp(inputYear, inputMonth, inputDay, inputHour, \
        inputMinute, inputSecond)
    readFromTimeStampSKR(enteredTimestamp)

else:
    print("Invalid Response: ")
예제 #15
0
 def change_create_ts_by_string(self, create_ts_str):
     t = TimeStamp()
     t.parse(create_ts_str)
     return self.change_meta_info(RootMetaInfo(create_ts=t))
예제 #16
0
 def change_mod_ts_by_string(self, mod_ts_str):
     t = TimeStamp()
     t.parse(mod_ts_str)
     return self.change_meta_info(RootMetaInfo(mod_ts=t))
예제 #17
0
# program will read from rawlogs file
datafile = open("rawlogs.txt", "r")

# prompt user to enter the first timestamp of interest
output = "Enter the following information regrading the first timestamp of " \
    + "interest..."
print(output)

inputYear = input("Year (4 digits please!): ")
inputMonth = input("Month (Ex. February = 02): ")
inputDay = input("Day: ")
inputHour = input("Hour (military time): ")
inputMinute = input("Minute: ")
inputSecond = input("Second: ")

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()