<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CSV with 1 minute rollup auto emailed via Meta Source]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/3741/get-roll-up-in-scripted-data-source">Get roll up in scripted data source</a></p>
<p dir="auto">So I've been playing with scripting in a meta source and have been able to print a few values, or print values and times but haven't quite pieced together the whole picture. I am aiming to make a csv report for the past 24 hours of around 6 different points (executed around midnight) with the data rolled up into 1 minute averages. I have already made a custom ftl and an excel report configured.</p>
<p dir="auto">Some of the random attempts at understanding below (stolen from other forum posts) - -&gt;</p>
<pre><code>var stdDevInput = []
PointValueQuery.query( [ p341.getDataPointWrapper().getId() ], CONTEXT.getTimestamp() - 600000, CONTEXT.getTimestamp(), false, function( value, index ) {
  stdDevInput.push( value.DoubleValue);
});
print(stdDevInput.length);

/*/var d = new Date().getTime();
var endDate = CONTEXT.getTimestamp();
var startDate = endDate - CONTEXT.millisInPast(DAY, 10); //handles DST shenanigans
var results = [];
var callback = function(idValueTime) {
  results.push(idValueTime);};
var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
PointValueQuery.rollupQuery( pointsToQuery, startDate, endDate, callback, LAST, 1, DAY);
//print(results);
//var pointies = DataPointQuery.query('like(name, *Ptot_kW*)&amp;limit(3)');
//var points = DataPointQuery.query("and(like(deviceName,BachmannPLC*),eq(name,Ptot_kW))&amp;limit(5)");
//var values = p341.pointValuesSince(CONTEXT.getTimestamp() - 300000);
//print(values[0].time);
//print(values);
//print(points);

 var values = [];
var valueCallback = function( value, index ) { //function definition in com.infiniteautomation.mango.db.query.PVTQueryCallback
    values.push(value);
  };
for( var point in CONTEXT_POINTS ) {
  PointValueQuery.query( [ p341.getDataPointWrapper().getId() ], 0, CONTEXT.getRuntime(), true, valueCallback);
}
print(values);
print (results);
*/
</code></pre>
]]></description><link>https://forum.mango-os.com/topic/4239/csv-with-1-minute-rollup-auto-emailed-via-meta-source</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 11:03:40 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/4239.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 06 Jun 2019 06:48:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 18:35:04 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Phil, I should have asked you about that months ago. Having no timestamp with the values turned me away from using it.</p>
]]></description><link>https://forum.mango-os.com/post/22358</link><guid isPermaLink="true">https://forum.mango-os.com/post/22358</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 18:35:04 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 16:42:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mattfox" aria-label="Profile: mattfox">@<bdi>mattfox</bdi></a> said in <a href="/post/22342">CSV with 1 minute rollup auto emailed via Meta Source</a>:</p>
<blockquote>
<p dir="auto">I don't think it attached a timestamp. If you want timestamps, we'll have to go via the HTTP Request route and query the API directly to pull a rolled up point values query.</p>
</blockquote>
<p dir="auto">Not so! For the rollupQuery, while it is true that if you supply a particular rollup type the callback will be handed the simple value and the inference is left to you to add the number of rollup periods from the start time to get the nth timestamp (every period will get a callback). But, if you use a rollup of <code>ALL</code> the whole statistics object (<code>AnalogStatistics</code> object in a Numeric case) is passed to the callback: <a href="https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/statistics/AnalogStatistics.java" rel="nofollow ugc">https://github.com/infiniteautomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/statistics/AnalogStatistics.java</a></p>
]]></description><link>https://forum.mango-os.com/post/22355</link><guid isPermaLink="true">https://forum.mango-os.com/post/22355</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Fri, 07 Jun 2019 16:42:13 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 09:10:03 GMT]]></title><description><![CDATA[<p dir="auto">updated code snippet with 3 points and a timestamp array concatenated then emailed</p>
<pre><code>//your code here
//Query to Retrieve and rollup previous 24 Hours Data
var endDate = CONTEXT.getTimestamp();
var startDate = endDate - CONTEXT.millisInPast(MINUTE, 4); //handles DST shenanigans
var results = [];
var callback = function(idValueTime) {
  results.push(idValueTime);};
