Skip to content

lib-finWatcher 库参考 ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793259265/FIN+5.3.1+lib-finWatcher 中文整理基于 FIN 5.3.1

导读: FIN观察者扩展

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • lib
  • meta
  • docs
  • tags
  • funcs
  • Overview
  • finResetBoolStats(ops: Etc.makeDict(["runStarts","runTime"]))
  • finResetStatsStartTime(points: null, ts: null)
  • finWatcherCallbackOn(filter, chagedRefs: Etc.makeEmptyGrid())
  • standardFinWatcher(self, ts)
    • src

概述(中译) ​

FIN观察者扩展


API 正文(英文) ​

docs ​

Overview


tags ​

finBoolStatsFreqTune how often the FinWatcher computes boolean runStarts and runTime
finWatcherAddedMarker tag for an added record
finWatcherCallbackMarker tag for a callback function that instructs the watcher to call it when changes are detected
finWatcherCallbackOnAxon expression tag placed on a finWatcherCallback callback
finWatcherChangedMarker tag for a changed record
finWatcherChangedRefReference to the record that is detected as changed
finWatcherChangesA serialized Zinc grid that encodes which tags where added/changed/removed on a finWatcherChangedRef record
finWatcherFreqTune how often the FinWatcher looks for changes
finWatcherRemovedMarker tag for a removed record
statsResetTsSet the start time used to calculate the statistics

funcs ​

finResetBoolStatsResets runtime statistics for bool points By default this will reset both runStarts and runTime
finResetStatsStartTimeResets the start time from when boolean statistics are collected
finWatcherCallbackOnBased on the filter expression, returns a grid with all the changes that match the filter expression
standardFinWatcherstandardFinWatcher An example callback function that gets executed by the FinWatcher A callback function is a func marked record that has a valid Axon src tag

lib finWatcher ​

Overview ​

The FinWatcher extension implements a watch mechanism for detecting changes on equipments and also for collecting statistics on historized boolean points.

Each change detected creates a transient record containing:

  • a finWatcherChangedRef Ref that points to the record that changed
  • a marker tag for kind of change, finWatcherAdded, finWatcherChanged, finWatcherRemoved
  • if a change in the record structure is detected, marked as finWatcherChanged, then a finWatcherChanges must be present

The FinWatcher will call a function (func) marked with finWatcherCallback each time a change was detected. There can be multiple callback functions that get executed on a detection pass. The callback function must take 2 parameters, "self" that points to current callback function record id and a "timestamp" (Number) of the last change detected. Functions will take care of selecting what needs to be done with the detected changes and can use the timestamp parameter to process only newer changes. Adding finWatcherCallbackOn tag to a finWatcherCallback function, instructs the FinWatcher to only evaluate the callback function for changes that match the Axon expression inside the finWatcherCallbackOn tag. Change records older than current time - 2x finWatcherFreq will be marked as trash.

The statistic collector for boolean points collects data about how often a point has been in the true states and for how long for a period of time. Each history enabled boolean point will have 2 additional tags for those two values called "runStarts" and "runTime". The initial period is determined by the start date time of the history of that point, then as the stats run, the period's start is the last collector's end date time. The statsResetTs tag can override the start time of the time span the collector uses.



def ​

finBoolStatsFreq ​

Tune how often the FinWatcher computes boolean runStarts and runTime. If not configured it defaults to 1h. The value must be greater than 5 seconds


meta ​

deffinBoolStatsFreq
isnumber
liblib:finWatcher

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit


def ​

finWatcherAdded ​

Marker tag for an added record.


meta ​

deffinWatcherAdded
ismarker
liblib:finWatcher

supertypes ​

markerMarker labels a dict with typing information


def ​

finWatcherCallback ​

Marker tag for a callback function that instructs the watcher to call it when changes are detected.


meta ​

deffinWatcherCallback
ismarker
liblib:finWatcher

supertypes ​

markerMarker labels a dict with typing information


def ​

finWatcherCallbackOn ​

Axon expression tag placed on a finWatcherCallback callback. FinWatcher evaluates it to determine if the function can be called for the changes detected.


meta ​

deffinWatcherCallbackOn
isstr
liblib:finWatcher

supertypes ​

valData value type
scalarScalar is an atomic value kind
strUnicode string of characters


def ​

finWatcherChanged ​

Marker tag for a changed record.


meta ​

deffinWatcherChanged
ismarker
liblib:finWatcher

supertypes ​

markerMarker labels a dict with typing information


def ​

finWatcherChangedRef ​

Reference to the record that is detected as changed.


meta ​

deffinWatcherChangedRef
isref
liblib:finWatcher

supertypes ​

valData value type
scalarScalar is an atomic value kind
refReference to an entity


def ​

finWatcherChanges ​

A serialized Zinc grid that encodes which tags where added/changed/removed on a finWatcherChangedRef record


meta ​

deffinWatcherChanges
isstr
liblib:finWatcher

supertypes ​

