message_list.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
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


rqt_console
Author(s): Aaron Blasdel
autogenerated on Fri Jan 3 2014 11:54:30