//var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
PointValueQuery.rollupQuery( [341,342,282], startDate, endDate, callback, AVERAGE, 1, MINUTE);
print(results);

//Date and time Variables
var d = new Date();
var t = new Date().getTime();
var y = d.getYear()-70;
var m = d.getMonth();
var dayinmonth = d.getDate();
var hours = d.getHours();
//ECMA function to convert date to locale string YYYY-MM-DD
var datestring = d.toLocaleDateString();
//Substr fX to make date DD-MM-YYYY time format
var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
var CSVname = "Performance_"+ddmmyyyy+".csv";

//Creating DateTime For Array
// 31556926000 mS in Year
// 2629743000 ms in Month
// 86400000 ms in Day
//3600000 ms in an Hour
//print(results[0].toString()+d.toString()+"\r\n");
var coeff = 1000 * 60 * 1;
var date = new Date();
//var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);

//var csvData =[];
var csvData ="kW,Timestamp\r\n";
var TimeWatch = [];
results.forEach(function(results,index){
    //csvData[index]=results+","+TimeAgo+"\r\n";
    var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);
    TimeWatch[index]=TimeAgo;
    if((index+1)%3&lt;1){
    TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+((index-2)/3)*60000);    
      csvData = csvData+results+","+TimeAgo+"\r\n";  
    }
    else{
        csvData = csvData+results+",";
    }
});
//csvDataString = csvData.toString();
print(csvData);
//print(TimeWatch);
/*
var recipients = ["funtimes84@live.com"];
var emailContent = new com.serotonin.web.mail.EmailContent(null, 
  "Email body content", com.serotonin.m2m2.Common.UTF8);
var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
  "PerformanceCSV"+datestring+".csv", csvDataString.getBytes());

emailContent.addAttachment(emailAttachment);
com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "NorthamCSV_"+ddmmyyyy, emailContent, null);
*/
</code></pre>
]]></description><link>https://forum.mango-os.com/post/22350</link><guid isPermaLink="true">https://forum.mango-os.com/post/22350</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 09:10:03 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 07:27:53 GMT]]></title><description><![CDATA[<p dir="auto">Man you really have gone above and beyond, you're making it rather complex for what you need.</p>
<ol>
<li>go into the user setting in the dashboard and use it to make yourself a token based bearer authentication key.<br />
<a href="https://help.infiniteautomation.com/mango-rest-api-authentication" rel="nofollow ugc">https://help.infiniteautomation.com/mango-rest-api-authentication</a></li>
</ol>
<p dir="auto">Next let's incorporate your timeframes into this:</p>
<pre><code>if (!Date.prototype.toISOString) {
  (function() {

    function pad(number) {
      if (number &lt; 10) {
        return '0' + number;
      }
      return number;
    }

    Date.prototype.toISOString = function() {
      return this.getUTCFullYear() +
        '-' + pad(this.getUTCMonth() + 1) +
        '-' + pad(this.getUTCDate()) +
        'T' + pad(this.getUTCHours()) +
        ':' + pad(this.getUTCMinutes()) +
        ':' + pad(this.getUTCSeconds()) +
        '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
        'Z';
    };

  }());
}

var xid = "internal_mango_uptime_hrs"; //for example this would be your context point XID
function GenerateEmail(data)
{
    var csvStr = "kW,Timestamp\r\n";
   for(var i=0;i&lt;data.length; i++)
   {
      csvStr += data[ i ].value+","+data[ i ].timestamp+"\r\n";
   }
var d = new Date();

//Substr fX to make date DD-MM-YYYY time format
var ddmmyyyy = d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear();
var CSVname = "Performance_"+ddmmyyyy+".csv";

var recipients = ["funtimes@live.com"];
var emailContent = new com.serotonin.web.mail.EmailContent(null, 
  "Email body content", com.serotonin.m2m2.Common.UTF8);
var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
  "attached"+datestring+".csv", csvStr.getBytes());

