Package: Predictive Control

Author: HCA Central
Version: 2
Added to Library: 11-Nov-23
HCAVersion needed: 17.0.48
Keywords: Utility
Extra Info Link: Here

Package Description:
What's new?

4-Nov-22

1. The program to determine the recording to remove if a new one is to be stored was updated. Previously it didn't always choose the oldest and least used. Now does.

2. Added the configuration global variable "PlaybackSpeedup". This is the percentage of the inter-action delay to use when doing a playback. See the notes on that global variable.

Program: Clear Recordings

Program Description:
Remove all recordings. A good way to reset the system.

Global Variable Use:

Name Description
RecordingLastActionTime Time of the last action during a recording
RecordingAction The action that started the recording
RecordingEndTime The time the recording will stop
RecordingStartTime The time the recording was started
RecordingDevice The device that started the recording
Recording The current recording being made
RecordingMax Max number of recordings that can be saved for a device.

Program: Finish Recording

Program Description:
Locates a slot for the recording and saves it then exits recording mode.

Global Variable Use:

Name Description
RecordingLastActionTime Time of the last action during a recording
RecordingEndTime The time the recording will stop
RecordingDevice The device that started the recording
RecordingAction The action that started the recording
RecordingStartTime The time the recording was started
RecordingSeconds The number of seconds to record for
Recording The current recording being made

Program: Have Recording

Program Description:
Detecting if a device action at a time has an matching stream. This checks to see if it is in an acceptable time range and has the minimum number of hits

Return value: Returns the recording if one if found or ""

Parameters:

Name Type Description Default
Device Value The device initiating the action  
AtTime Value At this time  
Percent Value With this action  

Global Variable Use:

Name Description
RecordingTimeMatchDeltaMinutes For a recording to match, the time it was recorded must be the same the current time plus or minus this number of minutes
RecordingMax Max number of recordings that can be saved for a device.
PlaybackMinHits The number of times a recording must match before considered for playback

Program: On State Change

Program Description:
This is the driver for this system. It is started for each state change of a device on or off. It tries to make sure that the state change is due to a local control and not a scheduled or program action.

Any devices that you want to participate in this system, add a tag whose name is "predict". No value needed.

Parameters:

Name Type Description Default
Device Object Object whose state changed  
Percent Value New percent of that object  
ReceptionTime Value Time of last reception from this device  

Global Variable Use:

Name Description
RecordingOnly If 1 then no playback attempted
RecordingLastActionTime Time of the last action during a recording
RecordingEndTime The time the recording will stop
RecordingSeconds The number of seconds to record for
RecordingStartTime The time the recording was started
RecordingAction The action that started the recording
RecordingDevice The device that started the recording

Program: Playback

Program Description:
Playback a stream.

Parameters:

Name Type Description Default
Playback Value The recorded stream  

Global Variable Use:

Name Description
PlaybackSpeedup When a recording playback happens, decrese inter-action delays by this percentage. Must be a value between 0 (all delays zero) and 1 (no speedup)

Program: Report Recordings

Program Description:
Creates a file "prediction recordings.txt" with information about all recordings on all devices that are signed up for the prediction facility

Global Variable Use:

Name Description
RecordingTimeMatchDeltaMinutes For a recording to match, the time it was recorded must be the same the current time plus or minus this number of minutes

Program: Slot For Recording

Program Description:
Finds a slot in the recording tags in a device where this recording will go.

It looks through all the recordings for one that is in a compatible time range, has the same action, and the same stream. If so it uses that one.

If it doesn't find one it uses an open slot.

If it must delete a recording to make room for a new one, it searches for the oldest with the lowest hit count. It then clears that one to be used.

Return value: The slot number to use

Parameters:

Name Type Description Default
Device Value Device that contains recordings  
AtTime Value Action time  
Percent Value Action percent  
Recording Value The recording  

Global Variable Use:

Name Description
RecordingTimeMatchDeltaMinutes For a recording to match, the time it was recorded must be the same the current time plus or minus this number of minutes
RecordingMax Max number of recordings that can be saved for a device.

Program: Stream Add

Program Description:
Add an action to a stream being recorded.

Parameters:

Name Type Description Default
RecordToDevice Value Device to add recording into  
TimeDelta Value Time from previous control operation  
Device Value Device controlled  
Percent Value To percent  

Global Variable Use:

Name Description
Recording The current recording being made

Program: Stream Find

Program Description:
Find a device in a stream. This is used by the "Streams Same" program.

Return value: 1 if found, 0 if not found

Parameters:

Name Type Description Default
Name Value Name in the stream to find  
Stream Value The stream / recording  
StartIndex Value Index of first name  

Program: Streams Same

Program Description:
Compares two streams. They must reference the same devices but the order and inter-control delays are not important.

Return value: 1 if the streams are the same, zero otherwise

Parameters:

Name Type Description Default
Stream Value Stream - no date-time, percent, #hits prefix  
Recording Value Recording