Perform History Recalculation using VtrinLib

History reconsolidation refers to the process of recalculating and recollecting historical data across hierarchical levels. Although the terms reconsolidation, recalculation, and recollection are often used interchangeably, reconsolidation typically encompasses both recalculation of source values and recollection of aggregated data. This process is essential in systems where historical values may be corrected or received late from source systems—particularly in energy management systems. The RTDB-Scheduler service manages history reconsolidation by triggering transformator and calculation processes based on its configuration. For example, if one-hour average values from yesterday are updated, the dependent calculations must be re-run, followed by recollection of higher-level aggregates such as daily and monthly averages. The RTDB-Scheduler ensures that all necessary recalculations and recollections are executed in the correct sequence to maintain data consistency across all levels.

User can update the history table using the mentioned example from here Update History table to update a history table of a variable or equipment property.

Here’s a summary of the RecalcHistory method and its role in history reconsolidation:

The RecalcHistory method initiates history reconsolidation in RTDB systems by triggering recalculation and recollection processes for historical data.

  1. Define Time Range Sets a 12-hour window from the current UTC time.

  2. Create RecalcHistory Instance Adds a new instance to the RecalcHistory class.

  3. Set Parameters

    • History: Specifies the history table number.
    • StartTime and EndTime: Define the time window for recalculation.
  4. Commit Changes Triggers the recalculation process by committing the instance.

public void RecalcHistory()
{
  	DateTime currentUtcTime = DateTime.UtcNow; // Get the current UTC time once
		DateTime startdate = currentUtcTime.AddHours(-12);
		DateTime enddate = currentUtcTime.AddHours(0);
    ABB.Vtrin.cDbClass template = Driver.Classes["RecalcHistory"];
    ABB.Vtrin.cDbClassInstance aggtemp = template.Instances.Add();
    aggtemp.SetRawPropertyValue("History", 1); //The number here specifies the History Table Number
    aggtemp.SetRawPropertyValue("StartTime", startdate);
    aggtemp.SetRawPropertyValue("EndTime", enddate);
    aggtemp.CommitChanges();
}