emailContent.addAttachment(emailAttachment);
com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "Attachment test", emailContent, null);

}

var to = new Date( CONTEXT.getTimestamp() );
var from = new Date( to.valueOf() - CONTEXT.millisInPast(MINUTE, 4) ); 
var rollup="AVERAGE";
var rollupPeriod = "MINUTES";
var rollupPeriodTime = "1";
//handles DST shenanigans
print(from.toISOString());
print(to.toISOString());
var _URL="http://localhost/rest/v1/point-values/"+xid+"?from="+from.toISOString()+
"&amp;rollup="+rollup+"&amp;timePeriodType="+rollupPeriod+"&amp;timePeriods="+rollupPeriodTime+"&amp;to="+to.toISOString();
//print(_URL);
HttpBuilder.get(_URL,
{"Accept":"*/*" ,
"Authorization":"Bearer \
[BEARER_TOKEN_HERE]"

}
,{}).err(function(status, headers, content) { //setErrorCallback for linguistic completion
	 print(content); print(status);
	}).resp(function(status, headers, content) { //setResponseCallback
			print(status);	print(content);
if(content.length)
{
       GenerateEmail(content); //don't generate if there are not any values
}
	}).excp(function(exception) { //setExceptionCallback
		//throw exception.getMessage();
		print(exception.getMessage() );
		}).execute();
</code></pre>
]]></description><link>https://forum.mango-os.com/post/22348</link><guid isPermaLink="true">https://forum.mango-os.com/post/22348</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 07:27:53 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 06:43:59 GMT]]></title><description><![CDATA[<p dir="auto">this seems to have worked i had trouble using arrays with a ,toString function where the "," was appearing in the final csv string - ie)<br />
Head1,Head2<br />
Val1,time1<br />
,Val2,time2<br />
,Val3,time3</p>
<p dir="auto">Using Strings seems to ahve gotten the correct output but im worried a string variable might get angry when it contains 1440*7 Values/time</p>
<p dir="auto">code so far --</p>
<pre><code>//Query to Retrieve and rollup previous 24 Hours Data
var endDate = CONTEXT.getTimestamp();
var startDate = endDate - CONTEXT.millisInPast(MINUTE, 4); //handles DST shenanigans
var results = [];
var callback = function(idValueTime) {
  results.push(idValueTime);};
var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
PointValueQuery.rollupQuery( [341], startDate, endDate, callback, AVERAGE, 1, MINUTE);
print(results);

//Date and time Variables
var d = new Date();
var t = new Date().getTime();
var y = d.getYear()-70;
var m = d.getMonth();
var dayinmonth = d.getDate();
var hours = d.getHours();
//ECMA function to convert date to locale string YYYY-MM-DD
var datestring = d.toLocaleDateString();
//Substr fX to make date DD-MM-YYYY time format
var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
var CSVname = "Performance_"+ddmmyyyy+".csv";

//Creating DateTime For Array
// 31556926000 mS in Year
// 2629743000 ms in Month
// 86400000 ms in Day
//3600000 ms in an Hour
//print(results[0].toString()+d.toString()+"\r\n");
var coeff = 1000 * 60 * 1;
var date = new Date();
//var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);

//var csvData =[];
var csvData ="kW,Timestamp\r\n"

