Exemplo n.º 1
0
 def start(self):
     CompositeNode.start(self)
     next_position = 0
     timestamp = PeriodicColumn()
     timestamp.configure({'parent':self.get_child('recorders'),
                          'name':'timestamp',
                          'position':next_position,
                          'sort_order':'ascending',
                          'args':(),
                          'function':self.scheduled_time})
     timestamp.sequence = 0
     sequences = []
     for child in self.get_child('recorders').children_nodes():
         if child.__class__ == Recorder:
             if child.sequence in sequences:
                 raise EConfiguration(
                     'Conflicting RecorderSet sequence %s on %r' %
                     (child.sequence, child.name))
         sequences.append(child.sequence)
     # Force Timestamp as column '0'.
     self.collector.add_column(timestamp)
     children = self.get_child('recorders').children_nodes()
     children.sort(_sort)
     for child in children:
         if child.__class__ == Recorder:
             for channel in child.channels():
                 next_position += 1
                 channel.position = next_position
                 self.collector.add_column(channel)
     cc = ColumnConfiguration()
     cc.configure(timestamp.configuration())
     self.log.configure([cc]+self.collector.columns[1:],
                        self.minimum_size,self.maximum_size)
     self.collector.start()
Exemplo n.º 2
0
 def configuration(self):
     config = PeriodicColumn.configuration(self)
     get_attribute(self,'node',config,as_node_url)
     get_attribute(self,'meter_description',config)
     get_attribute(self,'account',config)
     get_attribute(self,'meter_number',config)
     get_attribute(self,'units',config)
     return config
Exemplo n.º 3
0
 def test_configure_1(self):
     p = PeriodicLog()
     p.configure({'name':'log','parent':None, 'period':1})
     h = CompositeNode()
     h.configure({'name':'columnholder','parent':p})
     c = PeriodicColumn()
     c.configure({'position':0, 'name':'0', 'parent':h,
                  'function':self._random, 'args':()})
     c.start()
     try:
         c.function()
     finally:
         c.stop()
     return
Exemplo n.º 4
0
 def configure(self,config):
     set_attribute(self,'node',REQUIRED,config)
     config['function'] = 'mpx.lib.node.as_node("%s").get' % self.node
     PeriodicColumn.configure(self,config)
     set_attribute(self,'delta',0,config,as_boolean)
     if self.delta:
         c = Calculator()
         c.configure({'name':'delta',
                      'parent':self,
                      'statement':'value-last_value',
                      'variables':[{'vn':'value',
                                    'node_reference':'$value'},
                                   {'vn':'last_value',
                                    'node_reference':'$last_value'}]})
     set_attribute(self,'meter_description',self.name,config)
     set_attribute(self,'account',REQUIRED,config)
     set_attribute(self,'meter_number',REQUIRED,config)
     set_attribute(self,'units','',config)
Exemplo n.º 5
0
 def test_configure_2(self):
     p = PeriodicLog()
     p.configure({'name':'log','parent':None, 'period':1})
     h = CompositeNode()
     h.configure({'name':'columnholder','parent':p})
     c = PeriodicColumn()
     c.configure({'position':1, 'name':'1', 'parent':h,
                  'context':'import random', 'function':'random.uniform',
                  'args':'(0,100)'})
     c.start()
     try:
         c.function()
     finally:
         c.stop()
     return
Exemplo n.º 6
0
 def test_configure_3(self):
     p = PeriodicLog()
     p.configure({'name':'log','parent':None, 'period':1})
     h = CompositeNode()
     h.configure({'name':'columnholder','parent':p})
     c = PeriodicColumn()
     c.configure({'position':2, 'name':'2', 'parent':h,
                  'context':'',
                  'function':'mpx.lib.node.as_node("/").configuration',
                  'args':'()','conversion':'none'})
     c.start()
     try:
         c.function()
     finally:
         c.stop()
     return
