org.unizone.source

Type Average

org.unizone.0.4070
Instance of Type
Inheriting from SourceAdapterSingleTimeseries

Type dataValue
org.uninode.Type.displayPattern{att:org.unizone.source.Source.displayName}
org.unizone.source.Source.valueAttribute
org.uninode.Resource.resourceType'''adapter'''
org.uninode.Resource.labelAverage
org.uninode.Resource.resourceOfList{org.unizone.source.Source}
org.uninode.Listable.resourcesReference[org.uninode.Listable.resources] of org.unizone.source.Average

Attribute summaryDefined inUninode® IdPropertiesDefault
IntdaysAverageorg.unizone.0.407121
Reference[org.uninode.Listable.resources]resourcesListableorg.uninode.0.2001type
StringtoString
This is the display string.
Nodeorg.uninode.0.102
Typetype
The type of an object determines the behaviour and attributes of the object.
Nodeorg.uninode.0.101
StringuriNodeorg.uninode.0.103
StringlabelResourceorg.uninode.0.2041type
List[Type]resourceOfResourceorg.uninode.0.2042type
SignatureresourceType
This defines the type of resource. It can be 'view', 'adapter' or 'action'
Resourceorg.uninode.0.2043type
StringdisplayName
The display name is the name that is shown in lists, displays and graphs.
Sourceorg.unizone.0.4001essential
AttributevalueAttribute
The value attribute is used for determining the default value that should be used for displaying this source in a graph.
Sourceorg.unizone.0.4011type
inheritValue
SignaturevalueType
The value type determines which axes should be used in graphs.
Sourceorg.unizone.0.4002inheritValue
SourcesourceSourceAdapterSingleorg.unizone.0.4051

Method summaryDefined inOverridesProperties
voidactivateListable
voidcheckRangeSourceAdapterSingleSource
voiddesignEditor(WidgetWorkspace ws)Listable
voidgenerateScript(ScriptGenerationInfo info)SourceAdapterSingleScriptGenerator
Realget(DateTime timestamp)SourceAdapterSingleTimeseries
BooleanisResourceOf(Listable listable, Signature aspect)Mixabletype
ListablemixOn(Mixable mix)Mixable
ListablemixWith(Mixable mix)Mixable
voidput(DateTime timestamp, Real value)SourceAdapterSingleTimeseries
StringresourceStringListableintrospection
voidsetSource(Source source)SourceAdapterSingle
SourcesourceSourceAdapterSingle
voidXXXcom.nodelab.java.sourceadaptersingle.CheckRangeSourceAdapterSingle
SignatureXXXcom.nodelab.java.sourceadaptersingle.ValueTypeSourceAdapterSingle
voidcom.nodelab.java.source.ActivateSourceListable
Listablecom.nodelab.java.source.MixWithMiSourceMixable

Script summary
org.unizone.0.8546
import org.uninode.widget.Workspace;
import org.uninode.widget.Place;
import org.unizone.source.Source;
import org.uninode.Listable;
import com.nodelab.System;
import org.edgescript.ScriptGenerationInfo;
import org.uninode.dimension.DimensionHistory;
import org.uninode.collection.List;

constructor() {
  SourceAdapterSingleTimeseries:();
  days = 30;
//  addListener(Void () {changedHistory()});
}
constructor(Source src, Int days) {
  SourceAdapterSingleTimeseries:();
  setSource(src);
  this.days = days;
//  days.addListener(Void () {changedHistory()});
}
void setDays(Int days) {
  this.days = days;
}
type Boolean isResourceOf(Listable node, Signature aspect) {
  if (aspect == 'adapter') return true;
  false;
}
String displayName() {
  "" + days + " days average of " + source().toString();
}
/*
Signature valueType() {
  source.valueType;
}
*/
void designEditor(Workspace ws) {
//  ws.addLabel(new Place(0, 0).setPadding(5, 5), "Days");
//  ws.addField(new Place(1, 0).setPadding(20, 5), days, null);
}
trace void prepareRange() {
  System.report("preparing " + toString);
  Source src = source;
  List[Date] dates = new List[Date](10);
  List[Real] values = new List[Real](10);
  Date from = Date{DimensionHistory@'org.uninode.Dimension.from'};
  Date to = Date{DimensionHistory@'org.uninode.Dimension.to'};
  DimensionHistory@'org.uninode.Dimension.from' = from.addDays(-days);
  src.collectValues(dates, values, DimensionHistory);
  Real sum = 0.0;
  Int count = 0;
  Int fromIndex = 0;
  Int toIndex = -1;
  Int index = 0;
  Real val;
  while (index < dates.size && dates.get(index) < from) index = index + 1;
  while (index < dates.size) {
    while (toIndex < index) {
      toIndex = toIndex + 1;
      DimensionHistory@'org.uninode.Dimension.focus' = dates.get(toIndex);
      val = src.evaluate;
      if (val != null) {
        sum = sum + val;
        count = count + 1;
      }
    }
    Date fromDate = dates.get(index).addDays(-days);
    while (dates.get(fromIndex) < fromDate) {
      DimensionHistory@'org.uninode.Dimension.focus' = dates.get(fromIndex);
      val = src.evaluate;
      if (val != null) {
        sum = sum - val;
        count = count - 1;
      }
      fromIndex = fromIndex + 1;
    }
    if (count > 0)
      val = (10000.0 * sum / count).round / 10000.0;
    else
      val = null;
    put(dates.get(index), val);
    index = index + 1;
  }
}
void instanceScript(ScriptGenerationInfo info) {
//  getSource().instanceScript(info); // create variables
//  info.objectId(this, AverageDay, "ave");
}
void initScript(ScriptGenerationInfo info) {
//  String prefix = info.methodPrefix(this);
//  "  " + prefix + "setNextSource(" + getSource().instanceScript(info) + ");
//  " + prefix + "setDays(" + days.toString + ");
//";
}