results.forEach(function(results,index){
    //csvData[index]=results+","+TimeAgo+"\r\n";
    var TimeAgo = new Date((Math.round((date.getTime()-(hours*3600000)) / coeff) * coeff)+index*60000);
    csvData = csvData+results+","+TimeAgo+"\r\n";
    
});
//csvDataString = csvData.toString();
print(csvData)
</code></pre>
]]></description><link>https://forum.mango-os.com/post/22347</link><guid isPermaLink="true">https://forum.mango-os.com/post/22347</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 06:43:59 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 03:38:34 GMT]]></title><description><![CDATA[<p dir="auto">Note you'll want to fire the email <em>after</em> your callback returns so you'd be best to place it inside it otherwise you'll be firing an empty attachment.</p>
<pre><code>var callback = function(idValueTime) {
  results.push(idValueTime);
generateEmail(results);
};
function generateEmail(res)
{
var d = new Date();
//ECMA function to convert date to locale string YYYY-MM-DD
var datestring = d.toLocaleDateString();
//Substr fX to make date DD-MM-YYYY time format
var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
var CSVname = "Performance_"+ddmmyyyy+".csv";
print(CSVname);
/*
var recipients = ["funtimes@live.com"];
var emailContent = new com.serotonin.web.mail.EmailContent(null, 
  "Email body content", com.serotonin.m2m2.Common.UTF8);
var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
  "attached"+datestring+.csv", "Head1,Head2\r\n12,22".getBytes());

emailContent.addAttachment(emailAttachment);
com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "Attachment test", emailContent, null);
*/
}
</code></pre>
<p dir="auto">I believe that the rolled up point value query just returns an array of all of the values only. I don't think it attached a timestamp. If you want timestamps, we'll have to go via the HTTP Request route and query the API directly to pull a rolled up point values query.</p>
]]></description><link>https://forum.mango-os.com/post/22342</link><guid isPermaLink="true">https://forum.mango-os.com/post/22342</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 03:38:34 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 02:52:44 GMT]]></title><description><![CDATA[<p dir="auto">So far so good. Query works, Email attachment works, and can seperate rows using /r/n. Not sure what variable type is returned by the query but its returned as number,number, so i presume its a string? will Need to transpose over the query to insert /r/n i believe and then construct a corresponding time array for every minute of previous 24 hours for second colomn.</p>
<pre><code>var endDate = CONTEXT.getTimestamp();
var startDate = endDate - CONTEXT.millisInPast(MINUTE, 4); //handles DST shenanigans
var results = [];
var callback = function(idValueTime) {
  results.push(idValueTime);};
var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
PointValueQuery.rollupQuery( [341], startDate, endDate, callback, AVERAGE, 1, MINUTE);
print(results);


var d = new Date();
//ECMA function to convert date to locale string YYYY-MM-DD
var datestring = d.toLocaleDateString();
//Substr fX to make date DD-MM-YYYY time format
var ddmmyyyy = datestring.substr(8,2)+datestring.substr(4,4)+datestring.substr(0,4);
var CSVname = "Performance_"+ddmmyyyy+".csv";
print(CSVname);
/*
var recipients = ["funtimes@live.com"];
var emailContent = new com.serotonin.web.mail.EmailContent(null, 
  "Email body content", com.serotonin.m2m2.Common.UTF8);
var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
  "attached"+datestring+.csv", "Head1,Head2\r\n12,22".getBytes());

emailContent.addAttachment(emailAttachment);
com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "Attachment test", emailContent, null);
*/
</code></pre>
]]></description><link>https://forum.mango-os.com/post/22341</link><guid isPermaLink="true">https://forum.mango-os.com/post/22341</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 02:52:44 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:56:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/map" aria-label="Profile: map">@<bdi>map</bdi></a> said in <a href="/post/22339">CSV with 1 minute rollup auto emailed via Meta Source</a>:</p>
<blockquote>
<p dir="auto">but also a point where going in circles becomes painful.</p>
</blockquote>
<p dir="auto">Cripes I know that all too well....</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/map" aria-label="Profile: map">@<bdi>map</bdi></a> said in <a href="/post/22339">CSV with 1 minute rollup auto emailed via Meta Source</a>:</p>
<blockquote>
<p dir="auto">Ahh so the ByteArrayAttachment doesn't create a file on the filesystem  but just creates the file on the fly in the meta source and names it "attached.txt, with "attatched text" being the content of that file?</p>
</blockquote>
<p dir="auto">Bingo! Have a cigar, or a scotch, or whatever you kick back with. I'd say you've got the right idea here.</p>
<p dir="auto">EDIT:<br />
My advice: Test with one row to start with your headers etc and ensure you're happy with the format before going full tilt rising with everything in a given date range.</p>
]]></description><link>https://forum.mango-os.com/post/22340</link><guid isPermaLink="true">https://forum.mango-os.com/post/22340</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:56:24 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:36:43 GMT]]></title><description><![CDATA[<p dir="auto">Help is always nice, its nice to struggle with progress but also a point where going in circles becomes painful.</p>
<p dir="auto">Ahh so the ByteArrayAttachment doesn't create a file on the filesystem  but just creates the file on the fly in the meta source and names it "attached.txt, with "attatched text" being the content of that file?</p>
]]></description><link>https://forum.mango-os.com/post/22339</link><guid isPermaLink="true">https://forum.mango-os.com/post/22339</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:36:43 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:33:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/map" aria-label="Profile: map">@<bdi>map</bdi></a> correct, but using Phil's code above:</p>
<pre><code>var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
  "attached.txt", "attached text".getBytes());