Exemplo n.º 7
0
 def start(self):
     timestamp = PeriodicColumn()
     timestamp.configure({'parent':self.get_child('groups'),
                          'name':'timestamp',
                          'position':0,
                          'sort_order':'ascending',
                          'args':(),
                          'function':'self.scheduled_time'})
     self.collector.add_column(timestamp)
     self._groups = []
     for child in self.get_child('groups').children_nodes():
         if child.name != 'timestamp':
             self._groups.append(child)
     configs = [ColumnConfiguration()]
     configs[0].configure(timestamp.configuration())
     self._sort_groups()
     for i in range(0,len(self._groups)):
         group = self._groups[i]
         group.position = i+1
         self.collector.add_column(group)
         mata = {}
         if hasattr(group,'meta'):
             meta = group.meta
         configs.append(ColumnConfiguration(group.name,
                                            group.position,None,
                                            meta))
     self.log.configure(configs, self.minimum_size, self.maximum_size)
     column_data = self.log.data_manager.get_data()
     self._seqs = column_data.keys()
     self._seqs.sort()
     self._seqs.reverse()
     # seqs is list of config seqs starting with latest.
     self._configs = {}
     for seq in self._seqs:
         self._configs[seq] = {}
         for position in column_data[seq]:
             column = column_data[seq][position]
             if column['name'] in ('_seq','timestamp'):
                 continue
             self._configs[seq][column['name']] = column['meta']
     self.collector.start()
     CompositeNode.start(self)
Exemplo n.º 8
0
 def _configure(self):
     p = PeriodicLog()
     p.configure({'name':'log','parent':None, 'period':1})
     h = CompositeNode()
     h.configure({'name':'columnholder','parent':p})
     # Add a compiled function with compile arguments.
     c = PeriodicColumn()
     c.configure({'position':0, 'name':'0', 'parent':h,
                  'function':self._random, 'args':()})
     self.collector.add_column(c)
     # Add a string function, context and arguments.
     c = PeriodicColumn()
     c.configure({'position':1, 'name':'1', 'parent':h,
                  'context':'import random', 'function':'random.uniform',
                  'args':'()'})
     self.collector.add_column(c)
     # Add a node column.
     c = PeriodicColumn()
     c.configure({'position':2, 'name':'2', 'parent':h,
                  'context':'',
                  'function':'mpx.lib.node.as_node("/").configuration',
                  'args':'()'})
     self.collector.add_column(c)
Exemplo n.º 9
0
 def configuration(self):
     cd = PeriodicColumn.configuration(self)
     for attr_name,conv,def_val in self.attr_names:
         get_attribute(self, attr_name, cd, conv)
     return cd
Exemplo n.º 10
0
 def configure(self, cd):
     PeriodicColumn.configure(self, cd)
     for attr_name,conv,def_val in self.attr_names:
         set_attribute(self, attr_name, def_val, cd, conv)
     return
Exemplo n.º 11
0
 def test_add_entry_event(self):
     class Consumer(EventConsumerAbstract):
         def __init__(self, *args, **kw):
             EventConsumerAbstract.__init__(self, *args, **kw)
             self.entries = []
             self.errors = []
             self.lock = Lock()
         def event_thread(self,event):
             # The values returned in the event:
             values = event.values
             # The column as read from the source Log instance:
             column_dict = event.source[event.seq]
             # A map of COLUMN_DICT keys to VALUES indexes.
             column_value_map = {
                 'c0':0,
                 }
             # Validate that the list of values matches the actual column in
             # the log:
             for key,index in column_value_map.items():
                 if not column_dict.has_key(key):
                     self.errors.append('column_dict has no %r key.' % key)
                     return
                 if index >= len(values):
                     self.errors.append('Index(%r) >= len(values:%r).' %
                                        (index, len(values)))
                     return
                 if column_dict[key] != values[index]:
                     self.errors.append(
                         'column_dict[%r]:%r != values[%r]:%r' % (
                         key, column_dict[key], index, values[index]))
                     return
             self.lock.acquire()
             try:
                 # If any entries are left, the test will fail.
                 self.entries.remove(values)
             except:
                 # Also, if errors is not empty the test will fail.
                 self.errors.append("Failed to find %r in entries." %
                                    values)
             self.lock.release()
         def event_handler(self,event):
             t = Thread(target=self.event_thread, args=(event,))
             t.start()
             return
     consumer = Consumer()
     p = PeriodicLog()
     p.configure({'name':'log','parent':None, 'period':0})
     h = CompositeNode()
     h.configure({'name':'columns','parent':p})
     c = PeriodicColumn()
     c.configure({'position':0, 'name':'c0', 'parent':h,
                  'function':'None',})
     p.event_subscribe(consumer, LogAddEntryEvent)
     p.start()
     try:
         for c0 in range(0,10):
             entry = [c0,]
             consumer.entries.append(entry)
             p.add_entry(entry)
         t1 = time.time()
         while consumer.entries:
             if (time.time() - t1) >= 1.0:
                 msgs = [
                     "Failed to recieve matching events after 1 second."
                     ]
                 msgs.extend(consumer.errors)
                 self.fail('\n'.join(msgs))
             pause(0.1)
     finally:
         p.stop()
     return
