Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 from .message import Message
00034
00035
00036 class MessageList(object):
00037 """
00038 Partially simulates a two dimensional list with a single dimensional list of
00039 message objects. Also provides utility functions to provide data in useful formats
00040 """
00041 def __init__(self):
00042 self._messagelist = []
00043
00044 def column_count(self):
00045 return len(Message.get_message_members())
00046
00047 def get_message_list(self):
00048 return self._messagelist
00049
00050 def message_members(self):
00051 return Message.get_message_members()
00052
00053 def append_from_text(self, text):
00054 newmessage = Message()
00055 newmessage.file_load(text)
00056 self._messagelist.append(newmessage)
00057
00058 def get_data(self, row, col):
00059 if row >= 0 and row < len(self.get_message_list()) and col >= 0 and col < len(Message.get_message_members()):
00060 return self.get_message_list()[row].get_data(col)
00061 else:
00062 raise IndexError
00063
00064 def get_unique_col_data(self, index):
00065 """
00066 :param index: col index, ''int''
00067 :returns: a unique list of data index, ''list[str]''
00068 """
00069 uniques_list = set()
00070 for message in self._messagelist:
00071 uniques_list.add(getattr(message, self.message_members()[index]))
00072 return list(uniques_list)
00073
00074 def add_message(self, msg):
00075 self._messagelist.append(Message(msg))
00076
00077 def header_print(self):
00078 return Message.header_print()
00079
00080 def get_messages_in_time_range(self, start_time, end_time=None):
00081 """
00082 :param start_time: time to start in timestamp form (including decimal
00083 fractions of a second is acceptable, ''unixtimestamp''
00084 :param end_time: time to end in timestamp form (including decimal
00085 fractions of a second is acceptable, ''unixtimestamp'' (Optional)
00086 :returns: list of messages in the time range ''list[message]''
00087 """
00088 message_list = self.get_message_list()
00089 time_range_list = []
00090 for message in message_list:
00091 msg_time = message.time_in_seconds()
00092 if float(msg_time) >= float(start_time) and (end_time is None or float(msg_time) <= float(end_time)):
00093 time_range_list.append(message)
00094 return time_range_list