</code></pre>
<p dir="auto">Means we can be a bit more creative with the 'body' of our file. We just generate the data and turn it into a string and then apply the method above to convert it into binary.<br />
Want some help?</p>
]]></description><link>https://forum.mango-os.com/post/22338</link><guid isPermaLink="true">https://forum.mango-os.com/post/22338</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:33:00 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:29:37 GMT]]></title><description><![CDATA[<p dir="auto">Thanks again Matt - I was hoping there was some trickery you could somehow put a escape character + concatenate time in report name  input.</p>
<p dir="auto">Sorry if this is a little painful or covered elsewhere - I have little to no java script experience so this is all a little arcane to me. I would have expected you needed to point to the location on the file system to attach the file in an email?</p>
]]></description><link>https://forum.mango-os.com/post/22337</link><guid isPermaLink="true">https://forum.mango-os.com/post/22337</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:29:37 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:25:17 GMT]]></title><description><![CDATA[<p dir="auto">I do not believe it is possible.<br />
There was a similar question asked regarding the excel report:<br />
<a href="https://forum.infiniteautomation.com/topic/4037/changing-the-excel-report-name" rel="nofollow ugc">https://forum.infiniteautomation.com/topic/4037/changing-the-excel-report-name</a></p>
<p dir="auto">I feel you're better of using the applying the same code as above to give the desired results you want as it's a copy and paste with no fluff,</p>
]]></description><link>https://forum.mango-os.com/post/22336</link><guid isPermaLink="true">https://forum.mango-os.com/post/22336</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:25:17 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:17:51 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Matt, I meant through the interface as the current CSV report just utilises the mango standard module.</p>
]]></description><link>https://forum.mango-os.com/post/22335</link><guid isPermaLink="true">https://forum.mango-os.com/post/22335</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:17:51 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:39:58 GMT]]></title><description><![CDATA[<p dir="auto">Simple, when you add the email attachment, you set the name in the first parameter field.</p>
<pre><code> var emailAttachment = new com.serotonin.web.mail.EmailAttachment.FileAttachment("Data_nonRolled"+values[values.length-1].time+".csv",toAttach);

</code></pre>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/22334</link><guid isPermaLink="true">https://forum.mango-os.com/post/22334</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:39:58 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Fri, 07 Jun 2019 01:13:52 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the assistance!</p>
<p dir="auto">On another aside, the client has requested the current csv report (non rolled up) include the Timestamp much the same as the Excel Report.</p>
<p dir="auto">Is there an easy way to include the timestamp in the name of the report?</p>
]]></description><link>https://forum.mango-os.com/post/22333</link><guid isPermaLink="true">https://forum.mango-os.com/post/22333</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Fri, 07 Jun 2019 01:13:52 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Thu, 06 Jun 2019 20:00:07 GMT]]></title><description><![CDATA[<p dir="auto">I should be thanking you Phil! I can definitely use this myself in the near future combined with some other skulduggery I'm pulling hahaha. Hopefully this will give MaP what they need to pull off their task.</p>
]]></description><link>https://forum.mango-os.com/post/22327</link><guid isPermaLink="true">https://forum.mango-os.com/post/22327</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Thu, 06 Jun 2019 20:00:07 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Thu, 06 Jun 2019 19:58:36 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the good links Fox!</p>
<p dir="auto">I think if he wants to use a file attachment he'll need to write out to a file to then attach it. One could probably also use a ByteArrayAttachment, something like,</p>
<pre><code>var recipients = ["you@domain.extension"];
var emailContent = new com.serotonin.web.mail.EmailContent(null, 
  "Email body content", com.serotonin.m2m2.Common.UTF8);
