
PI Coresight 2016 Download Values Custom Symbol
Posted by Kenji Hashimoto in Kenji Hashimoto's Blog on Jul 20, 2016 3:53:47 AMI think some of the users, partners have created the custom symbol that can download the data.
Though I created sample custom symbol and I want to share it with community.
From here, you can put the tag or attribute to display and just click "Download".
Then you will get "Download.csv"
The downloaded contents are following.
HOU.Press.01|Mold Temperature,af:\\KHASHIMOTOE6440\PIBigTiresCo\Houston\HOU.Press.01|Mold Temperature 2016/07/20 4:01:30,36.056 2016/07/20 4:03:00,39.325 2016/07/20 4:04:30,38.216 ... (a lot of data) 2016/07/20 12:00:00,37.682 2016/07/20 12:00:30,37.062
So tags/attributes recorded values (From display's start time to end time) can be downloaded by this custom symbol.
The point is that I use DataQueryMode: CS.DataQueryMode.ModeEvents. So we can get recorded values. (PI Coresight 2016 Extensibility Documentation says "ModeEvents: Returns archived values.")
Copy following 2 files to %PIHOME64%\Coresight\Scripts\app\editor\symbols\ext folder.
Also copy the image (attaced download.svg) to %PIHOME64%\Coresight\Images folder.
sym-downloadvalues.js
(function (CS) { 'use strict'; var contents; var def = { typeName: 'DownloadValues', iconUrl: 'Images/download.svg', datasourceBehavior: CS.DatasourceBehaviors.Multiple, getDefaultConfig: function () { return { DataShape: 'TimeSeries', DataQueryMode: CS.DataQueryMode.ModeEvents, Height: 50, Width: 400, TextColor: 'rgb(255,255,255)', }; }, init: init }; function init(scope, elem) { var container = elem.find('#Download')[0]; if (scope.symbol.DataSources) { scope.symbol.DataSources.forEach(function (item) { item = item ? item.toString() : ''; // Make sure it's a string var path = item; item = item.substr(item.lastIndexOf('\\') + 1) || item; // strip out server and database item = item.substr(0, item.indexOf('?')) || item; // remove ID after last '?' scope.label = item; }); } function onUpdate(data) { if(data) { scope.contents= scope.label + "," + scope.symbol.DataSources[0] + "\r\n"; data.Data[0].Values.forEach( function(item) { var time = item.Time; var val = item.Value; scope.contents = scope.contents + time + "," + val + "\r\n"; }); } } scope.download = function() { var datacsv = new Blob([scope.contents]); container.href = URL.createObjectURL(datacsv); }; return { dataUpdate: onUpdate }; } CS.symbolCatalog.register(def); })(window.Coresight);
sym-downloadvalues-template.html
<div ng-style="{color: config.TextColor}"> <div>{{label}}</div> <a id='Download' class="btn" download='Download.csv' type='text/csv' ng-click="download()">Download</a> </div>
You can find these files in GitHub too.
GitHub - kenji0711/PICoresight2016-CustomSymbol-DownloadValues
So enjoy the download function!!
Adding this, PI Coresight 2016 R2 will have download data to Excel function officially.
PI Coresight - Roadmap Details
So it is also good to wait for PI Coresgiht 2016 R2 too.
Worked with Jerome Lefebvre
Comments:
I checked that Chrome, Firefox works fine but IE does not work.
-
download.svg.zip 788 bytes
Comments