There is an ongoing outage on the primary CPAN mirror. It is possible to work around the issue by using MetaCPAN as a mirror.

NAME

Schedule::Activity::Attribute - Updating, tracking, and reporting numeric values.

SYNOPSIS

my $attr=Schedule::Activity::Attribute->new(type=>'int',value=>0,tm=>0);
$attr->change(tm=>10,set=>10);
$attr->change(tm=>20,set=>20);
print $attr->value();
print $attr->average();

DESCRIPTION

This module is responsible for individual attributes. It tracks values for the attribute, facilitates updates, and handles reporting.

Attributes are intended to be typed, so cross-type requests may produce failures.

Functions

change

Ideally called as $attr-change(tm=>tm,options)>, this updates the value of the attribute and logs at the given timestamp. Change options must be type-appropriate. The specified time must exceed (or be the same as) the maximum logged time for the attribute to have any effect. That is, historical values don't update the current value, nor do they create an entry in the log.

Called without a timestamp, the maximum time will be assumed, the value changed, and the logged entry overwritten.

Historic entry is proposed by not yet defined, since it must support set and incr options.

value

The value of the attribute associated with the logged event having the maximum time.

average

Computes the type-specific time-weighted "average value" over all entries in the log. Currently this is a heavy action that requires recalculation for each call, making it accurate but slow.

report

Returns a hash of

y    the value
xy   this list of logged (time,value)
avg  the time-weighted average

_xy

An internal helper to build the list of values from the log.

validateConfig

Returns errors if any of the keys in an attribute configuration are unavailable for the type. By default, the type is 'int'.

log

Called with a timestamp as $attr-log(tm)> to create a log entry of the current value. This is public so callers can establish a "checkpoint" where the value is known/unchanged, typically at boundaries of events or scheduling windows.

Does nothing if the indicated time is below the maximum logged time.

dump

Return a hash of values that can be used to restore the state of the attribute.

restore

Called either as a static function or $attr-restore(%copy)>, loads the state of the attribute from the given hash.