var emailAttachment = new com.serotonin.web.mail.EmailAttachment.ByteArrayAttachment(
  "attached.txt", "attached text".getBytes());

emailContent.addAttachment(emailAttachment);
com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "Attachment test", emailContent, null);
</code></pre>
<p dir="auto">and here's a thread with a simple example of writing out to a file:<br />
<a href="https://forum.infiniteautomation.com/topic/4208/creating-files-in-filestore-from-excel-post-process-script" rel="nofollow ugc">https://forum.infiniteautomation.com/topic/4208/creating-files-in-filestore-from-excel-post-process-script</a></p>
]]></description><link>https://forum.mango-os.com/post/22326</link><guid isPermaLink="true">https://forum.mango-os.com/post/22326</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Thu, 06 Jun 2019 19:58:36 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Thu, 06 Jun 2019 10:48:00 GMT]]></title><description><![CDATA[<p dir="auto">This may be of some assistance for the email part.</p>
<p dir="auto"><a href="https://forum.infiniteautomation.com/topic/4034/exporting-excel-reports-to-csv/2" rel="nofollow ugc">https://forum.infiniteautomation.com/topic/4034/exporting-excel-reports-to-csv/2</a></p>
<p dir="auto">This post by Jared shows a way you can pull data via the API into a csv format. You could likely combine this with an http request to get your csv blob, attach it to the email and fire at will... Might need one of the infinite chaps to confirm...<br />
<a href="https://forum.infiniteautomation.com/topic/4050/datapoint-values-into-a-var-javascript/9" rel="nofollow ugc">https://forum.infiniteautomation.com/topic/4050/datapoint-values-into-a-var-javascript/9</a></p>
<p dir="auto">I'm not near my computer right now so I'm unable to be of further assistance. If nobody else has jumped in to assist when I wake up I'll give you a hand.</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/22323</link><guid isPermaLink="true">https://forum.mango-os.com/post/22323</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Thu, 06 Jun 2019 10:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to CSV with 1 minute rollup auto emailed via Meta Source on Thu, 06 Jun 2019 07:18:44 GMT]]></title><description><![CDATA[<pre><code>var endDate = CONTEXT.getTimestamp();
var startDate = endDate - CONTEXT.millisInPast(DAY, 1); //handles DST shenanigans
var results = [];
var callback = function(idValueTime) {
  results.push(idValueTime);};
var pointsToQuery = [ p341.getDataPointWrapper().getId() ];
PointValueQuery.rollupQuery( pointsToQuery, startDate, endDate, callback, AVERAGE, 1, MINUTE);
print(results.length);
</code></pre>
<p dir="auto">seems to be the method for returning the rolled up data for 1 point - Length is 1440 (60 minutes * 24 hours), and results contains the array of values.<br />
Having an array of the timestamps to construct the csv seems like the next logical point. Then the email which may be covered in other posts.<br />
I imagine if the script is executed via cron at midnight this will retrieve the appropriate range.</p>
]]></description><link>https://forum.mango-os.com/post/22322</link><guid isPermaLink="true">https://forum.mango-os.com/post/22322</guid><dc:creator><![CDATA[MaP]]></dc:creator><pubDate>Thu, 06 Jun 2019 07:18:44 GMT</pubDate></item></channel></rss>