Collector
Home Up History Media Collector Condition Item

 

Module history_collector

Module history_collector consists of a single class, HistoryCollector. An instance of HistoryCollector contains an ordered list of instances of class Tag.

Class History_Collector

A tag is a group of items that should be sampled at the same times and those samples written out to a history medium, such as a text file. Each tag has a name, a medium, and a list of items to be sampled. Tags have names so that they may be registered with their collector by name. Then, even if you do not have a reference to the tag, you can get one from the collector. Also, you can use the tag names to change the order in which different tags are processed, or to delete the tag from the collector.

Creation

HistoryCollector ()

An instance of HistoryCollector is returned, with an empty taglist.

Attributes

taglist is the list of tags owned by this collector.

Query Methods

tag (name) returns the tag named name, or raises NameError if there isn't one.

position (name) the position in taglist of the tag named name, or raises NameError if the name is not the name of a tag in taglist..

tagnames () returns a list of the names of the tags in taglist.

Manipulating the tag list

The list taglist can be manipulated with these commands.

add (tag, position = -1) adds the given tag to the list at the given position. By default, the position is the end of the list.

delete (name) removes the tag named name from the taglist.If there is no such tag, NameError is raised.

at_cycles (*cycles) similarly takes one or more specific cycles at which to sample.

Methods to Sample

These routines are used to collect samples of the tags currently in taglist. For each tag in the list:

sample (cycle, time) checks the state attribute of the logical condition. If it is true, and the state attribute of the regular condition is satisfied, the sample is collected. The user's sequence of calls to sample should have successive integer values of cycle and monotonically increasing values of time. The initial value of cycle may be anything you like as long as it is larger than history.NeverCollected.

If your program has a repetitive cycle but no concept of time, you can simply use the floating-point version of the cycle number as a time.

sample_final (cycle, time) may be called at the final time of the program. It will example the state_final attributes of its conditions rather than the normal state attribute. (See module history_condition). These state_final attributes have been chosen for the time and cycle conditions so that they are true unless the last possible time has already passed.

sample_unconditionally (cycle, time) does exactly what it says. The logical and regular conditions are ignored. It is not intended for normal use by the user.

The method sample_final may be called without worry about duplication of records that may have already been made by a previous call to sample on that same cycle.