AnsweredAssumed Answered

AnalysisRule.Run seems to return Interpolated Values?

Question asked by stephen.oconnor on Dec 15, 2015
Latest reply on Dec 16, 2015 by stephen.oconnor

Hey all,


I'm trying to develop my own backfilling code for PerformanceEquation based Analyses. I've scoured the forums (mainly here and here and here) and put together some code that looks like it should work, the results are not what I expected.


Here's the function I'm using:


        private static void PerformBackfill(AFAnalysis analysis, AFTime targetStart, AFTime targetStop, AFTimeSpan targetStep)
            var time = targetStart;
            var config = analysis.AnalysisRule.GetConfiguration();
            var state = new AFAnalysisRuleState(config);
            var outputs = config.GetOutputs();
            // delete past history
            foreach (var output in outputs)
                var attrib = output as AFAttribute;
                var values = attrib.PIPoint.RecordedValues(new AFTimeRange(targetStart, targetStop), AFBoundaryType.Inside, "", true);
                if (values.Count == 0)
                Log("Deleteing history for {0} ({1} values)", attrib.PIPoint.Name, values.Count);
                attrib.PIPoint.UpdateValues(values, AFUpdateOption.Remove);

            // backfill
            while (time <= targetStop)
                if (state.EvaluationError == null)
                    var values = new AFValues();
                    foreach (var output in config.ResolvedOutputs.Zip(state.Outputs, Tuple.Create))
                        var val = output.Item2 as AFValue;
                        var attrib = output.Item1.Attribute as AFAttribute;
                        Log("\t{0} = {1} ({2})", output.Item1.DisplayName, val.Value, val.Attribute);
                        if (attrib != null && attrib.PIPoint != null)
                            // TODO: batch this.
                            attrib.PIPoint.UpdateValue(val, AFUpdateOption.Replace);
                    Log("ERROR: {0}", state.EvaluationError.Message);

                time += targetStep;


Basically this deletes any values in the specified history and then recomputes them using the analysis.


The analysis is simple, load the value of an attribute, add 1, and save it back to the same attribute. There is some logic in there to set to 0 if error to handle initialization. The line output is has 'simple.totalizer' as it's output parameter.


val := 'simple.totalizer';
output := if (BadVal(val)) then 0 else val + 1;


I hoped to backfill the analysis using this code at a different time frequency (analysis is configured for 1m intervals, I'm running this at 1h intervals). I'm aware that this won't work in production as the rate will be very different, but this is a proof of concept demo and we'll worry about the details later. ;-)


So I expect a pretty jagged graph due to the different rates - a very low slope (1/60th) followed by a sharp vertical line up to the unoverwritten values. What I find is that the analysis starts at 0 (okay), and draws a straight line to the value at the end of the time range, like a hockey stick.



Here's a sample from the archive, notice that while the timestamps are what I expected, the values increase at a rate which shows an unusual linear slope:


2993.9112108799512/10/2015 6:00:00 PM
3160.505312995312/10/2015 7:00:00 PM
3326.0994151106512/10/2015 8:00:00 PM
3492.6742874839912/10/2015 9:00:00 PM
3658.2491598573412/10/2015 10:00:00 PM


Has anyone every experienced this before? Am I missing something? I may just turn to manually processing the inputs and outputs as the analyses will be fairly uniform but I was really hoping to use the builtin functionality.