4 Replies Latest reply on Sep 14, 2017 6:17 PM by oysteintorget

    Displaying values in the Trend view for custom data reference

    oysteintorget

      I am creating a custom data reference to get data from a different timeseries database into AF.

       

      I have implemented a class that inherits from AFDataReference and have overrides for GetValue and GetValues and created an attribute that use the custom data reference.

       

      Everything works as expected when looking at the current value, but when opening the Trend tool I only get one call to GetValue with the time context set to 01.01.1970.

       

      What do I have to do to get it to work with the Trend tool as well. I expected that GetValues would get called.

       

      I have also added this

       

              public override AFDataReferenceMethod SupportedMethods
              {
                  get { return (AFDataReferenceMethod.GetValue | AFDataReferenceMethod.GetValues); }
              }
      
        • Re: Displaying values in the Trend view for custom data reference
          sraposo

          Hi Oystein,

           

          Can you post your code completely? Also, this post might be of interest to you:

           

          Trend Custom DataReference

           

          Thanks,

          Seb

          1 of 1 people found this helpful
            • Re: Displaying values in the Trend view for custom data reference
              oysteintorget

              Hi Seabstien,

               

              the code is below. I have changed some references to make it a bit clearer, but this is the gist of it.

               

              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.Globalization;
              using System.Runtime.InteropServices;
              using OSIsoft.AF.Asset;
              using OSIsoft.AF.Data;
              using OSIsoft.AF.Time;
              using OSIsoft.AF.UnitsOfMeasure;
              using MyCompany.Time;
              using MyCompany.TimeSeries;
              using Calendar = MyCompany.Time.Calendar;
              using TimeSeriesRepository = MyCompany.Repository;
              
              
              
              
              namespace MyDataReference
              {
                  [Serializable]
                  [Guid("4e08dc76-3104-48d0-87b8-84791c4b3111")]
                  [Description("Custom Data reference")]
                  public class MyDataReference : AFDataReference
                  {
                      private IRepository repo;
              
              
                      public MyDataReference()
                      {
                          repo = new TimeSeriesRepository("connection string");
                      }
              
              
                      public override AFDataReferenceMethod SupportedMethods
                      {
                          get { return (AFDataReferenceMethod.GetValue | AFDataReferenceMethod.GetValues); }
                      }
              
              
                      public override AFDataReferenceContext SupportedContexts => AFDataReferenceContext.All;
              
              
                      public override AFDataMethods SupportedDataMethods
                      {
                          get { return base.DefaultSupportedDataMethods; }
                      }
              
              
                      public override AFValues GetValues(object context, AFTimeRange timeRange, int numberOfValues,
                          AFAttributeList inputAttributes, AFValues[] inputValues)
                      {
                          var tsname = "PRICE.SPOT.EL.FRA._.EPEX.EUR.MWH.H";
              
              
                          var cal = Calendar.Utc;
                          var start = cal.ToUtcTime(timeRange.StartTime.UtcTime);
                          var end = cal.ToUtcTime(timeRange.EndTime.UtcTime);
              
              
                          var period = new Period(start, end);
              
              
                          var tsList = repo.ReadRawPoints(new List<TsIdentity> {new TsIdentity(0, tsname)}, period);
                          var ts = tsList[0];
              
              
                          var afValues = new AFValues(ts.Count);
                          for (int i = 0; i < ts.Count; i++)
                          {
                              afValues.Add(new AFValue(ts.Value(i).V, new AFTime(cal.ToDateTime(ts.Time(i)))));
                          }
              
              
                          return afValues;
                      }
              
              
                      public override AFValue GetValue(object context, object timeContext, AFAttributeList inputAttributes,
                          AFValues inputValues)
                      {
                          var tsname = "PRICE.SPOT.EL.FRA._.EPEX.EUR.MWH.H";
              
              
                          var now = UtcTime.Now;
                          var period = new Period(now - TimeSpan.FromHours(1), now);
              
              
                          var tsList = repo.ReadRawPoints(new List<TsIdentity> {new TsIdentity(0, tsname)}, period);
              
              
                          var ts = tsList[0];
                          var value = ts.Value(0);
              
              
                          return new AFValue(value.V, AFTime.Now);
                      }
              
              
                      public virtual AFValues InterpolatedValuesAtTimes(
                          IList<AFTime> times,
                          string filterExpression,
                          bool includeFilteredValues,
                          AFAttributeList inputAttributes,
                          AFValues[] inputValues
                      )
                      {
                          return base.InterpolatedValuesAtTimes(times, filterExpression, includeFilteredValues, inputAttributes,
                              inputValues);
                      }
                  }
              }