{"id":9460,"date":"2016-02-18T09:23:27","date_gmt":"2016-02-18T01:23:27","guid":{"rendered":"http:\/\/localhost\/help\/?page_id=9460"},"modified":"2024-08-15T10:31:31","modified_gmt":"2024-08-15T02:31:31","slug":"sampling","status":"publish","type":"page","link":"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/sampling\/","title":{"rendered":"Sampling()"},"content":{"rendered":"\n<h2>Format<\/h2>\n<p class=\"intro-text\"><strong>Sampling(Expr, Method[, Interval])<\/strong><\/p>\n<h2>Purpose<\/h2>\n<p class=\"intro-text\">Overrides the sample method and\/or sample interval passed to tags referenced within the expression.\u00a0<br \/>\nThis function should only be used with time series data.<\/p>\n<p class=\"left-bar\">Related: <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/transforms\/\">Data Transformation and Sample Methods<\/a><\/p>\n<div class=\"best-prac\">\n<p class=\"best-prac-desc\"><i class=\"fa fa-download fa-2x fa-pull-left\"><\/i> \u00a0\u00a0New to sample methods? <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/printables\/P2%20Server%20Sampling%20Cheat%20Sheet.pdf\">Download the cheat sheet!<\/a><\/p>\n<\/div>\n<h2>Inputs<\/h2>\n<p class=\"intro-text\"><strong>Expr<\/strong>: The expression containing the tags to be fetched.<br \/>\nBehaviour: Required<br \/>\nDimension: Collection, SingleValue, Matrix, Error, MultiCollection<br \/>\nValid data\u00a0types: Boolean, DateTime, Decimal, Integer, String, Duration, Error, Null<\/p>\n<p class=\"intro-text\"><strong>Method<\/strong>: Fetch tags using the specified sample method. \u00a0<br \/>\nOptions: \"average\", \"linearinterpolate\", \"lastknownvalue\", \"raw\"<br \/>\nBehaviour: Required<\/p>\n<p class=\"intro-text\"><strong>Interval<\/strong>: Fetch tags using the specified sample interval.<br \/>\nBehaviour: Optional<br \/>\nDimension: SingleValue<br \/>\nValid data\u00a0types: Decimal, Integer, Duration<\/p>\n<p class=\"left-bar\">Notes:<br \/>\n- When intervals are expressed as numbers (decimal or integer), they are interpreted as seconds.<br \/>\n- Decimals are expressed by using a decimal point and at least 1 decimal number e.g. 60.0<\/p>\n<h2>Examples<\/h2>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Sampling({tagname}, \"raw\")<\/span><br \/>\nResult: Fetch tags using the Raw sample method<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Sampling({tagname}, \"average\", 60)<\/span><br \/>\nResult:\u00a0Fetch tags using the Average sample method, with an interval of 60 seconds expressed as an integer.<\/p>\n<p class=\"intro-text\">Expression:\u00a0<span class=\"code-fragment\">Sampling({tagname}, \"lastknownvalue\", 60.0)<\/span><br \/>\nResult:\u00a0Fetch tags using the Last Known Value sample method, with an interval of 60 seconds expressed as a decimal.<\/p>\n<p class=\"intro-text\">Expression:\u00a0<span class=\"code-fragment\">Sampling({tagname}, \"linearinterpolate\", {du'0:01'})<\/span><br \/>\nResult:\u00a0Fetch tags using the Linear Interpolate sample method, with an interval of 1 minute expressed as a duration.<\/p>\n<p class=\"intro-text\"><em>The following trend shows the {Silver} tag with different sampling methods being overridden using Sampling().<\/em><\/p>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend2.png\" rel=\"attachment wp-att-11186 lightbox-0\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-11186\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend2-800x268.png\" alt=\"sampling-trend2\" width=\"800\" height=\"268\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p class=\"intro-text\">Expression:\u00a0<span class=\"code-fragment\">Sampling({Entity[Template]:Attribute!AttributeValue}, \"raw\")<\/span><br \/>\nResult:\u00a0Fetch the attribute\u00a0using the Raw sample method.<\/p>\n<p class=\"intro-text\">It is possible to retrieve very large volumes of data through indiscriminate use of the raw sample method. Retrieving large amounts of historian data across a slow network can affect system performance for all users of the system.<\/p>\n<p class=\"intro-text\"><em>The following trend shows an attribute being trended\u00a0using the Raw\u00a0sampling method.<\/em><\/p>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2.png\" rel=\"attachment wp-att-10822 lightbox-1\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10822\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2.png\" alt=\"sampling-trend-2\" width=\"776\" height=\"498\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2.png 776w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2-768x493.png 768w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2-150x96.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2-24x15.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2-36x23.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-2-48x31.png 48w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p class=\"intro-text\">Expression: <span class=\"code-fragment\">Sampling({tagname}\/100, \"average\", 3600)<\/span><br \/>\nResult:\u00a0Fetch the tag and divide it by 100, then apply the Average\u00a0sample method and a sample interval of 3600 seconds (1 hour).<\/p>\n<p class=\"intro-text\"><em>The following trend shows the Silver tag\u00a0being divided by 100 and then trended\u00a0using the Average\u00a0sampling method with a sample interval of 3600 seconds.<\/em><\/p>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3.png\" rel=\"attachment wp-att-10840 lightbox-2\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10840\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3.png\" alt=\"sampling-trend-3\" width=\"778\" height=\"346\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3.png 778w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3-768x342.png 768w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3-150x67.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3-24x11.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3-36x16.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2016\/02\/sampling-trend-3-48x21.png 48w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/a><\/p>\n<p><strong>Using Sampling() instead of\u00a0Tag Syntax<\/strong>:<\/p>\n<p class=\"intro-text\">Sampling() can be used as a shortcut for expressions using tag syntax, typically used when overriding context parameters. For example:<\/p>\n<p class=\"intro-text\">This expression:<\/p>\n<pre>Sampling({myTag}, \"LastKnownValue\", {du'01:00'})<\/pre>\n<p class=\"intro-text\">Is the same as:<\/p>\n<pre>{myTag, sampleMethod=\"LastKnownValue\", sampleInterval={du'01:00'}}<\/pre>\n<h2>Common Traps<\/h2>\n<p class=\"intro-text\">Empty strings for the sample method are not accepted. E.g. The following example is not valid:<\/p>\n<p class=\"intro-text\">Sampling({tagname}, \"\", 60)<\/p>\n<p class=\"intro-text\">Expected result:\u00a0Override only the sample interval but not the sample method while fetching tags.<br \/>\nActual result: Calculation cannot be parsed as empty strings are not accepted. The equivalent correct call is:\u00a0<br \/>\n<span class=\"code-fragment\">Sampling({tagname}, param[sampleMethod], 60)<\/span><\/p>\n<p class=\"left-bar-yellow\">It is possible to retrieve very large volumes of data through indiscriminate use of this function. Retrieving large amounts of historian data across a slow network can affect system performance for all users of the system.<\/p>\n<h2><span id=\"Release_History\">Release History<\/span><\/h2>\n<ul class=\"intro-text\">\n<li>Sampling() 4.6.5\n<ul class=\"intro-text\">\n<li>Changed Expr parameter to support MultiCollection values.<\/li>\n<\/ul>\n<\/li>\n<li>Sampling() 4.0\n<ul class=\"intro-text\">\n<li>Initial version<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Use Sampling() to override the sampling method and\/or interval passed to tags referenced within the argument.<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/calculations\/sampling\/\">Read more<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":9638,"parent":3650,"menu_order":184,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[9],"tags":[100,361],"class_list":["post-9460","page","type-page","status-publish","has-post-thumbnail","hentry","category-tech-ref","tag-calculations","tag-sampling","Version-4-0","Version-4-6-5","Product-srv"],"_links":{"self":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/9460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/comments?post=9460"}],"version-history":[{"count":3,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/9460\/revisions"}],"predecessor-version":[{"id":64760,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/9460\/revisions\/64760"}],"up":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/3650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media\/9638"}],"wp:attachment":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media?parent=9460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/categories?post=9460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/tags?post=9460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}