valData value type
scalarScalar is an atomic value kind
strUnicode string of characters


def ​

finWatcherFreq ​

Tune how often the FinWatcher looks for changes. If not configured it defaults to 49sec.


meta ​

deffinWatcherFreq
isnumber
liblib:finWatcher

supertypes ​

valData value type
scalarScalar is an atomic value kind
numberInteger or floating point numbers annotated with an optional unit


def ​

finWatcherRemoved ​

Marker tag for a removed record.


meta ​

deffinWatcherRemoved
ismarker
liblib:finWatcher

supertypes ​

markerMarker labels a dict with typing information


def ​

func:finResetBoolStats ​

finResetBoolStats(ops: Etc.makeDict(["runStarts","runTime"])) ​

Resets runtime statistics for bool points

By default this will reset both runStarts and runTime.

Users can reset only one of them by setting the tag parameter like:

finResetBoolStats({runTime}) or finResetBoolStats({runStarts})


meta ​

deffunc:finResetBoolStats
isfunc
liblib:finWatcher
namefinResetBoolStats

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:finResetStatsStartTime ​

finResetStatsStartTime(points: null, ts: null) ​

Resets the start time from when boolean statistics are collected. there are 2 optional parameters:

  • point can be a point or list of points which need to be reseted, if null then all the bools stats point
  • time stamp, the datetime of the new stats collecting start, if null it is the current datetime

meta ​

deffunc:finResetStatsStartTime
isfunc
liblib:finWatcher
namefinResetStatsStartTime

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:finWatcherCallbackOn ​

finWatcherCallbackOn(filter, chagedRefs: Etc.makeEmptyGrid()) ​

Based on the filter expression, returns a grid with all the changes that match the filter expression.


meta ​

deffunc:finWatcherCallbackOn
isfunc
liblib:finWatcher
namefinWatcherCallbackOn

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function


def ​

func:standardFinWatcher ​

standardFinWatcher(self, ts) ​

standardFinWatcher An example callback function that gets executed by the FinWatcher A callback function is a func marked record that has a valid Axon src tag. The function is called by the FinWatcher with 2 arguments

  • self : the calback function record id
  • ts : last timestamp a change was registered

meta ​

deffunc:standardFinWatcher
disstandardFinWatcher
finWatcherCallback✓
finWatcherCallbackOnvavMyTest == marker()
isfunc
liblib:finWatcher
namestandardFinWatcher

supertypes ​

featureFeature namespace of definitions formatted as feature:name
funcAxon function

src ​

(self, ts) => do
    echo("Executing " + self->name)
     // only changed records
    if(self.toRec.has("finWatcherCallbackOn"))
      changes: finWatcherCallbackOn(self->finWatcherCallbackOn)
    else
      return null
    changes.each r => do
        // the record has a payload zip file stored
        f: finReadZipRes(`/pod/finWatcherExt/res/finWatcher/payload.zip`)
        // read the equip tags from the payload
        tags: f.finReadStrZipEntry("/equipTags.trio").ioReadTrio

        // determine what tags need to be added to the changed records
        changes: {}
        // add the tags from `equipTags.trio`
        rec: r->finWatcherChangedRef.toRec
        tags.each tr => do
          tr.each( (v,n) => do
            if(not rec.has(n)) do
              change:  {}
              if(changes.has(rec->id.toStr))
                change = changes.get(rec->id.toStr)
              change = change.set(n, v)
              changes = changes.set(rec->id.toStr, change)
            end
          end)
        end
        // commit the new amended records if any
        diffs: []
        changes.each ((v, n) => diffs = diffs.add(diff(n.parseRef.readById, v )))
        if(not diffs.isEmpty)
          commit(diffs)

        // add the missing program
        programs: f.finReadStrZipEntry("/programs.bline").ioReadZinc
        programs = programs.findAll r => r.has("program")
        programs.each p => do
          if(read(program and name == p->name, false) == null)
            diff(null, p, {add}).commit
        end
        // add the missing points
        points: f.finReadStrZipEntry("/Vav_Clg_Only.trio").ioReadTrio
        points = points.findAll p => p.has("point") and p.has("navName")

        points = points.findAll p => do
          read(point and navName == p->navName and equipRef == rec->id, false) == null
        end
        if(points.isEmpty)
          return null
        points = points.map p => do
         p = p.set("siteRef", rec["siteRef"])
          .set("equipRef", rec->id)
         if(rec.has("floorRef"))
          p = p.set("floorRef", rec["floorRef"])
         p = p.remove("id").remove("mod")
         return p
        end

        points = points.toRecList.map p => diff(null, p, {add})
        if(not points.isEmpty)
          commit(points)
    end
 end


def ​

statsResetTs ​

Set the start time used to calculate the statistics.


meta ​

defstatsResetTs
isdateTime
liblib:finWatcher

supertypes ​

valData value type
scalarScalar is an atomic value kind
dateTimeISO 8601 timestamp followed by timezone identifier