{"id":34213,"date":"2017-12-14T12:39:32","date_gmt":"2017-12-14T04:39:32","guid":{"rendered":"http:\/\/localhost\/help\/?page_id=34213"},"modified":"2018-10-12T16:14:38","modified_gmt":"2018-10-12T08:14:38","slug":"data-transformation-and-sample-methods-4-3-0","status":"publish","type":"page","link":"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/transforms\/data-transformation-and-sample-methods-4-3-0\/","title":{"rendered":"Data Transformation and Sample Methods (4.3.0)"},"content":{"rendered":"\n<p class=\"left-bar\">This article applies to versions 4.3.0-4.5.3 of P2 Server. For the latest, see\u00a0<a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/transforms\/\">Data Transformation and Sample Methods<\/a>.<\/p>\n<p class=\"intro-text\">In <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/server-system-overview\/\">P2 Server<\/a>, data may be requested raw or processed in some way. Currently the three kinds of data processing available are <em>average<\/em>, <em>last known value<\/em>, and <em>linear interpolate<\/em>. In P2 Server these different aggregations are known as <em>sample methods<\/em>.<\/p>\n<p class=\"intro-text\">How each of these sample methods is determined can vary from one source of data to another.\u00a0 Most Historians already have these functions built in, so P2 Server delegates these aggregations to the Historian to perform, so that we get the fastest and most accurate aggregations possible.<\/p>\n<p class=\"intro-text\">For any systems that do not have such features, P2 Server has a built-in set that will be used. \u00a0This article describes how these functions process the data.<\/p>\n<h2 class=\"page-subheading\">Background<\/h2>\n<p class=\"intro-text\">Before we get into how these methods work, let\u2019s define some of the other inputs to these functions.\u00a0When we ask P2 Server for data we need to specify a few parameters so that P2 Server knows what to do with the data.<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"165\">\n<p class=\"intro-text\"><strong>Start and End time (Request Interval)<\/strong><\/p>\n<\/td>\n<td>\n<p class=\"intro-text\">The start and end time for the request is sometimes called the <em>request interval<\/em>. These two times specify the whole range over which we want data. Note that start and end times are inclusive. For example, if we want data for the whole day, we may use 1\/1\/2015 00:00 and the 1\/1\/2015 23:59 to specify that we want data for that day only. Note that the calling application (e.g. <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-explorer\/\" target=\"_blank\" rel=\"noopener\">P2 Explorer<\/a>) must send the request interval to P2 Server in UTC.<\/p>\n<p class=\"intro-text\">When getting data from P2 Server, depending on how you set the request interval, you can get P2 Server to return different numbers of results. These two different methods are known as Range Fetches and Single Point (or Spot) Fetches.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p class=\"intro-text\"><strong>Sample Interval (Density)<\/strong><\/p>\n<\/td>\n<td>\n<p class=\"intro-text\">The <em>sample interval<\/em> is the amount of time between each data point that will be returned. If we set the sample interval to 3600 seconds, we will get a data point returned every hour between the start and end time (request interval). If that start and end time are 1 day apart, we will get 24 values returned, one per hour.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p class=\"intro-text\"><strong>Sample Methods<\/strong><\/p>\n<\/td>\n<td>\n<p class=\"intro-text\">The rest\u00a0of this article details how the built-in aggregations work inside P2 Server.\u00a0Note that if the source system natively supports any of the following sample methods, adaptors will often be written to use the source system\u2019s functions, rather than P2 Server\u2019s calculations as described below. However this is dependent on the adaptor itself.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"left-bar\">Related: <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/transforms\/single-point-fetch-vs-range-fetch\/\">Single Point Fetch vs Range Fetch<\/a>, <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/datasources\/\">Datasources and Adaptors<\/a><\/p>\n<h2 class=\"page-subheading\">Formulas<\/h2>\n<h3>Average<\/h3>\n<p class=\"intro-text\">The Average sample method returns a time-weighted average of the raw data for each sample interval over the specified request interval. The set of time-value pairs returned are generated using the following formula:<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image001.png\" rel=\"lightbox-0\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-4577\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image001-400x260.png\" alt=\"image001\" width=\"400\" height=\"260\" \/><\/a><\/p>\n<p class=\"intro-text\">The request interval <strong>[ts, tf]<\/strong> is divided into intervals using the configured sample interval <em><strong>SI<\/strong><\/em>. If the specified request interval is not an integral multiple of <em><strong>SI<\/strong><\/em>, then the returned results will cover slightly less than the desired interval (this gap is the interval <strong>[S2, tf]<\/strong>.<\/p>\n<p class=\"intro-text\">As a result, the request interval <strong>[ts, tf]<\/strong> will be broken into N intervals, where:<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003.png\" rel=\"lightbox-1\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4578\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003.png\" alt=\"image003\" width=\"160\" height=\"48\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003.png 160w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003-150x45.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003-24x7.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003-36x11.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image003-48x14.png 48w\" sizes=\"auto, (max-width: 160px) 100vw, 160px\" \/><\/a><\/p>\n<p class=\"intro-text\">There will be <em><strong>N<\/strong><\/em> aggregate values returned at times (s0, s1, \u2026 , sN), where:<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004.png\" rel=\"lightbox-2\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4579\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004.png\" alt=\"image004\" width=\"160\" height=\"39\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004.png 160w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004-150x37.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004-24x6.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004-36x9.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image004-48x12.png 48w\" sizes=\"auto, (max-width: 160px) 100vw, 160px\" \/><\/a><\/p>\n<p class=\"intro-text\">A time-weighted average is calculated for each interval, which factors into the result the amount of time each raw value was held during the sample interval.<\/p>\n<p class=\"intro-text\">In the above figure, the result for the second interval <strong>(s1,s2)<\/strong> will be <strong>v4<\/strong>, since the value is constant over the entire interval. As the raw value changes during <strong>(s0,s1)<\/strong>, the reported value will be an average of the four raw values over that interval, weighted by the duration that each raw value is held:<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005.png\" rel=\"lightbox-3\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4580\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005.png\" alt=\"image005\" width=\"223\" height=\"62\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005.png 223w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005-150x42.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005-24x7.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005-36x10.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image005-48x13.png 48w\" sizes=\"auto, (max-width: 223px) 100vw, 223px\" \/><\/a><\/p>\n<p class=\"intro-text\">The data used to calculate an average value for <strong>s0<\/strong> is based on an interval of<strong> <em>SI <\/em><\/strong>that ends at <strong>s0<\/strong>. To fulfil a request for average-sampled data at a particular instant in time <strong>(<em>ti<\/em>)<\/strong>, the <a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/datasources\/\">adaptor <\/a>examines the raw data over the interval <strong>(ti-SI, ti)<\/strong> and calculates the time-weighted average value over that interval. The value is reported for time <em><strong>ti<\/strong><\/em>.<\/p>\n<p>&nbsp;<\/p>\n<h3>Last Known Value<\/h3>\n<p class=\"intro-text\">The calculations of <em>last known value<\/em> data returns the last known raw value at the end of each sampling interval. As with time-weighted average data, the request interval <strong>[ts,tf]<\/strong> is first divided into <strong>N<\/strong> sample intervals, and values are reported for the end of each interval. The set of reported values are simply the raw value of the input at each of the times <strong>(s0, s1, \u2026 , sN)<\/strong>.<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006.jpg\" rel=\"lightbox-4\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4581\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006.jpg\" alt=\"image006\" width=\"382\" height=\"240\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006.jpg 382w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006-150x94.jpg 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006-24x15.jpg 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006-36x23.jpg 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image006-48x30.jpg 48w\" sizes=\"auto, (max-width: 382px) 100vw, 382px\" \/><\/a><\/p>\n<p class=\"intro-text\">In the above figure, the returned data would be three points: <strong>(s0,v1)<\/strong>, <strong>(s1,v4)<\/strong> and <strong>(s2,v4)<\/strong>. For last-known-value at a single-point instant, the algorithm looks for the most recent raw value from the source, but returns it with a timestamp of the requested sample interval time, which will be the same or after the raw value's actual time (the time of s0, S1 and S2).<\/p>\n<p>&nbsp;<\/p>\n<h3>Linear Interpolate<\/h3>\n<p class=\"intro-text\">For linear interpolate aggregate data, the sample period <strong>(ts, tf)<\/strong> is divided into intervals using the same process as for time-weighted average and last known value.<\/p>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image007.png\" rel=\"lightbox-5\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-4582\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image007-400x256.png\" alt=\"image007\" width=\"400\" height=\"256\" \/><\/a><\/p>\n<p class=\"intro-text\">Sample values are reported at the start of the request period, and all sample interval boundaries: (s0, s1, \u2026, sN). For each sample point, the formula looks for the most recent raw value and the closest subsequent raw value, and uses those two values as end points of a line. The value of that line at the sample point is the returned aggregate value.<\/p>\n<p class=\"intro-text\">In the above figure, the value at <strong>s0<\/strong> is based on the nearest previous value at <strong>t1<\/strong> and the nearest subsequent value at <strong>t2<\/strong>. The value reported at <strong>s0<\/strong> would be:<\/p>\n<p class=\"intro-text\"><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009.png\" rel=\"lightbox-6\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4583\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009.png\" alt=\"image009\" width=\"216\" height=\"60\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009.png 216w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009-150x42.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009-24x7.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009-36x10.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/image009-48x13.png 48w\" sizes=\"auto, (max-width: 216px) 100vw, 216px\" \/><\/a><\/p>\n<p class=\"intro-text\">In some situations, such as the values for <strong>s2<\/strong> and <strong>s3<\/strong>, the same two raw value data points may be used to calculate linear interpolated values for two different sample points. For the last sample point, the formula will need a raw value potentially beyond the end of the requested sample period (after <strong>tf<\/strong>). The adaptor looks forward in time using configuration values to find the next raw value.<\/p>\n<h2 class=\"page-subheading\">Cheat Sheet<\/h2>\n<p class=\"intro-text\">The following images provide a simplified overview of how the sample methods are calculated.<\/p>\n<div class=\"best-prac\">\n<p class=\"best-prac-desc\"><i class=\"fa fa-download fa-2x fa-pull-left\"><\/i> \u00a0\u00a0<a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/printables\/P2%20Server%20Sampling%20Cheat%20Sheet.pdf\">Download the cheat sheet!<\/a><\/p>\n<\/div>\n<h3>Average<\/h3>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4.png\" rel=\"attachment wp-att-11635 lightbox-7\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12765 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4.png\" alt=\"\" width=\"916\" height=\"449\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4.png 916w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4-768x376.png 768w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4-150x74.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4-24x12.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4-36x18.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/averagesm4-48x24.png 48w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/a><\/p>\n<h3>Last Known Value<\/h3>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3.png\" rel=\"attachment wp-att-11637 lightbox-8\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12713 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3.png\" alt=\"\" width=\"892\" height=\"404\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3.png 892w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3-768x348.png 768w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3-150x68.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3-24x11.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3-36x16.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lkvsm3-48x22.png 48w\" sizes=\"auto, (max-width: 892px) 100vw, 892px\" \/><\/a><\/p>\n<h3>Linear Interpolate<\/h3>\n<p><a href=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3.png\" rel=\"attachment wp-att-11636 lightbox-9\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12714 size-full\" src=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3.png\" alt=\"\" width=\"916\" height=\"432\" srcset=\"https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3.png 916w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3-768x362.png 768w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3-150x71.png 150w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3-24x11.png 24w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3-36x17.png 36w, https:\/\/oihelp.corporate.ifs.com\/help\/wp-content\/uploads\/2015\/05\/lism3-48x23.png 48w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In P2 Server, data may be requested raw or processed in some way. Currently the three kinds of data processing available are average, last known value, and linear interpolate. In P2 Server these different aggregations are known as sample methods. This article looks at the different sample methods available in P2 Server, and how they are calculated.<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"https:\/\/oihelp.corporate.ifs.com\/help\/p2-server\/primers\/transforms\/data-transformation-and-sample-methods-4-3-0\/\">Read more<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":33928,"parent":3672,"menu_order":1,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[3],"tags":[276,285,100,291,292,296,289,290,212,288,287,154,422,277],"class_list":["post-34213","page","type-page","status-publish","has-post-thumbnail","hentry","category-primer","tag-aggregation","tag-average","tag-calculations","tag-data-fetch","tag-density","tag-formulas","tag-last-known-value","tag-linear-interpolate","tag-raw","tag-request-interval","tag-sample-methods","tag-time","tag-time-weighted","tag-transformation","Version-4-5-0","Version-4-5-1","Version-4-5-2","Version-4-5-3","Product-srv"],"_links":{"self":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/34213","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=34213"}],"version-history":[{"count":0,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/34213\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/pages\/3672"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media\/33928"}],"wp:attachment":[{"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/media?parent=34213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/categories?post=34213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oihelp.corporate.ifs.com\/help\/wp-json\/wp\/v2\/tags?post=34213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}