Exemplo n.º 12
0
 def configuration(self):
     cd = PeriodicColumn.configuration(self)
     get_attribute(self, 'mmafmt_channel_id', cd, str)
     get_attribute(self, 'mmafmt_channel_label', cd, str)
     get_attribute(self, 'mmafmt_channel_pos', cd, str)
     return cd
Exemplo n.º 13
0
 def configure(self, cd):
     PeriodicColumn.configure(self, cd)
     set_attribute(self, 'mmafmt_channel_id', REQUIRED, cd, str)
     set_attribute(self, 'mmafmt_channel_label', REQUIRED, cd, str)
     set_attribute(self, 'mmafmt_channel_pos', '', cd, stripped_str)
     return
Exemplo n.º 14
0
 def __init__(self, *args, **kw):
     from mpx.lib import deprecated
     PeriodicColumn.__init__(self, *args, **kw)
     deprecated("Update configuration to use the MeterMailColumnDecorator.")
     return
Exemplo n.º 15
0
 def __init__(self, *args, **kw):
     from mpx.lib import deprecated
     PeriodicColumn.__init__(self, *args, **kw)
     deprecated("Update configuration to use the MeterMailColumnDecorator.")
     return
Exemplo n.º 16
0
 def _configure(self):
     p = PeriodicLog()
     p.configure({'name': 'log', 'parent': None, 'period': 1})
     h = CompositeNode()
     h.configure({'name': 'columnholder', 'parent': p})
     # Add a compiled function with compile arguments.
     c = PeriodicColumn()
     c.configure({
         'position': 0,
         'name': '0',
         'parent': h,
         'function': self._random,
         'args': ()
     })
     self.collector.add_column(c)
     # Add a string function, context and arguments.
     c = PeriodicColumn()
     c.configure({
         'position': 1,
         'name': '1',
         'parent': h,
         'context': 'import random',
         'function': 'random.uniform',
         'args': '()'
     })
     self.collector.add_column(c)
     # Add a node column.
     c = PeriodicColumn()
     c.configure({
         'position': 2,
         'name': '2',
         'parent': h,
         'context': '',
         'function': 'mpx.lib.node.as_node("/").configuration',
         'args': '()'
     })
     self.collector.add_column(c)
Exemplo n.º 17
0
 def configure(self, cd):
     PeriodicColumn.configure(self, cd)
     set_attribute(self, 'mmafmt_channel_id', REQUIRED, cd, str)
     set_attribute(self, 'mmafmt_channel_label', REQUIRED, cd, str)
     set_attribute(self, 'mmafmt_channel_pos', '', cd, stripped_str)
     return
Exemplo n.º 18
0
 def configuration(self):
     cd = PeriodicColumn.configuration(self)
     get_attribute(self, 'mmafmt_channel_id', cd, str)
     get_attribute(self, 'mmafmt_channel_label', cd, str)
     get_attribute(self, 'mmafmt_channel_pos', cd, str)
     return cd